# Documentation

### This is machine translation

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

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

# dsp.SpectrumAnalyzer System object

Package: dsp

Display frequency spectrum of time-domain signals

## Description

The `SpectrumAnalyzer` object, hereafter referred to as the scope, displays the frequency spectrum of time-domain signals. This scope supports variable-size input, which allows the input frame size to change. Frame size is the first dimension of the input vector. The number of input channels must remain constant.

To display the spectra of signals in the Spectrum Analyzer:

1. Define and set up your Spectrum Analyzer. See Construction.

2. Call `step` to display the frequency spectrum of the signals in the Spectrum Analyzer figure. The number of inputs to the step method must match the value of the `NumInputPorts` property. The input to every port must have same frame length, but can have a different number of channels. Each input is an individual channel of input data. For example, if the first input is a signal vector, it is Channel 1. If the second input is a two-column matrix, it is Channel 2 and Channel 3.

Use the MATLAB® `clear` function to close the Spectrum Analyzer figure window and clear its associated data. Use the `hide` method to hide the Spectrum Analyzer window and the `show` method to make it visible.

Use the MATLAB `mcc` function to compile code containing a Spectrum Analyzer.

 Note:   You cannot open Spectrum Analyzer configuration dialogs if you have more than one compiled component in your application.

See the following sections for more information on the Spectrum Analyzer Graphical User Interface:

 Note:   For information about the Spectrum Analyzer block, see Spectrum Analyzer.
 Note:   If you own the MATLAB Coder™ product, you can generate C or C++ code from MATLAB code in which an instance of this system object is created. When you do so, the scope system object is automatically declared as an extrinsic variable. In this manner, you are able to see the scope display in the same way that you would see a figure using the `plot` function, without directly generating code from it. For the full list of system objects supporting code generation, see DSP System Toolbox in the MATLAB Coder documentation.
 Note:   Starting in R2016b, instead of using the `step` method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, ```y = step(obj,x)``` and `y = obj(x)` perform equivalent operations.

## Construction

`H = dsp.SpectrumAnalyzer` creates a Spectrum Analyzer System object, `H`. This object displays the frequency spectrum of real- and complex-valued floating- and fixed-point signals.

`H = dsp.SpectrumAnalyzer(ports)` creates a Spectrum Analyzer with the specified number of input `ports`. This value is stored in the `NumInputPorts` property.

`H = dsp.SpectrumAnalyzer('Name',Value,...)` creates a Spectrum Analyzer System object, `H`, with each specified property `Name` set to the specified value. You can specify `Name``Value` arguments in any order.

## Properties

`CenterFrequency`

Frequency over which frequency span is centered

