Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

## Configure Spectrum Analyzer

Use the Spectrum Analyzer to visualize frequency. You can customize the spectrum analyzer display to show the data and measurement information needed.

### Signal and Spectrum Computation Information

The Spectrum Analyzer shows the spectrum computation settings for the current visualization. In the scope status bar, check the Resolution Bandwidth, Time Resolution, and Offset indicators for this information. The values specified by these indicators can change depending on your settings in the Spectrum Settings panel. You can also view the simulation status and the amount of time data that correspond to the current display. Check the Simulation status and Display time indicators for this information.

• Resolution Bandwidth — The smallest positive frequency or frequency interval that can be resolved.

• Time Resolution — The time resolution for a spectrogram line.

• Offset — The constant frequency offset to apply to the entire spectrum or a vector of frequency offsets to apply to each spectrum for multiple inputs.

• Simulation Status — Provides the current status of the model simulation.

• Display time — The amount of time that has progressed since the last update to the Spectrum Analyzer display.

• Frequency span — The range of values shown on the frequency-axis on the Spectrum Analyzer window.

#### Reduce Plot Rate to Improve Performance

By default, Spectrum Analyzer updates the display at fixed intervals of time at a rate not exceeding 20 hertz. If you want Spectrum Analyzer to plot a spectrum on every simulation time step, you can disable the Simulation > Reduce Plot Rate to Improve Performance option.

### Note

When this option is selected, the Spectrum Analyzer may display a misleading spectrum in some situations. For example, if the input signal is wide-band with non-stationary behavior, such as a chirp signal, Spectrum Analyzer might display a stationary spectrum. The reason for this behavior is that Spectrum Analyzer buffers the input signal data and only updates the display periodically at approximately 20 times per second. Therefore, Spectrum Analyzer does not render changes to the spectrum that occur and elapse between updates, which gives the impression of an incorrect spectrum. To ensure that spectral estimates are as accurate as possible, clear the Reduce Plot Rate to Improve Performance check box. When you clear this box, Spectrum Analyzer calculates spectra whenever there is enough data, rendering results correctly.

### Generate a MATLAB Script

You can change Spectrum Analyzer settings using menus and options in the interface of the scope, or by changing properties at the command line. If you change settings in the `dsp.SpectrumAnalyzer` interface, you can generate the corresponding command line settings to use later.

### Note

The script only generates commands for settings that are available from the command line, applicable to the current visualization, and changed from the default value.

This example shows how to generate a script after making changes to the `dsp.SpectrumAnalyzer` in the interface:

1. Create a `dsp.SpectrumAnalyzer` System object.

```scope = dsp.SpectrumAnalyzer(); show(scope);```
2. Set options in the Spectrum Analyzer. For this example, turn on the Cursor Measurements. Also in the Spectrum Settings, change the View type to Spectrum and spectrogram and set the Axes Layout to Horizontal.

3. Generate a script to recreate the `dsp.SpectrumAnalyzer` with the same modified settings. Either select File > Generate MATLAB Script or enter:

``generateScript`(scope);`

A new editor window opens with code to regenerate the same scope.

```% Creation Code for 'dsp.SpectrumAnalyzer'. % Generated by Spectrum Analyzer on 10-Mar-2019 16:25:49 -0500. specScope = dsp.SpectrumAnalyzer('ViewType','Spectrum and spectrogram', ... 'AxesLayout','Horizontal'); % Cursor Measurements Configuration specScope.CursorMeasurements.Enable = true;```

### Spectral Masks

Add upper and lower masks to the Spectrum Analyzer to visualize spectrum limits and compare spectrum values to specification values.

To open the Spectral Mask pane, in the toolbar, select the spectral mask button, .

#### Set Up Spectral Masks

In the Spectrum Analyzer window:

1. In the Spectral Mask pane, select a Masks option.

2. In the Upper limits or Lower limits box, enter the mask limits as a constant scalar, an array, or a workspace variable name.

3. (Optional) Select additional properties:

• Reference level — Set a reference level for the mask. Enter a specific value or select `Spectrum peak`.

• Channel — Select a channel to use for the mask reference.

• Frequency offset — Set a frequency offset for mask.

From the command-line, to add a spectral mask to the `dsp.SpectrumAnalyzer` System object or the `SpectrumAnalyzerConfiguration` block configuration object:

1. Create a `SpectralMaskSpecfication` object.

