getMeasurementsData
Get the current measurement data displayed on the spectrum analyzer
Description
Examples
Obtain Measurements Data Programmatically for spectrumAnalyzer
object
Compute and display the power spectrum of a noisy sinusoidal input signal using the spectrumAnalyzer
MATLAB® object. Measure the peaks, cursor placements, adjacent channel power ratio, and distortion values in the spectrum by enabling these properties:
PeakFinder
CursorMeasurements
ChannelMeasurements
DistortionMeasurements
Initialization
The input sine wave has two frequencies: 1000 Hz and 5000 Hz. Create two dsp.SineWave
System objects to generate these two frequencies. Create a spectrumAnalyzer
object to compute and display the power spectrum.
Fs = 44100; Sineobject1 = dsp.SineWave(SamplesPerFrame=1024,PhaseOffset=10,... SampleRate=Fs,Frequency=1000); Sineobject2 = dsp.SineWave(SamplesPerFrame=1024,... SampleRate=Fs,Frequency=5000); SA = spectrumAnalyzer(SampleRate=Fs,SpectrumType="power",... PlotAsTwoSidedSpectrum=false,ChannelNames={'Power spectrum of the input'},... YLimits=[-120 40],ShowLegend=true);
Enable Measurements Data
To obtain the measurements, set the Enabled
property to true
.
SA.CursorMeasurements.Enabled = true; SA.ChannelMeasurements.Enabled = true; SA.PeakFinder.Enabled = true; SA.DistortionMeasurements.Enabled = true;
Use getMeasurementsData
Stream in the noisy sine wave input signal and estimate the power spectrum of the signal using the spectrum analyzer. Measure the characteristics of the spectrum. Use the getMeasurementsData
function to obtain these measurements programmatically. The isNewDataReady
function returns true
when there is new spectrum data. Store the measured data in the variable data
.
data = []; for Iter = 1:1000 Sinewave1 = Sineobject1(); Sinewave2 = Sineobject2(); Input = Sinewave1 + Sinewave2; NoisyInput = Input + 0.001*randn(1024,1); SA(NoisyInput); if SA.isNewDataReady data = [data;getMeasurementsData(SA)]; end end
The bottom of the spectrum analyzer shows the measurement panes you enabled. The values in these panes match the values in the last time step of the data
variable. You can access the individual fields of data
to obtain the various measurements programmatically.
Compare Peak Values
Use the PeakFinder
property to obtain peak values. Verify that the peak values in the last time step of data
match the values shown on the spectrum analyzer plot.
peakvalues = data.PeakFinder(end).Value
peakvalues = 3×1
-59.4124
-59.8725
-60.0010
frequencieskHz = data.PeakFinder(end).Frequency/1000
frequencieskHz = 3×1
0.2799
0.5383
0.6029
Obtain Measurements Data Programmatically for Spectrum Analyzer Block
Compute and display the power spectrum of a noisy sinusoidal input signal using the Spectrum Analyzer block. Measure the peaks, cursor placements, adjacent channel power ratio, distortion, and CCDF values in the spectrum by enabling these block configuration properties:
PeakFinder
CursorMeasurements
ChannelMeasurements
DistortionMeasurements
CCDFMeasurements
Open and Inspect the Model
Filter a streaming noisy sinusoidal input signal using a Lowpass Filter block. The input signal consists of two sinusoidal tones: 1 kHz and 15 kHz. The noise is white Gaussian noise with zero mean and a variance of 0.05. The sampling frequency is 44.1 kHz. Open the model and inspect the various block settings.
model = 'spectrumanalyzer_measurements.slx';
open_system(model)
Access the configuration properties of the Spectrum Analyzer block using the get_param
function.
sablock = 'spectrumanalyzer_measurements/Spectrum Analyzer'; cfg = get_param(sablock,'ScopeConfiguration');
Enable Measurements Data
To obtain the measurements, set the Enable
property of the measurements to true
.
cfg.CursorMeasurements.Enable = true; cfg.ChannelMeasurements.Enable = true; cfg.PeakFinder.Enable = true; cfg.DistortionMeasurements.Enable = true;
Simulate the Model
Run the model. The Spectrum Analyzer block compares the original spectrum with the filtered spectrum.
sim(model)
The right side of the spectrum analyzer shows the enabled measurement panes.
Using getMeasurementsData
Use the getMeasurementsData
function to obtain these measurements programmatically.
data = getMeasurementsData(cfg)
data = 1x5 table SimulationTime PeakFinder CursorMeasurements ChannelMeasurements DistortionMeasurements ______________ __________ __________________ ___________________ ______________________ {[0.9985]} 1x1 struct 1x1 struct 1x1 struct 1x1 struct
The values shown in measurement panes match the values shown in data
. You can access the individual fields of data
to obtain the various measurements programmatically.
Compare Peak Values
As an example, compare the peak values. Verify that the peak values obtained by data.PeakFinder
match with the values seen in the Spectrum Analyzer
window.
peakvalues = data.PeakFinder.Value frequencieskHz = data.PeakFinder.Frequency/1000
peakvalues = 26.8441 26.3472 -4.4072 frequencieskHz = 15.0015 1.0049 21.7629
Save and Close the Model
save_system(model); close_system(model);
Input Arguments
scope
— Spectrum Analyzer
object name | block configuration
Spectrum Analyzer you want to query, specified as one of the following:
spectrumAnalyzer
objectSpectrumAnalyzerConfiguration
object for a Spectrum Analyzer block
Output Arguments
data
— Measurements data
table
Measurements data, returned as a table. When you specify "all"
,
the function returns a measurements table containing the following fields.
Field | Description |
---|---|
SimulationTime | Simulation time |
PeakFinder | Peak finder data |
CursorMeasurements | Cursor measurements data |
ChannelMeasurements | Channel measurements data |
DistortionMeasurements | Distortion measurements data |
CCDFMeasurements (applies only for
SpectrumAnalyzerConfiguration object) | CCDF measurements data |
When you do not specify "all"
, the data table contains only the
Spectrum Analyzer measurements currently in use.
Version History
Introduced in R2018bR2022a: Support for dsp.SpectrumAnalyzer
object will be removed
The getMeasurementsData
function will stop supporting the
dsp.SpectrumAnalyzer
object in a future release. Use the
spectrumAnalyzer
object instead.
Update Code
No updates to your code are required except replacing instances of
dsp.SpectrumAnalyzer
with spectrumAnalyzer
.
This table shows how the getMeasurementsData
function typically
uses the dsp.SpectrumAnalyzer
System object™ and explains how to update existing code to use the
spectrumAnalyzer
object.
Discouraged Usage | Recommended Replacement |
---|---|
scope = dsp.SpectrumAnalyzer; scope.CursorMeasurements.Enable = true; scope.ChannelMeasurements.Enable = true; scope(randn(100000,1)) getMeasurementsData(scope) |
scope = spectrumAnalyzer; scope.CursorMeasurements.Enabled = true; scope.ChannelMeasurements.Enabled = true; scope(randn(100000,1)) getMeasurementsData(scope) |
See Also
Functions
Objects
Blocks
Apri esempio
Si dispone di una versione modificata di questo esempio. Desideri aprire questo esempio con le tue modifiche?
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)