Specify as a real scalar the center frequency, in hertz, of the frequency span over which the Spectrum Analyzer computes and plots the spectrum. This property applies when you set the `FrequencySpan` property to ```'Span and center frequency'```. The overall frequency span, defined by the `Span` and `CenterFrequency` properties, must fall within the Nyquist frequency interval. When the `PlotAsTwoSidedSpectrum` property is set to `true`, the interval is $\left[-\frac{SampleRate}{2},\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz. When the `PlotAsTwoSidedSpectrum` property is set to `false`, the interval is$\left[0,\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz.

This property is Tunable.

Default: `0`

`ChannelNames`

Channel names

Specify as a cell array of character vectors the input channels names to display in the legend, the Style dialog, and in some Measurements panels. The channel names only appear in the legend when the `ShowLegend` property is `true`. The default is an empty cell array, which labels the channels as `Channel 1`, ```Channel 2```, etc.

This property is Tunable.

`FFTLength`

FFT length

Specify as a positive, scalar integer the length of the FFT that the Spectrum Analyzer uses to compute spectral estimates. This property applies only when you set the `FrequencyResolutionMethod` property to `'WindowLength'` and the `FFTLengthSource` property to `'Property'`. The `FFTLength` must be greater than or equal to the `WindowLength`. You cannot control the FFT length when the `FrequencyResolutionMethod` property is `'RBW'`. In that case, the FFT length is set as the window length required to achieve the specified resolution bandwidth value or 1024, whichever is larger.

This property is Tunable.

Default: `128`

`FFTLengthSource`

Source of the FFT length value

Specify the source of the FFT length value as one of `'Auto'` or `'Property'`.

• When you set this property to `'Auto'`, the Spectrum Analyzer sets the FFT length to the window length specified in the `WindowLength` property or to 1024, whichever is larger.

• When you set this property to `'Property'`, specify the number of FFT points using the `FFTLength` property. The `FFTLength` must be greater than the `WindowLength`.

This property applies only when you set the `FrequencyResolutionMethod` property to `'WindowLength'` property to `'Property'`.

`FFTLengthSource` property is Tunable.

Default: `'Auto'`

`FrequencyOffset`

Frequency offset

Specify as a real, scalar value to apply the same frequency offset, in Hertz, to all channels. To apply a specific frequency offset for each channel, specify a vector of real, scalar values. The vector length must be equal to number of input channels. The frequency-axis values are offset by the values specified in this property. The overall span must fall within the Nyquist frequency interval. When the `PlotAsTwoSidedSpectrum` property is `true`, the Nyquist interval is $\left[-\frac{SampleRate}{2},\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz. When you set the `PlotAsTwoSidedSpectrum` property to `false`, the Nyquist interval is$\left[0,\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz. You can control the overall span in different ways based on how you set the `FrequencySpan` property.

This property is Tunable.

Default: `0`

`FrequencyResolutionMethod`

Frequency resolution method

Specify how to control the frequency resolution of the spectrum analyzer as either `'RBW'` or `'WindowLength'`. When you set this property to `'RBW'`, the `RBWSource` and `RBW` properties control the frequency resolution (in Hz) of the analyzer. When you set this property to `'WindowLength'`, the `WindowLength` property controls the frequency resolution.

In this case, the frequency resolution of the analyzer is defined as where NENBW is the normalized effective noise bandwidth of the window currently specified in the `Window` property. You can control the number of FFT points only when the `FrequencyResolutionMethod` property is `'WindowLength'`. When the `FrequencyResolutionMethod` property is `'RBW'`, the FFT length is the window length that results from achieving the specified RBW value or 1024, whichever is larger.

This property is Tunable.

Default: `'RBW'`

`FrequencyScale`

Frequency scale

Specify the frequency scale as either `'Linear'` or `'Log'`. When you set the `FrequencyScale` property to `'Log'`, the Spectrum Analyzer displays the frequencies on the x-axis on a logarithmic scale. To use the `'Log'` setting, you must also set the `PlotAsTwoSidedSpectrum` property to `false`. When the `PlotAsTwoSidedSpectrum` property is `true`, you must set this property to `'Linear'`.

This property is Tunable.

Default: `'Linear'`

`FrequencySpan`

Frequency span mode

Specify the frequency span mode as one of `'Full'`, ```'Span and center frequency'```, or `'Start and stop frequencies'`.

• When you set this property to `'Full'`, the Spectrum Analyzer computes and plots the spectrum over the entire Nyquist frequency interval. When the `PlotAsTwoSidedSpectrum` property is `true`, the Nyquist interval is $\left[-\frac{SampleRate}{2},\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz. If you set the `PlotAsTwoSidedSpectrum` property to `false`, the Nyquist interval is$\left[0,\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz.

• When you set this property to ```'Span and center frequency'```, the Spectrum Analyzer computes and plots the spectrum over the interval specified by the `Span` and `CenterFrequency` properties.

• When you set this property to ```'Start and stop frequencies'```, the Spectrum Analyzer computes and plots the spectrum over the interval specified by the `StartFrequency` and `StopFrequency` properties.

This property is Tunable.

Default: `'Full'`

`Name`

Caption to display on Spectrum Analyzer window

Specify as a character vector the caption to display on the scope window. This property is Tunable.

Default: `'Spectrum Analyzer'`

`NumInputPorts`

Number of input ports

Number of input ports, specified as an integer. Each signal coming through an input port becomes a separate channel in the Spectrum Analyzer.

Default: `1`

`OverlapPercent`

Overlap percentage

Specify as a real, scalar value, the percentage overlap between the previous and current buffered data segments. The overlap creates a window segment that is used to compute a spectral estimate. The value must be greater than or equal to zero and less than 100. This property is Tunable.

Default: `0`

`PlotAsTwoSidedSpectrum`

Two sided spectrum flag

Set this property to `true` to compute and plot two-sided spectral estimates. Set this property to `false` to compute and plot one-sided spectral estimates. If you set this property to `false`, then the input signal must be real valued. When the input signal is complex valued, you must set this property to `true`.

When this property is `false`, Spectrum Analyzer uses power folding. The y-axis values are twice the amplitude that they would be if this property were set to `true`, except at 0 and the Nyquist frequency. A one-sided PSD contains the total power of the signal in the frequency interval from DC to half of the Nyquist rate. For more information, see the `pwelch` function reference page.

Default: `true`

`PlotMaxHoldTrace`

Max-hold trace flag

Set this property to `true` to compute and plot the maximum-hold spectrum of each input channel. The maximum-hold spectrum at each frequency bin is computed by keeping the maximum value of all the power spectrum estimates. When you toggle this property, the Spectrum Analyzer resets its maximum-hold computations. This property applies only when you set the `SpectrumType` property to `'Power'` or `'Power density'`.

This property is Tunable.

See also: `PlotMinHoldTrace` and `PlotNormalTrace`.

Default: `false`

`PlotMinHoldTrace`

Min-hold trace flag

Set this property to `true` to compute and plot the minimum-hold spectrum of each input channel. The minimum-hold spectrum at each frequency bin is computed by keeping the minimum value of all the power spectrum estimates. When you toggle this property, the Spectrum Analyzer resets its minimum-hold computations. This property applies only when you set the `SpectrumType` property to `'Power'` or `'Power density'`.

This property is Tunable.

See also: `PlotMaxHoldTrace` and`PlotNormalTrace`.

Default: `false`

`PlotNormalTrace`

Normal trace flag

Set this property to `false` to remove the display of the normal traces. These traces display the free-running spectral estimates. Note that even when the traces are removed from the display, the Spectrum Analyzer continues its spectral computations. This property applies only when you set the `SpectrumType` property to `'Power'` or ```'Power density'```.

This property is Tunable.

See also: `PlotMaxHoldTrace` and `PlotMinHoldTrace`.

Default: `true`

`PlotType`

Plot type for normal traces

Specify the type of plot to use for displaying normal traces as either `'Line'` or `'Stem'`. Normal traces are traces that display free-running spectral estimates. This property applies only when you set the `SpectrumType` property to `'Power'` or `'Power density'`. and the `PlotNormalTrace` property to `true`.

This property is Tunable.

Default: `'Line'`

`Position`

Spectrum Analyzer window position in pixels

Specify, in pixels, the size and location of the scope window as a 4-element double vector of the form [left bottom width height]. You can place the scope window in a specific position on your screen by modifying the values to this property. This property is Tunable.

Default: The default depends on your screen resolution. By default, the Spectrum Analyzer window appears in the center of your screen with a width of `800` pixels and height of `450` pixels.

`PowerUnits`

Power units

Specify the units in which the Spectrum Analyzer displays power values as either `'dBm'`, `'dBW'`, or `'Watts'`.

This property is Tunable.

Default: `'dBm'`

`RBW`

Resolution bandwidth

Specify as a real, positive scalar the resolution bandwidth (RBW), in hertz. RBW controls the spectral resolution of Spectrum Analyzer. This property applies only when you set the `FrequencyResolutionMethod` property to `'RBW'` and the `RBWSource` property to `'Property'`. You must specify a value to ensure that there are at least two RBW intervals over the specified frequency span. Thus, the ratio of the overall span to RBW must be greater than two: $\frac{span}{RBW}>2$. You can specify the overall span in different ways based on how you set the `FrequencySpan` property.

This property is Tunable.

See also: `RBWSource`.

Default: `9.76`

`RBWSource`

Source of resolution bandwidth value

Specify the source of the resolution bandwidth (RBW) as either `'Auto'` or `'Property'`. This property is relevant only when you set the `FrequencyResolutionMethod` property to `'RBW'`.

• When you set this property to `'Auto'`, the Spectrum Analyzer adjusts the spectral estimation resolution to ensures that there are 1024 RBW intervals over the defined frequency span.

• When you set this property to `'Property'`, specify the resolution bandwidth directly using the `RBW` property.

This property is Tunable.

See also: `RBW`.

Default: `'Auto'`

`ReducePlotRate`

Reduce plot rate to improve performance

When you set this property to `true`, the scope logs data for later use and updates the display at fixed intervals of time. Data occurring between these fixed intervals might not be plotted. When you set this property to `false`, the scope updates every time it computes the power spectrum. Use the `false` setting when you do not want to miss any spectral updates at the expense of slower simulation speed. The simulation speed is faster when this property is set to `true`. This property is Tunable.

Default: `true`

`ReferenceLoad`

Specify as a real, positive scalar the load, in ohms, that the Spectrum Analyzer uses as a reference to compute power values.

This property is Tunable.

Default: `1`

`SampleRate`

Sample rate of input

Specify the sample rate, in hertz, of the input signals.

The sample rate must be a finite numeric scalar.

Default: `10e3`

`ShowGrid`

Option to enable or disable grid display

When you set this property to `true`, the grid appears. When you set this property to `false`, the grid is hidden. This property is Tunable.

Default: `false`

`ShowLegend`

Show or hide legend

When you set this property to `true`, the scope displays a legend with the input channels labels specified in the `ChannelNames` property. When you set this property to `false`, the scope does not display a legend. This property applies only when you set the `SpectrumType` property to `'Power'` or `'Power density'`. This property is Tunable.

Default: `false`

`SidelobeAttenuation`

Sidelobe attenuation of window

Specify as a real, positive scalar the window sidelobe attenuation, in decibels (dB). This property applies only when you set the `Window` property to `'Chebyshev'` or `'Kaiser'`. The value must be greater than or equal to `45`.

This property is Tunable.

Default: `60`

`Span`

Frequency span over which spectrum is computed and plotted

Specify as a real, positive scalar the frequency span, in hertz, over which the Spectrum Analyzer computes and plots the spectrum. This property applies only when you set the `FrequencySpan` property to ```'Span and center frequency'```. The overall span, defined by this property and the `CenterFrequency` property, must fall within the Nyquist frequency interval. When the `PlotAsTwoSidedSpectrum` property is `true`, the Nyquist interval is $\left[-\frac{SampleRate}{2},\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz. When you set the `PlotAsTwoSidedSpectrum` property to `false`, the Nyquist interval is$\left[0,\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz.

This property is Tunable.

Default: `10e3`

`SpectralAverages`

Number of spectral averages

Specify as a positive, scalar integer the number of spectral averages. This property applies only when you set the `SpectrumType` property to `'Power'` or ```'Power density'```. The Spectrum Analyzer computes the current power spectrum estimate by computing a running average of the last N power spectrum estimates. This property defines the number of spectral averages, N.

This property is Tunable.

Default: `1`

`SpectralMask`

Spectral mask lines for a power or power density plot.

Specify whether to display upper and lower spectral masks lines on a power or power density plot. This property uses `SpectralMaskSpecfication` properties to enable and configure the spectral masks. The `SpectralMaskSpecfication` properties are

• `EnabledMasks` — Masks to enable, specified as a character vector. Valid values are `'None'`, `'Upper'`, `'Lower'`, or `'Upper and lower'`.

Default: `'None'`

• `UpperMask` — Upper limit spectral mask, specified as a scalar or two-column matrix. If `UpperMask` is a scalar, the upper limit mask uses the power value of the scalar for all frequency values applicable to the Spectrum Analyzer. If `UpperMask` is a matrix, the first column contains the frequency values (Hz), which correspond to the x-axis values. The second column contains the power values, which correspond to the associated y-axis values. To apply offsets to the power and frequency values, use `ReferenceLevel` and `MaskFrequencyOffset` property values, respectively.

Default: `Inf`

• `LowerMask` — Lower limit spectral mask, specified as a scalar or two-column matrix. If `LowerMask` is a scalar, the lower limit mask uses the power value of the scalar for all frequency values applicable to the Spectrum Analyzer. If `LowerMask` is a matrix, the first column contains the frequency values (Hz), which correspond to the x-axis values. The second column contains the power values, which correspond to the associated y-axis values. To apply offsets to the power and frequency values, use `ReferenceLevel` and `MaskFrequencyOffset` property values, respectively.

Default: `Inf`

• `ReferenceLevel` — Reference level for mask power values, specified as either `'Custom'` or `'Spectrum peak'`. When `ReferenceLevel` is `'Custom'`, the `CustomReferenceLevel` property value is used as the reference to the power values, in dBr, in the `UpperMask` and `LowerMask` properties. When `ReferenceLevel` is `'Spectrum peak'`, the peak value of the current spectrum of the `SelectedChannel` is used.

Default: `'Custom'`

• `CustomReferenceLevel` — Custom reference level, specified as a real value, in the same units as the power units. The reference level is the value to which to reference the power values in the `UpperMask` and `LowerMask` properties. This property applies when `ReferenceLevel` is set to `'Custom'`. This property uses the same units as the `PowerUnits` property of the Spectrum Analyzer.

Default: `0`

• `SelectedChannel` — Input channel with peak spectrum to use as the mask reference level, specified as an integer. This property applies when `ReferenceLevel` is set to `'Spectrum peak'`.

Default: `1`

• `MaskFrequencyOffset` — Frequency offset, specified as a finite, numeric scalar. Frequency offset is the amount of offset to apply to frequency values in the `UpperMask` and `LowerMask` properties.

Default: `0`

All of these `SpectralMaskSpecfication` properties are Tunable.

This example shows how to add a spectral mask to an existing `dsp.SpectrumAnalyzer` System object scope.

```sine = dsp.SineWave('Frequency',[98 100],'SampleRate',1000); sine.SamplesPerFrame = 1024; scope = dsp.SpectrumAnalyzer('SampleRate',sine.SampleRate, ... 'PlotAsTwoSidedSpectrum',false,'ShowLegend',true); for i=1:100 scope(sine() + 0.05*randn(1024,2)); end scope.SpectralMask.EnabledMasks = 'Upper and lower'; upperMask = [0 -10; 90 -10; 90 40; 110 40; 110 -10; 500 -10]; set(scope.SpectralMask,'UpperMask',upperMask,'LowerMask',-60); release(scope);```

`SpectrumType`

Spectrum type

Specify the spectrum type as one of `'Power'`, ```'Power density'```, or `'Spectrogram'`.

• When you set this property to `'Power'`, the Spectrum Analyzer shows the power spectrum.

• When you set this property to `'Power density'`, the Spectrum Analyzer shows the power spectral density. The power spectral density is the magnitude squared of the spectrum normalized to a bandwidth of 1 hertz.

• When you set this property to `'Spectrogram'`, the Spectrum Analyzer open a spectrogram view, which shows frequency content over time. Each line of the spectrogram is one periodogram. Time scrolls from the bottom to the top of the display. The most recent spectrogram update is at the bottom of the display.

This property is Tunable.

Default: `'Power'`

`StartFrequency`

Start frequency over which spectrum is computed

Specify as a real scalar the start frequency, in hertz, over which the Spectrum Analyzer computes and plots the spectrum. This property applies only when you set the `FrequencySpan` property to `'Start and stop frequencies'`. The overall span, which is defined by `StopFrequency` and this property, must fall within the Nyquist frequency interval. When the `PlotAsTwoSidedSpectrum` property is `true`, the Nyquist interval is $\left[-\frac{SampleRate}{2},\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz. If you set the `PlotAsTwoSidedSpectrum` property to `false`, the Nyquist interval is$\left[0,\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz.

This property is Tunable.

Default: `-5e3`

`StopFrequency`

Stop frequency over which spectrum is computed

Specify as a real scalar the stop frequency, in hertz, over which the Spectrum Analyzer computes and plots the spectrum. This property applies only when you set the `FrequencySpan` property to `'Start and stop frequencies'`. The overall span, defined by this property and the `StartFrequency` property, must fall within the Nyquist frequency interval. When the `PlotAsTwoSidedSpectrum` property is set to `true`, the interval is $\left[-\frac{SampleRate}{2},\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz. When the `PlotAsTwoSidedSpectrum` property is set to `false`, the interval is$\left[0,\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz.

This property is Tunable.

Default: `5e3`

`TimeResolution`

Time resolution

Specify the time resolution of each spectrogram line as a positive scalar, expressed in seconds. This property applies when you set the `SpectrumType` property to `'Spectrogram'`, and the `TimeResolutionSource` property to `'Property'`.

The time resolution value is determined based on frequency resolution method, the RBW setting, and the time resolution setting.

Frequency Resolution RBW SettingTime Resolution SettingTime Resolution
RBW (Hz)`Auto``Auto`1/RBW s
RBW (Hz)`Auto`Manually enteredTime Resolution s
RBW (Hz)Manually entered`Auto`1/RBW s
RBW (Hz)Manually enteredManually enteredMust be equal to or greater than the minimum attainable time resolution, 1/RBW s. Several spectral estimates are combined into one spectrogram line to obtain the desired time resolution. Interpolation is used to obtain time resolution values that are not integer multiples of 1/RBW s.
Window length`Auto`1/RBW s

RBW = (NENBW*Fs)/Window Length, where NENBW is the normalized effective noise bandwidth of the specified window.
Window lengthManually enteredMust be equal to or greater than the minimum attainable time resolution, (NENBW*Fs)/Window Length. Several spectral estimates are combined into one spectrogram line to obtain the desired time resolution. Interpolation is used to obtain time resolution values that are not integer multiples of 1/RBW s.

This property is Tunable.

Default: `0.001`

`TimeResolutionSource`

Source of the time resolution value.

Specify the source for the time resolution of each spectrogram line as either `'Auto'` or `'Property'`. This property applies when you set the `SpectrumType` property to `'Spectrogram'`. See the time resolution table at `TimeResolution`.

This property is Tunable.

Default: `'Auto'`

`TimeSpan`

Time span

Specify the time span of the spectrogram display as a positive scalar in seconds. This property applies when you set the `SpectrumType` property to `'Spectrogram'` and the `TimeSpanSource` property to `'Property'`. You must set the time span to be at least twice as large as the duration of the number of samples required for a spectral update.

This property is Tunable.

Default: `0.1`

`TimeSpanSource`

Source of time span value

Specify the source for the time span of the spectrogram as either `'Auto'` or `'Property'`. This property applies when you set the`SpectrumType` property to `'Spectrogram'`. If you set this property to `'Auto'`, the spectrogram displays 100 spectrogram lines at any given time. If you set this property to `'Property'`, the spectrogram uses the time duration you specify in seconds in the `TimeSpan` property.

This property is Tunable.

Default: `'Auto'`

`Title`

Display title

Specify the display title as a character vector. Enter `%<SignalLabel>` to use the signal labels in the Simulink Model as the axes titles. This property is Tunable.

Default: `''`

`Window`

Window function

Specify a window function for the spectral estimator as one of the options in the following table. For information on any window function, follow the link to the corresponding function reference in the Signal Processing Toolbox™ documentation.

Window OptionCorresponding Function in Signal Processing Toolbox
`'Rectangular'``rectwin`
`'Chebyshev'``chebwin`
`'Flat Top'``flattopwin`
`'Hamming'``hamming`
`'Hann'``hann`
`'Kaiser'``kaiser`

This property is Tunable.

Default: `'Hann'`

`WindowLength`

The window length

Control the frequency resolution by specifying the window length, in samples used to compute the spectral estimates. The window length must be an integer scalar greater than 2. This property applies only when you set the `FrequencyResolutionMethod` property to `'WindowLength'`, which controls the frequency resolution based on your window length setting. The resulting resolution bandwidth (RBW) is where Nwindow is the `WindowLength` value.

This property is Tunable.

See also: `Window`.

Default: `1024`

`YLabel`

The label for the y-axis

Specify the text for the scope to display to the left of the y-axis. Tunable

This property applies only when you set the `SpectrumType` property to `'Power'` or ```'Power density'```. Regardless of this property, Spectrum Analyzer always displays power units as one of `'dBm'`, `'dBW'`, `'Watts'`, `'dBm/Hz'`, `'dBW/Hz'`, `'Watts/Hz'`.

See also: `PowerUnits`.

Default: `''`

`YLimits`

The limits for the y-axis

Specify the y-axis limits as a 2-element numeric vector, `[ymin ymax]`. This property is Tunable.

This property applies only when you set the `SpectrumType` property to `'Power'` or ```'Power density'```. The units directly depend upon the `PowerUnits` property.

Default: `[-80, 20]`

## Methods

 clone Create spectrum analyzer object with same property values getNumInputs Number of expected inputs to step method getNumOutputs Number of outputs of step method hide Hide Spectrum Analyzer window isLocked Locked status for input attributes and nontunable properties release Allow property value and input characteristics changes reset Reset internal states of Spectrum Analyzer object show Make Spectrum Analyzer window visible step Update spectrum in Spectrum Analyzer figure

## Examples

View a two-sided power spectrum of a sine wave with noise on the Spectrum Analyzer.

```hsin = dsp.SineWave('Frequency',100,'SampleRate',1000); hsin.SamplesPerFrame = 1000; hsa = dsp.SpectrumAnalyzer('SampleRate',hsin.SampleRate); for ii = 1:250 x = step(hsin) + 0.05*randn(1000,1); step(hsa, x); end ```

Run the `release` method to let property values and input characteristics change. The scope automatically scales the axes. It updates the display one more time if any data is in the internal buffer.

`release(hsa);`

Run the MATLAB `clear` function to close the Spectrum Analyzer window.

`clear('hsa');`

View a one-sided power spectrum made from the sum of five real sine waves with different amplitudes and frequencies.

```Fs = 100e6; % Sampling frequency fSz = 5000; % Frame size hsin1 = dsp.SineWave(1e0, 5e6, 0, 'SamplesPerFrame', fSz, 'SampleRate', Fs); hsin2 = dsp.SineWave(1e-1, 15e6, 0, 'SamplesPerFrame', fSz, 'SampleRate', Fs); hsin3 = dsp.SineWave(1e-2, 25e6, 0, 'SamplesPerFrame', fSz, 'SampleRate', Fs); hsin4 = dsp.SineWave(1e-3, 35e6, 0, 'SamplesPerFrame', fSz, 'SampleRate', Fs); hsin5 = dsp.SineWave(1e-4, 45e6, 0, 'SamplesPerFrame', fSz, 'SampleRate', Fs); hsb = dsp.SpectrumAnalyzer; hsb.SampleRate = Fs; hsb.SpectralAverages = 1; hsb.PlotAsTwoSidedSpectrum = false; hsb.RBWSource = 'Auto'; hsb.PowerUnits = 'dBW'; hsb.Position = [749 227 976 721]; for idx = 1:1e2 y1 = step(hsin1); y2 = step(hsin2); y3 = step(hsin3); y4 = step(hsin4); y5 = step(hsin5); step(hsb,y1+y2+y3+y4+y5+0.0001*randn(fSz,1)); end ```

Run the `release` method to let property values and input characteristics change. The scope automatically scales the axes.

`release(hsb);`

Run the MATLAB `clear` function to close the Spectrum Analyzer window.

`clear('hsb');`

This example shows the spectrogram for a chirp signal with added random noise.

```Fs = 233e3; frameSize = 20e3; hchirp = dsp.Chirp('SampleRate',Fs,... 'SamplesPerFrame',frameSize,... 'InitialFrequency',11e3,... 'TargetFrequency',11e3+55e3); hss = dsp.SpectrumAnalyzer('SampleRate',Fs); hss.SpectrumType = 'Spectrogram'; hss.RBWSource = 'Property'; hss.RBW = 500; hss.TimeSpanSource = 'Property'; hss.TimeSpan = 2; hss.PlotAsTwoSidedSpectrum = false; for idx = 1:50 y = step(hchirp)+ 0.05*randn(frameSize,1); step(hss,y); end release(hss) ```

## Signal Display

The Spectrum Analyzer indicates the spectrum computation settings that are represented in the current display. Check the Resolution Bandwidth, Time Resolution, and Offset indicators in the scope status bar for this information. The values specified by these indicators may be changed by modifying parameters in the Spectrum Settings panel. You can also view the object state and the amount of time data that correspond to the current display. Check the Simulation status and Display time indicators for this information. The following figure highlights these aspects of the Spectrum Analyzer window.

• 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 Reduce Plot Rate to Improve Performance option. In the Spectrum Analyzer menu, select Simulation > Reduce Plot Rate to Improve Performance to clear the check box. Tunable.

 Note:   When this check box is selected, 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.

## Spectrum Settings

The Spectrum Settings panel appears at the right side of the Spectrum Analyzer figure. This panel enables you to modify settings to control the manner in which the spectrum is calculated. You can choose to hide or display the Spectrum Settings panel. In the Spectrum Analyzer menu, select View > Spectrum Settings. Alternatively, in the Spectrum Analyzer toolbar, select the Spectrum Settings button.

The Spectrum Settings panel is separated into three panes, labeled Main Options, Window Options, and Trace Options. You can expand each pane to see the available options.

### Main Options Pane

The Main Options pane enables you to modify or view the main options.

• Type — The type of spectrum to display. Available options are `Power`, ```Power density```, and `Spectrogram`. When you set this parameter to `Power`, the Spectrum Analyzer shows the power spectrum. When you set this parameter to ```Power density```, the Spectrum Analyzer shows the power spectral density. The power spectral density is the magnitude of the spectrum normalized to a bandwidth of 1 hertz. When you set this parameter to `Spectrogram`, the Spectrum Analyzer shows the spectrogram, which displays frequency content over time. This parameter is equivalent to the `SpectrumType` property. Tunable.

• Channel — Select the signal channel for which the spectrogram settings apply. This option displays only when the Type is `Spectrogram` and only if there is more than one signal channel input.

• Sample rate (Hz) — The sample rate, in hertz, of the input signals.

• Full frequency span — Enable this check box to have Spectrum Analyzer compute and plot the spectrum over the entire Nyquist frequency interval. By default, when the Two-sided spectrum check box is also enabled, the Nyquist interval is $\left[-\frac{SampleRate}{2},\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz. If you clear the Two-sided spectrum check box, the Nyquist interval is$\left[0,\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz. Enabling this check box is equivalent to setting the `FrequencySpan` property to `'Full'`. Tunable.

• Span (Hz) and CF (Hz), or FStart (Hz) and FStop (Hz) — When Span (Hz) is showing in the Main Options pane, you define the range of values shown on the frequency-axis on the Spectrum Analyzer window using frequency span and center frequency. From the drop-down list, select FStart (Hz) to define the range of frequency-axis values using start frequency and stop frequency instead.

• Span (Hz) — The frequency span, in hertz. This parameter defines the range of values shown on the frequency-axis on the Spectrum Analyzer window. When this parameter is set to a numeric value, then it is equivalent to the `Span` property when the `FrequencySpan` property is set to ```'Span and Center Frequency'```. Tunable.

• CF (Hz) — The center frequency, in hertz. This parameter defines the value shown at the middle point of the frequency-axis on the Spectrum Analyzer window. This parameter is equivalent to the `CenterFrequency` property when the `FrequencySpan` property is set to ```'Span and Center Frequency'```. Tunable.

• FStart (Hz) — The start frequency, in hertz. This parameter defines the value shown at the leftmost side of the frequency-axis on the Spectrum Analyzer window. This parameter is equivalent to the `StartFrequency` property when the `FrequencySpan` property is set to `'Start and stop frequencies'`. Tunable.

• FStop (Hz) — The stop frequency, in hertz. The parameter defines the value shown at the rightmost side of the frequency-axis on the Spectrum Analyzer window. This parameter is equivalent to the `StopFrequency` property when the `FrequencySpan` property is set to ```'Start and stop frequencies'```. Tunable.

• RBW (Hz) / Window length — The frequency resolution method.

If set to RBW (Hz), the resolution bandwidth, in hertz. This parameter defines the smallest positive frequency that can be resolved. By default, this parameter is set to `Auto`. In this case, the Spectrum Analyzer determines the appropriate value to ensure that there are 1024 RBW intervals over the specified Frequency span. This case is equivalent to when you set the `RBWSource` property to `'Auto'`.

If you set this parameter to a numeric value, then you must specify a value that ensures there are at least two RBW intervals over the specified frequency span. In other words, the ratio of the overall span to RBW must be at least two: $\frac{span}{RBW}>2$. In this case, this parameter is equivalent to the `RBW` property, when `RBWSource` is set to `'Property'`.

If set to Window length, the length of the window, in samples, to compute the spectral estimates. The window length must be an integer scalar greater than 2.

. Tunable.

• NFFT — The number of Fast Fourier Transform (FFT) points. This parameter is available only when the frequency resolution method is Window length. This parameter defines the length of the FFT that Spectrum Analyzer uses to compute spectral estimates. Acceptable options are `Auto` or a positive, scalar integer. The NFFT (`FFTLength`) value must be greater than or equal to the `WindowLength`. By default, when NFFT is set to `Auto`, Spectrum Analyzer sets the number of FFT points to the window length or 1024, whichever is larger. This case is equivalent to when you set the `FFTLengthSource` property to `'Auto'`.

When this parameter is set to a positive integer, this parameter is equivalent to the `n` parameter that you can set when you run the MATLAB `fft` function. In this case, this parameter is also equivalent to `FFTLength` when you set `FFTLengthSource` to `'Property'`. Tunable.

• Time res. (s) — The time resolution, in seconds. This parameter is available only in spectrogram mode. Time resolution is the amount of data, in seconds, used to compute a spectrogram line. The minimum attainable resolution is the amount of time required to compute a single spectral estimate. The tooltip displays the minimum attainable resolution, based on the current settings. When the `SpectrumType` property is set to `'Spectrogram'`, you can get or set the minimum attainable resolution value from the `TimeResolution` property. Tunable.

• Time span (s) — The time span over which the Spectrum Analyzer displays the spectrogram, in seconds. This parameter is available only in spectrogram mode. The time span is the product of the number of spectral lines you want and the time resolution. The tooltip displays the minimum allowable time span, given the current settings. If the time span is set to `Auto`, 100 spectral lines are used. This parameter is equivalent to the `TimeSpan` property when the `SpectrumType` property is set to `'Spectrogram'`. Tunable.

• Samples/update — The number of input samples required to compute one spectral update. You cannot modify this parameter; it is shown here for display purposes only. This parameter is directly related to RBW by the following equation: ${N}_{samples}=\frac{\left(1-\frac{{O}_{p}}{100}\right)×NENBW×{F}_{s}}{RBW}$ or to the window length by this equation: . NENBW is the normalized effective noise bandwidth, a factor of the windowing method used, which is shown in the Window Options pane. Fs is the sample rate. If the number of samples provided in the input are not sufficient to achieve the resolution bandwidth that you specify, Spectrum Analyzer produces a message on the display as shown in the following figure.

### Window Options Pane

The Window Options pane enables you to modify the window options.

• Overlap (%) — The segment overlap percentage. This parameter defines the amount of overlap between the previous and current buffered data segments. The value must be greater than or equal to zero and less than 100. This parameter is equivalent to the `OverlapPercent` property. Tunable.

• Window — The windowing method to apply to the spectrum. Windowing is used to control the effect of sidelobes in spectral estimation. The window you specify affects the segment length required to achieve a resolution bandwidth and the required number of samples per update. For more information about windowing, see the Window Function block. This parameter is equivalent to the `Window` property. Tunable.

• Attenuation (dB) — The sidelobe attenuation, in decibels (dB). This property applies only when you set the Window parameter to `Chebyshev` or `Kaiser`. You must specify a value greater than or equal to `45`. If you use a Chebyshev window and set the sidelobe attenuation to less than 35 dB, the desired resolution bandwidth may not be achieved. This parameter is equivalent to the `SidelobeAttenuation` property. Tunable.

• NENBW — Normalized Effective Noise Bandwidth of the window. You cannot modify this parameter; it is a readout shown here for display purposes only. This parameter is a measure of the noise performance of the window. It is the width of a rectangular filter that accumulates the same noise power with the same peak power gain. NENBW can be calculated from the windowing function using the following equation: . The rectangular window has the smallest NENBW, with a value of 1. All other windows have a larger NENBW value. For example, the Hann window has an NENBW value of approximately 1.5.

### Trace Options Pane

The Trace Options pane enables you to modify the trace options.

• Units — The units of the spectrum. Available options are `dBm`, `dBW`, and `Watts`. This parameter is equivalent to the `PowerUnits` property. Tunable.

• Averages — Specify as a positive, scalar integer the number of spectral averages. This parameter applies only when the Spectrum Type is `Power` or ```Power density```. Spectrum Analyzer computes the current power spectrum estimate by averaging the last N power spectrum estimates. This property defines the number of spectral averages, N. This parameter is equivalent to the `SpectralAverages` property. Tunable.

• Reference load — The reference load, in ohms, used to scale the spectrum. Specify as a real, positive scalar the load, in ohms, that the Spectrum Analyzer uses as a reference to compute power values. This parameter is equivalent to the `ReferenceLoad` property. Tunable.

• Scale — Linear or logarithmic scale. When the frequency span contains negative frequency values, Spectrum Analyzer disables the logarithmic option. This parameter is equivalent to the `FrequencyScale` property. Tunable.

• Offset — The constant frequency offset to apply to the entire spectrum or a vector of frequencies to apply to each spectrum for multiple inputs. The constant offset parameter is added to the values on the frequency-axis in the Spectrum Analyzer window. It is not used in any spectral computations. You must take this parameter into consideration when you set the Span (Hz) and CF (Hz) parameters to ensure that the frequency span is within Nyquist limits. The Nyquist interval is $\left[-\frac{SampleRate}{2},\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz if Two-sided spectrum is selected, and $\left[0,\frac{SampleRate}{2}\right]+FrequencyOffset$ hertz otherwise. This parameter is equivalent to the `FrequencyOffset` property.

• Normal trace — Normal trace view. This parameter applies only when the Spectrum Type is `Power` or ```Power density```. By default, when this check box is enabled, Spectrum Analyzer calculates and plots the power spectrum or power spectrum density computed by the Welch estimator. The Welch estimator performs a smoothing operation by averaging a number of spectral estimates. To clear this check box, you must first select either the Max hold trace or the Min hold trace check box. This parameter is equivalent to the `PlotNormalTrace` property. Tunable.

• Max hold trace — Maximum hold trace view. This parameter applies only when the Spectrum Type is `Power` or ```Power density```. Select this check box to enable Spectrum Analyzer to plot the maximum spectral values of all the estimates obtained. This parameter is equivalent to the `PlotMaxHoldTrace` property. Tunable.

• Min hold trace — Minimum hold trace view. This parameter applies only when the Spectrum Type is `Power` or ```Power density```. Select this check box to enable Spectrum Analyzer to plot the minimum spectral values of all the estimates obtained. This parameter is equivalent to the `PlotMinHoldTrace` property. Tunable.

• Two-sided spectrum — Select this check box to enable two-sided spectrum view. In this view, both negative and positive frequencies are shown. If you clear this check box, Spectrum Analyzer shows a one-sided spectrum with only positive frequencies. Spectrum Analyzer requires that this parameter is selected when the input signal is complex-valued. When your signal includes DC input, you should display a two-sided spectrum to resolve low frequency power and DC power. This parameter is equivalent to the property.

## Measurements Panels

The Measurements panels are the panels that appear to the right side of the Spectrum Analyzer figure. .

 Note:   When `SpectrumType` is `'Spectrogram'`, the Measurements panels are not available.

### Trace Selection Panel

When you use the scope to view multiple signals, the Trace Selection panel appears if you have more than one signal displayed and you click any of the other Measurements panels. The Measurements panels display information about only the signal chosen in this panel. Choose the signal name for which you would like to display time domain measurements. See the following figure.

You can choose to hide or display the Trace Selection panel. In the Scope menu, select Tools > Measurements > Trace Selection.

### 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 appears as follows for power and power density spectra.

The Cursor Measurements panel appears as follows for spectrograms.

 Note:   You must pause the spectrogram display before you can use cursors.

The Cursor Measurements panel is separated into two panes, labeled Settings and Measurements. You can expand each pane to see the available options.

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.

The Settings pane enables you to 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 power and power density spectra only).

• Horizontal — Shows horizontal screen cursors (for power and power density spectra only).

• Vertical — Shows vertical screen cursors (for power and power density spectra only).

• Waveform Cursors — Shows cursors that attach to the input signals (for power and power density spectra only).

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

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

### Peak Finder Panel

 Note:   The Peak Finder panel requires a DSP System Toolbox™ or Simscape™ license.

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 to be peaks. This panel allows you to modify the settings for peak threshold, maximum number of peaks, and peak excursion. You can choose to hide or display the Peak Finder panel. In the scope menu, select Tools > Measurements > Peak Finder. Alternatively, in the scope toolbar, select the Peak Finder button.

The Peak finder panel is separated into two panes, labeled Settings and Peaks. You can expand each pane to see the available options.

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 Signal Processing Toolbox `findpeaks` function reference.

• 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 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, 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 all of 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 sort descending button ( ) to rearrange the category and order by which Peak Finder displays peak values. Click this button again to sort the peaks in ascending order instead. When you do so, the arrow changes direction to become the sort ascending button ( ). A filled sort button indicates that the peak values are currently sorted in the direction of the button arrow. If the sort button is not filled ( ), then the peak values are sorted in the opposite direction of the button arrow. The Max Num of Peaks parameter still controls the number of peaks listed.

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 all the peak values on the display, select the check box in the top-left corner of the Peaks pane. To hide all the peak values on the display, clear this check box. To show an individual peak, select the check box directly to the left of its Value listing. To hide an individual peak, clear the check box directly to the left of its Value listing.

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. You can choose to hide or display this pane in the Scope menu by selecting Tools > Measurements > Channel Measurements. Alternatively, in the Scope toolbar, click the Cursor 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 — Enables you to 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. You can choose to hide or display this panel in the Scope menu by selecting Tools > Measurements > Distortion Measurements. Alternatively, in the Scope 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 Algorithms 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 best view the 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. Additionally, the noise floor should be visible. Using a Kaiser window with a large sidelobe attenuation may help to reduce the skirts.
• Num. Harmonics — Number of harmonics to display, including the fundamental frequency. Valid values of Num. Harmonics are from `2` to `10`. 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 one 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 = 10log10(D/S).

• 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 = 10log10(S/N). If you see – – as the reported SNR, your signal's total non-harmonic content 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 = 10log10(S/(N+D).

• 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. SFDR = 10log10(S/R).

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.

You can choose to hide or display this panel in the Scope menu by selecting Tools > Measurements > CCDF Measurements. Alternatively, in the Scope toolbar, click the CCDF Measurements button.

• Plot Gaussian reference — Select Plot Gaussian reference to 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.

## Visuals — Spectrum Properties

The Visuals—Spectrum Properties dialog box controls the visual configuration settings of the Spectrum Analyzer display. From the Spectrum Analyzer menu, select View > Configuration Properties to open this dialog box. Alternatively, in the Spectrum Analyzer toolbar, click the Configuration Properties button.

### Display Pane

When the Spectrum Type is `Power` or ```Power density```, the Display pane of the Visuals—Spectrum Properties dialog box appears as follows:

When the Spectrum Type is `Spectrogram` the Display pane of the Visuals—Spectrum Properties dialog box appears as follows:

#### Title

Specify the display title as a character vector. Enter `%<SignalLabel>` to use the signal labels in the Simulink Model as the axes titles. This property is Tunable.

By default, the display has no title.

#### Show legend

Select this check box to show the legend in the display. The channel legend displays a name for each channel of each input signal. When the legend appears, you can place it anywhere inside of the scope window. To turn off the legend, clear the Show legend check box. This parameter applies only when the Spectrum Type is `Power` or ```Power density```. Tunable

You can edit the name of any channel in the legend. To do so, double-click the current name, and enter a new channel name. By default, if the signal has multiple channels, the scope uses an index number to identify each channel of that signal. To change the appearance of any channel of any input signal in the scope window, from the scope menu, select View > Style.

#### Show grid

When you select this check box, a grid appears in the display of the scope figure. To hide the grid, clear this check box. Tunable

#### Y-limits (Minimum)

Specify the minimum value of the y-axis. Tunable

#### Y-limits (Maximum)

Specify the maximum value of the y-axis. Tunable

#### Y-axis label

Specify the text for the scope to display to the left of the y-axis. Regardless of this property, Spectrum Analyzer always displays power units after this text as one of `'dBm'`, `'dBW'`, `'Watts'`, `'dBm/Hz'`, `'dBW/Hz'`, or `'Watts/Hz'`. Tunable.

#### Color map

Select the color map for the spectrogram, or enter a 3-column matrix expression for the color map. See `colormap` for information. Tunable.

#### Color-limits (Minimum)

Set the signal power for the minimum color value of the spectrogram. Tunable.

#### Color-limits (Maximum)

Set the signal power for the maximum color value of the spectrogram. Tunable.

## Style Dialog Box

In the Style dialog box, you can customize the style of power and power density displays. This dialog box is not available in spectrogram view. You are able to change the color of the figure, the background and foreground colors of the axes, and properties of the lines. From the Spectrum Analyzer menu, select View > Style to open this dialog box.

### Properties

The Style dialog box allows you to modify the following properties of the Spectrum Analyzer figure:

#### Figure color

Specify the color that you want to apply to the background of the scope figure. By default, the figure color is gray.

#### Plot type

Specify whether to display a `Line` or `Stem` plot.

#### Axes colors

Specify the color that you want to apply to the background of the axes.

#### Properties for line

Specify the channel for which you want to modify the visibility, line properties, and marker properties.

#### Visible

Specify whether the selected channel should be visible. If you clear this check box, the line disappears.

#### Line

Specify the line style, line width, and line color for the selected channel.

#### Marker

Specify marks for the selected channel to show at its data points. This parameter is similar to the `Marker` property for plot objects. You can choose any of the marker symbols from the dropdown.

## Tools — Axes Scaling Properties

The Tools—Axes Scaling Properties dialog box allows you to automatically zoom in on and zoom out of your data. You can also scale the axes of the Spectrum Analyzer. In the Spectrum Analyzer menu, select Tools > Scaling Properties to open this dialog box.

### Properties

The Tools—Axes Scaling Properties dialog box appears as follows for power and power density views.

For spectrogram view, the Tools—Axes Scaling Properties dialog box appears as follows.

#### Axes scaling/Color scaling

Specify when the scope automatically scales the axes. If the spectrogram is displayed, specify when the scope automatically scales the color. You can select one of the following options:

• `Manual` — When you select this option, the scope does not automatically scale the axes or color. You can manually scale the axes or color in any of the following ways:

• Select Tools > Scaling Properties.

• Press one of the Scale Axis Limits toolbar buttons.

• When the scope figure is the active window, press Ctrl and A simultaneously.

• `Auto` — When you select this option, the scope scales the axes or color as needed, both during and after simulation. Selecting this option shows the Do not allow Y-axis limits to shrink or Do not allow color limits to shrink .

• `After N Updates` — Selecting this option causes the scope to scale the axes or color after a specified number of updates. This option is useful and more efficient when your scope display starts with one axis scale, but quickly reaches a different steady state axis scale. Selecting this option shows the Number of updates edit box.

By default, this parameter is set to `Auto`, and the scope does not shrink the y-axis limits when scaling the axes or color. Tunable.

#### Do not allow Y-axis limits to shrink / Do not allow color limits to shrink

When you select this property, the y-axis are allowed to grow during axes scaling operations. If the spectrogram is displayed, selecting this property allows the color limits to grow during axis scaling. If you clear this check box, the y-axis or color limits can shrink during axes scaling operations.

This property appears only when you select `Auto` for the Axis scaling or Color scaling property. When you set the Axes scaling or Color scaling property to `Manual` or ```After N Updates```, the y-axis or color limits can shrink. Tunable.

#### Number of updates

Specify as a positive integer the number of updates after which to scale the axes. If the spectrogram is displayed, this property specifies the number of updates after which to scale the color. This property appears only when you select `After N Updates` for the Axes scaling or Color scaling property. Tunable.

#### Scale axes limits at stop/Scale color limits at stop

Select this check box to scale the axes when the simulation stops. If the spectrogram is displayed, select this check box to scale the color when the simulation stops. The y-axis is always scaled. The x-axis limits are only scaled if you also select the Scale X-axis limits check box.

#### Y-axis Data range (%) / Color-limits Data range

Set the percentage of the y-axis that the scope uses to display the data when scaling the axes. If the spectrogram is displayed, set the percentage of the power values range within the colormap. Valid values are from 1 through 100. For example, if you set this property to `100`, the Scope scales the y-axis limits such that your data uses the entire y-axis range. If you then set this property to `30`, the scope increases the y-axis range or color such that your data uses only 30% of the y-axis range or color. Tunable.

#### Y-axis Align / Color-limits Align

Specify where the scope aligns your data along the y-axis when it scales the axes. If the spectrogram is displayed, specify where the scope aligns your data along the y-axis when it scales the color. You can select `Top`, `Center`, or `Bottom`. Tunable.

#### Autoscale X-axis limits

Check this box to allow the scope to scale the x-axis limits when it scales the axes. If Axes scaling is set to `Auto`, checking Autoscale X-axis limits only scales the data currently within the axes, not the entire signal in the data buffer. If Autoscale X-axis limits is on and the resulting axis is greater than the span of the scope, trigger position markers will not be displayed. Triggers are controlled using the Trigger Measurements panel. Tunable.

#### X-axis Data range (%)

Set the percentage of the x-axis that the scope uses to display the data when scaling the axes. Valid values are from 1 through 100. For example, if you set this property to `100`, the scope scales the x-axis limits such that your data uses the entirex-axis range. If you then set this property to `30`, the scope increases the x-axis range such that your data uses only 30% of the x-axis range. Use the x-axis Align property to specify data placement along the x-axis.

This property appears only when you select the Scale X-axis limits check box. Tunable.

#### X-axis Align

Specify how the scope aligns your data along the x-axis: `Left`, `Center`, or `Right`. This property appears only when you select the Scale X-axis limits check box. Tunable.

## Algorithms

Spectrum Analyzer uses the `RBW` or the `Window Length` setting in the Spectrum Settings panel to determine the data window length. The value of the `FrequencyResolutionMethod` property determines whether RBW or window length is used. Then, it partitions the input signal into a number of windowed data segments. Finally, Spectrum Analyzer uses the modified periodogram method to compute spectral updates, averaging the windowed periodograms for each segment.

1. Spectrum Analyzer requires that a minimum number of samples have been provided before it computes a spectral estimate. This number of input samples required to compute one spectral update is shown as Samples/update in the Main options pane. This value is directly related to resolution bandwidth, RBW, by the following equation or to the window length, by the equation shown in step 1b.

${N}_{samples}=\frac{\left(1-\frac{{O}_{p}}{100}\right)×NENBW×{F}_{s}}{RBW}$

The normalized effective noise bandwidth, NENBW, is a factor that depends on the windowing method. Spectrum Analyzer shows NENBW in the Window Options pane of the Spectrum Settings panel. Overlap percentage, Op, is the value of the Overlap % parameter in the Window Options pane of the Spectrum Settings panel. Fs is the sample rate of the input signal. Spectrum Analyzer shows sample rate in the Main Options pane of the Spectrum Settings panel.

1. When in RBW mode, the window length required to compute one spectral update, Nwindow, is directly related to the resolution bandwidth and normalized effective noise bandwidth by the following equation.

When in WindowLength mode, the window length is used as specified.

2. The number of input samples required to compute one spectral update, Nsamples, is directly related to the window length and the amount of overlap by the following equation.

When you increase the overlap percentage, fewer new input samples are needed to compute a new spectral update. For example, if the window length is 100, then the number of input samples required to compute one spectral update is given as shown in the following table.

OpNsamples
0%100
50%50
80%20

3. The normalized effective noise bandwidth, NENBW, is a window parameter determined by the window length, Nwindow, and the type of window used. If w(n) denotes the vector of Nwindow window coefficients, then NENBW is given by the following equation.

4. When in RBW mode, you can set the resolution bandwidth using the value of the RBW parameter on the Main options pane of the Spectrum Settings panel. You must specify a value to ensure that there are at least two RBW intervals over the specified frequency span. The ratio of the overall span to RBW must be greater than two, as given in the following equation.

$\frac{span}{RBW}>2$

By default, the RBW parameter on the Main options pane is set to `Auto`. In this case, the Spectrum Analyzer determines the appropriate value to ensure that there are 1024 RBW intervals over the specified frequency span. Thus, when you set RBW to `Auto`, it is calculated by the following equation.$RB{W}_{auto}=\frac{span}{1024}$

5. When in window length mode, you specify Nwindow and the resulting RBW is

In some cases, the number of samples provided in the input are not sufficient to achieve the resolution bandwidth that you specify. When this situation occurs, Spectrum Analyzer produces a message on the display, as shown in the following figure.

Spectrum Analyzer removes this message and displays a spectral estimate as soon as enough data has been input. Notice that this behavior differs from the Spectrum Scope block in versions R2012b and earlier. If the Buffer input check box was selected, the Spectrum Scope block computed a spectral update using the number of samples given by the Buffer size parameter. Otherwise, the Spectrum Scope block computed a spectral update using the number of samples in each frame.

2. Spectrum Analyzer calculates and plots the power spectrum, power spectrum density, or spectrogram computed by the modified Periodogram estimator. For more information about the Periodogram method, see `periodogram` in the Signal Processing Toolbox documentation.

Power Spectral Density — The power spectral density (PSD) is given by the following equation.

In this equation, x[n] is the discrete input signal. On every input signal frame, Spectrum Analyzer generates as many overlapping windows as possible, each window denoted as x(p)[n], and computes their periodograms. Spectrum Analyzer displays a running average of the P most current periodograms.

Power Spectrum — The power spectrum is the product of the power spectral density and the resolution bandwidth, as given by the following equation.

Spectrogram — Each line of the spectrogram is one periodogram. The time resolution of each line is 1/RBW, which is the minimum attainable resolution. Achieving the resolution you want may require combining several periodograms may be combined. You then useinterpolation to calculate noninteger values of 1/RBW. In the spectrogram display, time scrolls from bottom to top, so the most recent data is shown at the bottom of the display. The offset shows the time value at which the center of the most current spectrogram line occurred.

 Note:   The number of FFT points (Nfft) is independent of the window length (Nwindow). You can set them to different values provided that Nfft is greater than or equal to Nwindow.

The Occupied BW is calculated as follows.

• Calculate the total power in the measured frequency range.

• Determine the lower frequency value. Starting at the lowest frequency in the range and moving upward, the power distributed in each frequency is summed until this sum is of the total power.

• Determine the upper frequency value. Starting at the highest frequency in the range and moving downward, the power distributed in each frequency is summed until it reaches of the total power.

• The bandwidth between the lower and upper power frequency values is the occupied bandwidth.

• The frequency halfway between the lower and upper frequency values is the center frequency.

The Distortion Measurements are computed as follows.

1. Spectral content is estimated by finding peaks in the spectrum. When the algorithm detects a peak, it ignores all adjacent content that decreases monotonically from the peak. After recording the width of the peak, it clears all monotonically decreasing values (that is, it treats all of these values as if they belong to the peak). Using this method, all spectral content centered at DC (0 Hz) is removed from the spectrum and the amount of bandwidth cleared (W0) is recorded.

2. The fundamental power (P1) is determined from the remaining maximum value of the displayed spectrum. A local estimate (Fe1) of the fundamental frequency is made by computing the central moment of the power in the vicinity of the peak. The bandwidth of the fundamental power content (W1) is recorded. Then, the power associated from the fundamental is removed as in step 1.

3. The power and width of the second, and higher order harmonics (P2, W2, P3, W3, etc.) are determined in succession by examining the frequencies closest to the appropriate multiple of the local estimate (Fe1). Any spectral content that decreases in a monotonically about the harmonic frequency is removed from the spectrum first before proceeding to the next harmonic.

4. Once the DC, fundamental, and harmonic content is removed from the spectrum, the power of the remaining spectrum is examined for its sum (Premaining) peak value (Pmaxspur), and its median value (Pestnoise).

5. The sum of all the removed bandwidth is computed as Wsum = W0+W1+W2+...+Wn.

The sum of powers of the second and higher order harmonics are computed as Pharmonic = P2+P3+P4+...+Pn.

6. The sum of the noise power is then estimated as Pnoise = (Premaining*dF + Pestnoise*Wsum)/RBW, where dF is the absolute difference between frequency bins, and RBW is the resolution bandwidth of the window.

7. The metrics for SNR, THD, SINAD, and SFDR are then computed from the estimates.

• THD = 10*log10(Pharmonic/P1)

• SINAD = 10*log10(P1/(Pharmonic + Pnoise)

• SNR = 10*log10(P1/Pnoise)

• SFDR = 10*log10(P1/max(Pmaxspur, max(P2,P3,...,Pn))

The following considerations apply to Distortion Measurements.

• The harmonic distortion measurements use the spectrum trace shown in the display as the input to the measurements. The default `Hann` window setting of the Spectrum Analyzer may exhibit leakage that can completely mask the noise floor of the measured signal.

The harmonic measurements attempt to correct for leakage by ignoring all frequency content that decreases monotonically away from the maximum of harmonic peaks. If the window leakage covers more than 70% of the frequency bandwidth in your spectrum, you may see a blank reading (–) reported for SNR and SINAD. Consider using a Kaiser window with a high attenuation (up to 330dB) to minimize spectral leakage if your application can tolerate the increased equivalent noise bandwidth (ENBW) of the Kaiser window.

• The DC component is ignored.

• After windowing, the width of each harmonic component masks the noise power in the neighborhood of the fundamental frequency and harmonics. To estimate the noise power in each region, Spectrum Analyzer computes the median noise level in the nonharmonic areas of the spectrum. It then extrapolates that value into each region.

• Nth order intermodulation products occur at

A*F1 + B*F2

where F1 and F2 are the sinusoid input frequencies and |A| + |B| = N. A and B are integer values.

• For intermodulation measurements, the third-order intercept (TOI) point is computed as follows, where P is power in decibels of the measured power referenced to one milliwatt (dBm).:

• TOIlower = PF1 + (PF2 - P(2F1-F2))/2

• TOIupper = PF2 + (PF1 - P(2F2-F1))/2

• TOI = + (TOIlower + TOIupper)/2