2. Set properties, such as `EnabledMasks`, `LowerMask`, or `UpperMask`. For a full list of properties, see SpectralMask (block) and SpectralMask (System object™).

3. In the `dsp.SpectrumAnalyzer` or `SpectrumAnalyzerConfiguration` object, set the `SpectralMask` property equal to your `SpectralMaskSpecfication` object.

For example:

```mask = SpectralMaskSpecification(); mask.EnabledMasks = 'Upper'; mask.UpperMask = 10; scope = dsp.SpectrumAnalyzer(); scope.SpectralMask = mask; scope.SpectralMask```
```ans = SpectralMaskSpecification with properties: EnabledMasks: 'Upper' UpperMask: 10 LowerMask: -Inf ReferenceLevel: 'Custom' CustomReferenceLevel: 0 MaskFrequencyOffset: 0 Events for class SpectralMaskSpecification: MaskTestFailed ```

#### Check Spectral Masks

You can check the status of the spectral mask in several different ways:

• In the Spectrum Analyzer window, select the spectral mask button, . In the Spectral Mask pane, the Statistics section shows statistics about how often the masks fail, which channels have caused a failure, and which masks are currently failing.

• To get the current status of the spectral masks, call `getSpectralMaskStatus`.

• To perform an action every time the mask fails, use the `MaskTestFailed` event. To trigger a function when the mask fails, create a listener to the `MaskTestFailed` event and define a callback function to trigger. For more details about using events, see Events (MATLAB).

#### Spectral Mask in Spectrum Analyzer Block

This example shows how to create a new model based on the `dsp_basic_filter` template, add a spectral mask to its Spectrum Analyzer block, and run the model.

Masks are overlaid on the spectrum. If the mask is green, the signal is passing. If the mask is red, the signal is failing. The Spectral Mask panel shows what percentage of the time the mask is succeeding, which mask is failing, how many times the mask(s) failed, and which channels are causing the failure.

``` [~,mdl] = fileparts(tempname); open_system(new_system(mdl,'FromTemplate','dsp_basic_filter')); saBlock = find_system(mdl,'BlockType','SpectrumAnalyzer'); scopeConfig = get_param(saBlock{1},'ScopeConfiguration'); upperMask = [0 50; 1200 50; 1200 -10; 24000 -10]; scopeConfig.SpectralMask.UpperMask = upperMask; scopeConfig.SpectralMask.LowerMask = -100; scopeConfig.SpectralMask.EnabledMasks = 'Upper and lower'; sim(mdl,'StopTime','20'); ```

### Measurements Panels

The Measurements panels are the panels that appear on the right side of the Spectrum Analyzer. These measurements allow you to interact with the frequency values.

#### Trace Selection Panel

When you use the scope to view multiple signals, the Trace Selection panel appears. Use this panel to select which signal to measure. To open the Trace Selection panel:

• From the menu, select Tools > Measurements > Trace Selection.

• Open a measurement panel.

#### Cursor Measurements Panel

The Cursor Measurements panel displays screen cursors. The panel provides two types of cursors for measuring signals. Waveform cursors are vertical cursors that track along the signal. Screen cursors are both horizontal and vertical cursors that you can place anywhere in the display.

### Note

If a data point in your signal has more than one value, the cursor measurement at that point is undefined and no cursor value is displayed.

In the Scope menu, select Tools > Measurements > Cursor Measurements. Alternatively, in the Scope toolbar, click the Cursor Measurements button.

The Cursor Measurements panel for the spectrum and dual view:

The Cursor Measurements panel for the spectrogram view. You must pause the spectrogram display before you can use cursors.

You can use the mouse or the left and right arrow keys to move vertical or waveform cursors and the up and down arrow keys for horizontal cursors.

In the Settings pane, you can modify the type of screen cursors used for calculating measurements. When more than one signal is displayed, you can assign cursors to each trace individually.

• Screen Cursors — Shows screen cursors (for spectrum and dual view only).

• Horizontal — Shows horizontal screen cursors (for spectrum and dual view only).

• Vertical — Shows vertical screen cursors (for spectrum and dual view only).

• Waveform Cursors — Shows cursors that attach to the input signals (for spectrum and dual view only).

• Lock Cursor Spacing — Locks the frequency difference between the two cursors.

• Snap to Data — Positions the cursors on signal data points.

The Measurements pane displays the frequency (Hz) , time (s), and power (dBm) value measurements. Time is displayed only in spectrogram mode. Channel Power shows the total power between the cursors.

• 1 — Shows or enables you to modify the frequency, time (for spectrograms only), or both, at cursor number one.

• 2 — Shows or enables you to modify the frequency, time (for spectrograms only), or both, at cursor number two.

• Δ — Shows the absolute value of the difference in the frequency, time (for spectrograms only), or both, and power between cursor number one and cursor number two.

• Channel Power — Shows the total power in the channel defined by the cursors.

The letter after the value associated with a measurement indicates the abbreviation for the appropriate International System of Units (SI) prefix.

#### Peak Finder Panel

The Peak Finder panel displays the maxima, showing the x-axis values at which they occur. Peaks are defined as a local maximum where lower values are present on both sides of a peak. Endpoints are not considered peaks. This panel allows you to modify the settings for peak threshold, maximum number of peaks, and peak excursion.

• From the menu, select Tools > Measurements > Peak Finder.

• On the toolbar, click the Peak Finder button.

The Settings pane enables you to modify the parameters used to calculate the peak values within the displayed portion of the input signal. For more information on the algorithms this pane uses, see the `findpeaks` function reference.

Properties to set:

• Peak Threshold — The level above which peaks are detected. This setting is equivalent to the `MINPEAKHEIGHT` parameter, which you can set when you run the `findpeaks` function.

• Max Num of Peaks — The maximum number of peaks to show. The value you enter must be a scalar integer from 1 through 99. This setting is equivalent to the `NPEAKS` parameter, which you can set when you run the `findpeaks` function.

• Min Peaks Distance — The minimum number of samples between adjacent peaks. This setting is equivalent to the `MINPEAKDISTANCE` parameter, which you can set when you run the `findpeaks` function.

• Peak Excursion — The minimum height difference between a peak and its neighboring samples. Peak excursion is illustrated alongside peak threshold in the following figure.

The peak threshold is a minimum value necessary for a sample value to be a peak. The peak excursion is the minimum difference between a peak sample and the samples to its left and right in the time domain. In the figure, the green vertical line illustrates the lesser of the two height differences between the labeled peak and its neighboring samples. This height difference must be greater than the Peak Excursion value for the labeled peak to be classified as a peak. Compare this setting to peak threshold, which is illustrated by the red horizontal line. The amplitude must be above this horizontal line for the labeled peak to be classified as a peak.

The peak excursion setting is equivalent to the `THRESHOLD` parameter, which you can set when you run the `findpeaks` function.

• Label Format — The coordinates to display next to the calculated peak values on the plot. To see peak values, you must first expand the Peaks pane and select the check boxes associated with individual peaks of interest. By default, both x-axis and y-axis values are displayed on the plot. Select which axes values you want to display next to each peak symbol on the display.

• `X+Y` — Display both x-axis and y-axis values.

• `X` — Display only x-axis values.

• `Y` — Display only y-axis values.

The Peaks pane displays the largest calculated peak values. It also shows the coordinates at which the peaks occur, using the parameters you define in the Settings pane. You set the Max Num of Peaks parameter to specify the number of peaks shown in the list.

The numerical values displayed in the Value column are equivalent to the `pks` output argument returned when you run the `findpeaks` function. The numerical values displayed in the second column are similar to the `locs` output argument returned when you run the `findpeaks` function.

The Peak Finder displays the peak values in the Peaks pane. By default, the Peak Finder panel displays the largest calculated peak values in the Peaks pane in decreasing order of peak height.

Use the check boxes to control which peak values are shown on the display. By default, all check boxes are cleared and the Peak Finder panel hides all the peak values. To show or hide all the peak values on the display, use the check box in the top-left corner of the Peaks pane.

The Peaks are valid for any units of the input signal. The letter after the value associated with each measurement indicates the abbreviation for the appropriate International System of Units (SI) prefix, such as m for milli-. For example, if the input signal is measured in volts, an m next to a measurement value indicates that this value is in units of millivolts.

#### Channel Measurements Panel

The Channel Measurements panel displays occupied bandwidth or adjacent channel power ratio (ACPR) measurements.

• From the menu, select Tools > Measurements > Channel Measurements.

• On the toolbar, click the Channel Measurements button.

In addition to the measurements, the Channel Measurements panel has an expandable Channel Settings pane.

• Measurement — The type of measurement data to display. Available options are `Occupied BW` or `ACPR`. See Algorithms for information on how Occupied BW is calculated. ACPR is the adjacent channel power ratio, which is the ratio of the main channel power to the adjacent channel power.

When you select `Occupied BW` as the Measurement, the following fields appear.

• Channel Settings — Modify the parameters for calculating the channel measurements.

• Channel Power — The total power in the channel.

• Occupied BW — The bandwidth containing the specified Occupied BW (%) of the total power of the spectrum. This setting is available only if you select ```Occupied BW``` as the Measurement type.

• Frequency Error — The difference between the center of the occupied band and the center frequency (CF) of the channel. This setting is available only if you select `Occupied BW` as the Measurement type.

When you select `ACPR` as the Measurement, the following fields appear.

• Channel Settings — Enables you to modify the parameters for calculating the channel measurements.

• Channel Power — The total power in the channel.

• Offset (Hz) — The center frequency of the adjacent channel with respect to the center frequency of the main channel. This setting is available only if you select `ACPR` as the Measurement type.

• Lower (dBc) — The power ratio of the lower sideband to the main channel. This setting is available only if you select `ACPR` as the Measurement type.

• Upper (dBc) — The power ratio of the upper sideband to the main channel. This setting is available only if you select `ACPR` as the Measurement type.

#### Distortion Measurements Panel

The Distortion Measurements panel displays harmonic distortion and intermodulation distortion measurements.

• From the menu, select Tools > Measurements > Distortion Measurements.

• On the toolbar, click the Distortion Measurements button.

The Distortion Measurements panel has an expandable Harmonics pane, which shows measurement results for the specified number of harmonics.

### Note

For an accurate measurement, ensure that the fundamental signal (for harmonics) or primary tones (for intermodulation) is larger than any spurious or harmonic content. To do so, you may need to adjust the resolution bandwidth (`RBW`) of the spectrum analyzer. Make sure that the bandwidth is low enough to isolate the signal and harmonics from spurious and noise content. In general, you should set the RBW so that there is at least a 10dB separation between the peaks of the sinusoids and the noise floor. You may also need to select a different spectral window to obtain a valid measurement.

• Distortion — The type of distortion measurements to display. Available options are `Harmonic` or `Intermodulation`. Select `Harmonic` if your system input is a single sinusoid. Select `Intermodulation` if your system input is two equal amplitude sinusoids. Intermodulation can help you determine distortion when only a small portion of the available bandwidth will be used.

See Distortion Measurements for information on how distortion measurements are calculated.

When you select `Harmonic` as the Distortion, the following fields appear.

The harmonic distortion measurement automatically locates the largest sinusoidal component (fundamental signal frequency). It then computes the harmonic frequencies and power in each harmonic in your signal. Any DC component is ignored. Any harmonics that are outside the spectrum analyzer’s frequency span are not included in the measurements. Adjust your frequency span so that it includes all the desired harmonics.

### Note

To view the best harmonics, make sure that your fundamental frequency is set high enough to resolve the harmonics. However, this frequency should not be so high that aliasing occurs. For the best display of harmonic distortion, your plot should not show skirts, which indicate frequency leakage. Also, the noise floor should be visible.

For a better display, try a Kaiser window with a large sidelobe attenuation (e.g. between 100–300 db).

• Num. Harmonics — Number of harmonics to display, including the fundamental frequency. Valid values of Num. Harmonics are from `2` to `99`. The default value is `6`.

• Label Harmonics — Select Label Harmonics to add numerical labels to each harmonic in the spectrum display.

• 1 — The fundamental frequency, in hertz, and its power, in decibels of the measured power referenced to 1 milliwatt (dBm).

• 2, 3, ... — The harmonics frequencies, in hertz, and their power in decibels relative to the carrier (dBc). If the harmonics are at the same level or exceed the fundamental frequency, reduce the input power.

• THD — The total harmonic distortion. This value represents the ratio of the power in the harmonics, D, to the power in the fundamental frequency, S. If the noise power is too high in relation to the harmonics, the THD value is not accurate. In this case, lower the resolution bandwidth or select a different spectral window.

`$THD=10\cdot {\mathrm{log}}_{10}\left(D/S\right)$`

• SNR — Signal-to-noise ratio (SNR). This value represents the ratio of power in the fundamental frequency, S, to the power of all nonharmonic content, N, including spurious signals, in decibels relative to the carrier (dBc).

`$SNR=10\cdot {\mathrm{log}}_{10}\left(S/N\right)$`

If you see `––` as the reported SNR, the total non-harmonic content of your signal is less than 30% of the total signal.

• SINAD — Signal-to-noise-and-distortion. This value represents the ratio of the power in the fundamental frequency, S to all other content (including noise, N, and harmonic distortion, D), in decibels relative to the carrier (dBc).

`$SINAD=10\cdot {\mathrm{log}}_{10}\left(\frac{S}{N+D}\right)$`

• SFDR — Spurious free dynamic range (SFDR). This value represents the ratio of the power in the fundamental frequency, S, to power of the largest spurious signal, R, regardless of where it falls in the frequency spectrum. The worst spurious signal may or may not be a harmonic of the original signal. SFDR represents the smallest value of a signal that can be distinguished from a large interfering signal. SFDR includes harmonics.

`$SNR=10\cdot {\mathrm{log}}_{10}\left(S/R\right)$`

When you select `Intermodulation` as the Distortion, the following fields appear.

The intermodulation distortion measurement automatically locates the fundamental, first-order frequencies (F1 and F2). It then computes the frequencies of the third-order intermodulation products (2*F1-F2 and 2*F2-F1).

• Label frequencies — Select Label frequencies to add numerical labels to the first-order intermodulation product and third-order frequencies in the spectrum analyzer display.

• F1 — Lower fundamental first-order frequency

• F2 — Upper fundamental first-order frequency

• 2F1 - F2 — Lower intermodulation product from third-order harmonics

• 2F2 - F1 — Upper intermodulation product from third-order harmonics

• TOI — Third-order intercept point. If the noise power is too high in relation to the harmonics, the TOI value will not be accurate. In this case, you should lower the resolution bandwidth or select a different spectral window. If the TOI has the same amplitude as the input two-tone signal, reduce the power of that input signal.

#### CCDF Measurements Panel

The CCDF Measurements panel displays complimentary cumulative distribution function measurements. CCDF measurements in this scope show the probability of a signal’s instantaneous power being a specified level above the signal’s average power. These measurements are useful indicators of a signal’s dynamic range.

To compute the CCDF measurements, each input sample is quantized to 0.01 dB increments. Using a histogram 100 dB wide (10,000 points at 0.01 dB increments), the largest peak encountered is placed in the last bin of the histogram. If a new peak is encountered, the histogram shifts to make room for that new peak.

To open this dialog box:

• From the menu, select Tools > Measurements > CCDF Measurements

• In the toolbar, click the CCDF Measurements button.

• Plot Gaussian reference — Show the Gaussian white noise reference signal on the plot.

• Probability (%) — The percentage of the signal that contains the power level above the value listed in the dB above average column

• dB above average — The expected minimum power level at the associated Probability (%).

• Average Power — The average power level of the signal since the start of simulation or from the last reset.

Max Power — The maximum power level of the signal since the start of simulation or from the last reset.

• PAPR — The ratio of the peak power to the average power of the signal. PAPR should be less that 100 dB to obtain accurate CCDF measurements. If PAPR is above 100 dB, only the highest 100 dB power levels are plotted in the display and shown in the distribution table.

• Sample Count — The total number of samples used to compute the CCDF.

• Reset — Clear all current CCDF measurements and restart.

### Customize Visualization

To control the labels, minimum and maximum values, the legend, and gridlines, use the configuration properties. From the Spectrum Analyzer, select View > Configuration Properties or click the toolbar button .

In the Style dialog box, you can customize the style of spectrum display. This dialog box is not available for the spectrogram view. You can change the color of the spectrum plot, color of the background, and properties of the lines. To open this dialog box, select View > Style.

If you are viewing only the spectrum or the spectrogram, you only see the relevant options. For more details about these options, see Configuration Properties and Style.

### Zoom and Pan

To zoom in and out of the plot, or pan to different area of the plot, use the zoom buttons in the toolbar or in the Tools menu.

You can set properties to zoom in/out automatically or scale the axes. In the Spectrum Analyzer menu, select Tools > Axes Scaling.

If you are viewing only the spectrum or the spectrogram, you see only the relevant options. If you are using the CCDF measurements, you will also see x-axis scaling options. For more details about these options, see Axes Scaling.

Watch now