Main Content

Display frequency spectrum of time-domain signals

The Spectrum Analyzer System object™ 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:

Create the

`dsp.SpectrumAnalyzer`

object and set its properties.Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

`scope = dsp.SpectrumAnalyzer`

creates a Spectrum Analyzer
System object. This object displays the frequency spectrum of real- and complex-valued
floating- and fixed-point signals.

`scope = dsp.SpectrumAnalyzer(ports)`

creates a Spectrum Analyzer object and sets the NumInputPorts property to the value of `ports`

.

`scope = dsp.SpectrumAnalyzer(Name,Value)`

sets properties using one or more name-value pairs.
Enclose each property name in single quotes.

Unless otherwise indicated, properties are *nontunable*, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
`release`

function unlocks them.

If a property is *tunable*, you can change its value at
any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

`NumInputPorts`

— Number of input ports`1`

(default) | integer between [1, 96]Number of input ports, specified as a positive integer. Each signal coming through a separate input becomes a separate channel in the scope. You must invoke the scope with the same number of inputs as the value of this property.

`InputDomain`

— Domain of the input signal`"Time"`

(default) | `"Frequency"`

The domain of the input signal you want to visualize. If you visualize time-domain signals, the signal is transformed to the frequency spectrum based on the algorithm specified by the Method parameter.

Open the **Spectrum Settings**. In the **Main options** section, set
**Input Domain**.

**Data Types: **`char`

| `string`

`SpectrumType`

— Type of spectrum to show`"Power"`

(default) | `"Power density"`

| `"RMS"`

Specify the spectrum type to display.

`"Power"`

— Power spectrum

`"Power density"`

— Power spectral density. The power spectral density is the magnitude squared of
the spectrum normalized to a bandwidth of 1 hertz.

`"RMS"`

— Root mean square. The root-mean-square shows the square
root of the mean square. This option is useful when viewing the frequency of voltage or
current signals.

**Tunable: **Yes

Open the **Spectrum Settings**. In the **Main options** section, set **Type**.

**Data Types: **`char`

| `string`

`ViewType`

— Viewer type`"Spectrum"`

(default) | `"Spectrogram"`

| `"Spectrum and spectrogram"`

Specify the spectrum type as one of `"Spectrum"`

, `"Spectrogram"`

, or
`"Spectrum and spectrogram"`

.

`"Spectrum"`

— shows the power spectrum.`"Spectrogram"`

— 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.`"Spectrum and Spectrogram"`

— shows a dual view of a spectrum and spectrogram.

**Tunable: **Yes

Open the **Spectrum Settings**. In the **Main options** section, set
**View**.

**Data Types: **`char`

| `string`

`SampleRate`

— Sample rate of input`10000`

(default) | finite scalarSpecify the sample rate, in hertz, of the input signals as a finite numeric scalar.

Open the **Spectrum Settings**. In the **Main options** section, set
**Sample rate (Hz)**.

`Method`

— Spectrum estimation method`"Welch"`

(default) | `"Filter Bank"`

Specify the spectrum estimation method as `Welch`

or `Filter bank`

.

To enable this property, set InputDomain to
`"Time"`

.

Open the **Spectrum Settings**. In the **Main options** section, set
**Method**.

**Data Types: **`char`

| `string`

`PlotAsTwoSidedSpectrum`

— Two-sided spectrum flag`true`

(default) | `false`

`true`

— Compute and plot two-sided spectral estimates. When the input signal is complex-valued, you must set this property to`true`

.`false`

— Compute and plot one-sided spectral estimates. If you set this property to`false`

, then the input signal must be real-valued.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 power spectral density (PSD) contains the total power of the signal in the frequency interval from DC to half of the Nyquist rate. For more information, see`pwelch`

.

Open the **Spectrum Settings**. In the **Trace options** section, select
**Two-sided spectrum**.

**Data Types: **`logical`

`FrequencyScale`

— Frequency scale`"Linear"`

(default) | `"Log"`

`"Log"`

— 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`

.`"Linear"`

— displays the frequencies on the*x*-axis on a linear scale. To use the`"Linear"`

setting, you must also set the`PlotAsTwoSidedSpectrum`

property to`true`

.

**Tunable: **Yes

Open the **Spectrum Settings**. In the **Trace options** section, set
**Scale**.

**Data Types: **`char`

| `string`

`FrequencySpan`

— Frequency span mode`"Full"`

(default) | `"Span and center frequency"`

| `"Start and stop frequencies"`

`"Full"`

- The Spectrum Analyzer computes and plots the spectrum over the entire Nyquist frequency interval.`"Span and center frequency"`

- The Spectrum Analyzer computes and plots the spectrum over the interval specified by the Span and CenterFrequency properties.`"Start and stop frequencies"`

- The Spectrum Analyzer computes and plots the spectrum over the interval specified by the StartFrequency and StopFrequency properties.

**Tunable: **Yes

Open the **Spectrum Settings**. In the **Main options** section, select
**Full frequency span** for `"Full"`

. Otherwise, clear the **Full
frequency span** check box and choose between `Span`

or
`FStart`

.

**Data Types: **`char`

| `string`

`Span`

— Frequency span to compute spectrum`10e3`

(default) | real positive scalarSpecify the frequency span, in hertz, over which the Spectrum Analyzer computes and plots the spectrum. The overall span, defined by this property and the CenterFrequency property, must fall within the Nyquist frequency interval.

**Tunable: **Yes

To enable this property, set FrequencySpan to ```
"Span and center
frequency"
```

.

Open the **Spectrum Settings**. In the **Main options** section, clear the
**Full frequency span** check box and set `Span`

.

`StartFrequency`

— Start frequency to compute spectrum`-5e3`

(default) | real scalarStart of the frequency interval over which spectrum is computed, specified in hertz as a real scalar. The overall span, which is defined by this property and StopFrequency, must fall within the Nyquist frequency interval.

**Tunable: **Yes

To enable this property, set FrequencySpan to ```
"Start and stop
frequencies"
```

.

Open the **Spectrum Settings**. In the **Main options** section, clear the
**Full frequency span** and change `Span`

to
`FStart`

. Set **FStart (Hz)**.

`StopFrequency`

— Stop frequency to compute spectrum`5e3`

(default) | real scalarEnd of the frequency interval over which spectrum is computed, specified in hertz as a real scalar. The overall span, which is defined by this property and the StartFrequency property, must fall within the Nyquist frequency interval.

**Tunable: **Yes

To enable this property, set FrequencySpan to ```
"Start and stop
frequencies"
```

.

Open the **Spectrum Settings**. In the **Main options** section, clear the
**Full frequency span** and change `Span`

to
`FStart`

. Set **FStop (Hz)**.

`CenterFrequency`

— Center of frequency span`0`

(default) | real scalarSpecify in hertz the center frequency of the span over which the Spectrum Analyzer computes and plots the spectrum. The overall frequency span, defined by the Span and this property, must fall within the Nyquist frequency interval.

**Tunable: **Yes

To enable this property, set FrequencySpan to ```
"Span and center
frequency"
```

.

Open the **Spectrum Settings**. In the **Main**, clear **Full
frequency span** and set **CF (Hz)**.

`FrequencyResolutionMethod`

— Frequency resolution method`"RBW"`

(default) | `"WindowLength"`

| `"NumFrequencyBands"`

Specify the frequency resolution method of the Spectrum Analyzer.

`"RBW"`

- the RBWSource and RBW properties control the frequency resolution (in Hz) of the analyzer. The FFT length is the window length that results from achieving the specified RBW value or 1024, whichever is larger.`"WindowLength"`

- applies only when the Method property is set to`"Welch"`

. The WindowLength property controls the frequency resolution. You can control the number of FFT points only when the`FrequencyResolutionMethod`

property is`"WindowLength"`

.`"NumFrequencyBands"`

- applies only when the Method property is set to`"Filter Bank"`

. The`FFTLengthSource`

and`FFTLength`

properties control the frequency resolution.

**Tunable: **Yes

To enable this property, set InputDomain to
`"Time"`

.

Open the **Spectrum Settings**. In the **Main options** section, set the
frequency resolution method by selecting the **RBW (Hz)** dropdown.

**Data Types: **`char`

| `string`

`RBWSource`

— Source of resolution bandwidth value`"Auto"`

(default) | `"Property"`

Specify the source of the resolution bandwidth (RBW) as either `"Auto"`

or
`"Property"`

.

`"Auto"`

— The Spectrum Analyzer adjusts the spectral estimation resolution to ensure that there are 1024 RBW intervals over the defined frequency span.`"Property"`

— Specify the resolution bandwidth directly using the RBW property.

**Tunable: **Yes

To enable this property, set either:

InputDomain to

`"Time"`

and FrequencyResolutionMethod to`"RBW"`

.`InputDomain`

to`"Frequency"`

.

Open the **Spectrum Settings**. In the **Main options** section, set
**RBW (Hz)**.

**Data Types: **`char`

| `string`

`RBW`

— Resolution bandwidth`9.76`

(default) | real positive scalarRBW controls the spectral resolution of Spectrum Analyzer. Specify the resolution bandwidth in hertz as a real positive scalar. 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.

To enable, set:

RBWSource to

`"Property"`

Open the **Spectrum Settings**. In the **Main options** section, set
**RBW (Hz)**.

`WindowLength`

— Window length`1024`

(default) | integer greater than 2Control 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.

**Tunable: **Yes

To enable this property, set:

FrequencyResolutionMethod to

`"WindowLength"`

, which controls the frequency resolution based on your window length settingMethod to

`"Welch"`

Open the **Spectrum Settings**. Change the **RBW (Hz)** dropdown to
`Window length`

.

`FFTLengthSource`

— Source of the FFT length`"Auto"`

(default) | `"Property"`

`"Auto"`

- sets the FFT length to the window length specified in the WindowLength property or 1024, whichever is larger.`"Property"`

- number of FFT points using the`FFTLength`

property.`FFTLength`

must be greater than`WindowLength`

.

**Tunable: **Yes

To enable this property, set FrequencyResolutionMethod to
`"WindowLength"`

.

Open the **Spectrum Settings**. In the **Main options** section, next to the **RBW (Hz)** option, enter
a number or select `Auto`

.

**Data Types: **`char`

| `string`

`FFTLength`

— Length of FFT`1024`

(default) | positive integerSpecify the length of the FFT that the Spectrum Analyzer uses to compute spectral estimates.

If FrequencyResolutionMethod is
`"RBW"`

, the FFT length is set as the window length required to achieve the specified resolution
bandwidth value or 1024, whichever is larger.

**Tunable: **Yes

To use this property, the following must be true:

FrequencyResolutionMethod is set to

`"WindowLength"`

or`"NumFrequencyBands"`

`FFTLength`

is greater than or equal to the WindowLength.FFTLengthSource is set to

`"Property"`

.

Open the **Spectrum Settings**. In the **Main options** section, next to the
**RBW (Hz)** option, enter a number or select `Auto`

.

`NumTapsPerBand`

— Number of filter taps per frequency band`12`

(default) | positive even scalarSpecify the number of filter taps or coefficients for each frequency band. This number must be a positive even
integer. This value corresponds to the number of filter coefficients per polyphase branch. The total number of
filter coefficients is equal to `NumTapsPerBand`

+ FFTLength.

To enable this property, set Method to `"Filter Bank"`

Open the **Spectrum Settings**. In the **Main options** section, set
**Taps per band**.

`FrequencyVectorSource`

— Source of frequency vector`"Auto"`

(default) | `"Property"`

`"Auto"`

— The frequency vector is calculated from the length of the input. See Frequency Vector.`"Property"`

— Enter a custom vector as the frequency vector.

To enable this property, set InputDomain to
`"Frequency"`

.

Open the **Spectrum Settings**. In the **Frequency input options** section,
set **Frequency (Hz)**.

**Data Types: **`char`

| `string`

`FrequencyVector`

— Custom frequency vector`[-5000 5000]`

(default) | monotonically increasing vectorSet the frequency vector that determines the *x*-axis of the display. The vector must be monotonically
increasing and of the same size as the input frame size.

To enable this property, set `FrequencyVectorSource`

to `"Property"`

.

Open the **Spectrum Settings**. In the **Frequency input options** section, set **Frequency (Hz)**.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`OverlapPercent`

— Overlap percentage`0`

(default) | real, scalar valueThe percentage overlap between the previous and current buffered data segments, specified as a real, scalar value. 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.

**Tunable: **Yes

Open the **Spectrum Settings**. In the **Window options** section, set
**Overlap (%)**.

`Window`

— Window function`"Hann"`

(default) | `"Rectangular"`

| `"Chebyshev"`

| `"Flat Top"`

| `"Hamming"`

| `"Kaiser"`

| `"Blackman-Harris"`

| `"Custom"`

Specify a window function for the spectral estimator. The following table shows preset windows. For more information, follow the link to the corresponding function reference in the Signal Processing Toolbox™ documentation.

Window Option | Corresponding Signal Processing Toolbox Function |
---|---|

`"Rectangular"` | `rectwin` |

`"Chebyshev"` | `chebwin` |

`"Flat Top"` | `flattopwin` |

`"Hamming"` | `hamming` |

`"Hann"` | `hann` |

`"Kaiser"` | `kaiser` |

`"Blackman-Harris"` | `blackmanharris` |

To set your own spectral estimation window, set this property to `"Custom"`

and specify a custom
window function in the CustomWindow property.

**Tunable: **Yes

Open the **Spectrum Settings**. In the **Window options** section, set
**Window**.

**Data Types: **`char`

| `string`

`CustomWindow`

— Custom window function`"hann"`

(default) | character array | string scalarSpecify a custom window function as a character array or string. The custom window function name must be on the MATLAB path. This property is useful if you want to customize the window using additional properties available with the Signal Processing Toolbox version of the window function.

**Tunable: **Yes

Define and use a custom window function.

function w = my_hann(L) w = hann(L, 'periodic') end scope.Window = 'Custom'; scope.CustomWindow = 'my_hann'

To use this property, set Window to `"Custom"`

.

Open the **Spectrum Settings**. In the **Window options** section, in the
**Window** option box, enter a custom window function name.

**Data Types: **`char`

| `string`

`SidelobeAttenuation`

— Sidelobe attenuation of window`60`

(default) | real positive scalarThe window sidelobe attenuation, in decibels (dB). The value must be greater than or equal to
`45`

.

**Tunable: **Yes

To enable this property, set Window to `"Chebyshev"`

or
`"Kaiser"`

.

Open the **Spectrum Settings**. In the **Window options** section, set
**Attenuation (dB)**.

`InputUnits`

— Units of frequency input`"dBm"`

(default) | `"dBV"`

| `"dBW"`

| `"Vrms"`

| `"Watts"`

Select the units of the frequency-domain input. This property allows the Spectrum Analyzer to scale frequency data if you choose a different display unit with the Units property.

This option is only available when InputDomain is set to
`Frequency`

.

Open the **Spectrum Settings**. In the **Frequency input options** section,
set **Input units**.

**Data Types: **`char`

| `string`

`SpectrumUnits`

— Units of the spectrum`"Auto"`

(default) | `"dBm"`

| `"dBFS"`

| `"dBV"`

| `"dBW"`

| `"Vrms"`

| `"Watts"`

Specify the units in which the Spectrum Analyzer displays power values.

**Tunable: **Yes

The available spectrum units depend on the value of SpectrumType.

`InputDomain` | `SpectrumType` | Allowed `SpectrumUnits` |
---|---|---|

`Time` | `Power` or `Power density` | `"dBFS"` , `"dBm"` , `"dBW"` ,
`"Watts"` |

`RMS` | `"Vrms"` , `"dBV"` | |

`Frequency` | ― | `"dBm"` , `"dBV"` , `"dBW"` ,
`"Vrms"` , `"Watts"` , |

Open the **Spectrum Settings**. In the **Trace options** section, set
**Units**.

**Data Types: **`char`

| `string`

`FullScaleSource`

— Source of full scale`"Auto"`

(default) | `"Property"`

Specify the source of the dBFS scaling factor as either `"Auto"`

or
`"Property"`

.

`"Auto"`

- The Spectrum Analyzer adjusts the scaling factor based on the input data.`"Property"`

- Specify the full-scale scaling factor using the`FullScale`

property.

To enable this property, set SpectrumUnits to
`"dBFS"`

.

Open the **Spectrum Settings**. In the **Trace options** section, set **Full
scale** to `Auto`

or enter a number.

**Data Types: **`char`

| `string`

`FullScale`

— Full scale`1`

(default) | positive scalarSpecify a real positive scalar for the `dBFS`

full scale.

**Tunable: **Yes

To enable this option set:

SpectrumUnits to

`"dBFS"`

FullScaleSource to

`"Property"`

Open the **Spectrum Settings**. In the **Trace options** section, set
**Full scale** to `Auto`

or enter a number.

`AveragingMethod`

— Smoothing method`"Running"`

(default) | `"Exponential"`

Specify the smoothing method as:

`Running`

— Running average of the last*n*samples. Use the`SpectralAverages`

property to specify*n*.`Exponential`

— Weighted average of samples. Use the`ForgettingFactor`

property to specify the weighted forgetting factor.

For more information about the averaging methods, see Averaging Method.

To enable this property, set `ViewType`

to
`"Spectrum"`

or ```
"Spectrum and
spectrogram"
```

.

Open the **Spectrum Settings**. In the **Trace options** section, set **Averaging method**.

**Data Types: **`char`

| `string`

`SpectralAverages`

— Number of spectral averages`1`

(default) | positive integerThe Spectrum Analyzer computes the current power spectrum estimate by computing a running average of the last
*N* power spectrum estimates. This property defines *N*.

**Tunable: **Yes

To enable this property, set ViewType to `"Spectrum"`

.

This property applies only when the `AveragingMethod`

is
`"Running"`

.

Open the **Spectrum Settings**. In the **Trace options** section, set
**Averages**.

`ForgettingFactor`

— Weighting forgetting factor`0.9`

(default) | scalar in the range (0,1]Specify the exponential weighting as a scalar value greater than 0 and less than or equal to 1.

This property applies only when the `AveragingMethod`

is
`"Exponential"`

.

Open the **Spectrum Settings**. In the **Trace
options** section, set **Forgetting factor**.

`ReferenceLoad`

— Reference load`1`

(default) | real positive scalarThe load the scope uses as a reference to compute power levels.

**Tunable: **Yes

Open the **Spectrum Settings**. In the **Trace options** section, set
**Reference load**.

`FrequencyOffset`

— Frequency offset`0`

(default) | scalar | vectorScalar — Apply the same frequency offset to all channels, specified in hertz as a character vector.

Vector — apply a specific frequency offset for each channel, specify a vector of frequencies. 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. You can control the overall span in different ways based on how you set the

`FrequencySpan`

property.

**Tunable: **Yes

Open the **Spectrum Settings**. In the **Trace options** section, set
**Offset (Hz)**.

`SpectrogramChannel`

— Channel for which spectrogram is plotted`1`

(default) | positive scalar integerSpecify the channel for which the spectrogram is plotted, as a real, positive scalar integer in the range [1
*N*], where *N* is the number of input channels.

**Tunable: **Yes

To enable this property, set ViewType to
`"Spectrogram"`

or `"Spectrum and spectrogram"`

.

Open the **Spectrum Settings**. In the **Spectrogram options** section,
select a **Channel**.

`TimeResolutionSource`

— Source of the time resolution value`"Auto"`

(default) | `"Property"`

Specify the source for the time resolution of each spectrogram line as either
`"Auto"`

or `"Property"`

. The TimeResolution
property shows the time resolution for the different frequency resolution methods and
time resolution properties.

**Tunable: **Yes

To enable this property, set ViewType to
`"Spectrogram"`

or ```
"Spectrum and
spectrogram"
```

.

Open the **Spectrum Settings**. In the **Spectrogram options** section, set
**Time res (s)**.

**Data Types: **`char`

| `string`

`TimeResolution`

— Time resolution`0.001`

(default) | positive scalarSpecify the time resolution of each spectrogram line as a positive scalar, expressed in seconds.

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

Method | Frequency Resolution Method | Frequency Resolution Setting | Time Resolution Setting | Resulting Time Resolution in Seconds |
---|---|---|---|---|

`Welch` or `Filter Bank` | `RBW (Hz)` | `Auto` | `Auto` | 1/RBW |

`Welch` or `Filter Bank` | `RBW (Hz)` | `Auto` | Manually entered | Time Resolution |

`Welch` or `Filter Bank` | `RBW (Hz)` | Manually entered | `Auto` | 1/RBW |

`Welch` or `Filter Bank` | `RBW (Hz)` | Manually entered | Manually entered | Must be equal to or greater than the minimum attainable time resolution, 1/RBW. 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. |

`Welch` | `Window length` | — | `Auto` | 1/RBW |

`Welch` | `Window length` | — | Manually entered | Must be equal to or greater than the minimum attainable time resolution. 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. |

`Filter Bank` | `Number of frequency bands` | — | `Auto` | 1/RBW |

`Filter Bank` | `Number of frequency bands` | — | Manually entered | Must be equal to or greater than the minimum attainable time resolution, 1/RBW. |

**Tunable: **Yes

To enable this property, set:

ViewType to

`"Spectrogram"`

or`"Spectrum and spectrogram"`

TimeResolutionSource to

`"Property`

.

Open the **Spectrum Settings**. In the **Spectrogram options** section, in
the **Time res (s)** box, enter a number.

`TimeSpanSource`

— Source of time span value`"Auto"`

(default) | `"Property"`

Specify the source for the time span of the spectrogram as either
`"Auto"`

or `"Property"`

. 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.

**Tunable: **Yes

To enable this property, set ViewType to
`"Spectrogram"`

or ```
"Spectrum and
spectrogram"
```

.

Open the **Spectrum Settings**. In the **Spectrogram options** section, set
**Time span (s)**.

**Data Types: **`char`

| `string`

`TimeSpan`

— Time span`0.1`

(default) | positive scalarSpecify the time span of the spectrogram display in seconds. 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.

**Tunable: **Yes

To enable this property, set:

ViewType to

`"Spectrogram"`

or`"Spectrum and spectrogram"`

.TimeSpanSource to

`"Property"`

.

Open the **Spectrum Settings**. In the **Spectrogram options** section, in
the **Time span (s)** box, enter a number.

`MeasurementChannel`

— Channel for which measurements are obtained`1`

(default) | positive integerChannel for which the measurements are obtained, specified as a real, positive integer greater than 0 and less than or equal to 100. The maximum number you can specify is the number of channels (columns) in the input signal.

**Tunable: **Yes

Click on **Tools** > **Measurements** and
open the **Trace Selection** settings.

**Data Types: **`double`

`SpectralMask`

— Spectral mask lines`SpectralMaskSpecification`

objectSpecify whether to display upper and lower spectral mask lines on a spectrum plot.
This property uses properties from a `SpectralMaskSpecification`

object to enable and configure the spectral
masks.

**Tunable: **Yes

Open the **Spectral Mask** pane and modify the
**Settings** options.

`PeakFinder`

— Peak finder measurement`PeakFinderSpecification`

objectEnable peak finder to compute and display the largest calculated peak values. The `PeakFinder`

property uses the `PeakFinderSpecification`

properties.

The `PeakFinderSpecification`

properties are:

`MinHeight`

–– Level above which peaks are detected, specified as a scalar value.Default:

`-Inf`

`NumPeaks`

–– Maximum number of peaks to show, specified as a positive integer scalar less than 100.Default:

`3`

`MinDistance`

–– Minimum number of samples between adjacent peaks, specified as a positive real scalar.Default:

`1`

`Threshold`

–– Minimum height difference between peak and its neighboring samples, specified as a nonnegative real scalar.Default:

`0`

`LabelFormat`

–– Coordinates to display next to the calculated peak value, specified as a character vector or a string scalar. Valid values are`"X"`

,`"Y"`

, or`"X + Y"`

.Default:

`"X + Y"`

`Enable`

–– Set this property to`true`

to enable peak finder measurements. Valid values are`true`

or`false`

.Default:

`false`

All `PeakFinderSpecification`

properties are tunable.

**Tunable: **Yes

Open the **Peak Finder** pane () and modify the **Settings**
options.

`CursorMeasurements`

— Cursor measurements`CursorMeasurementsSpecification`

objectEnable cursor measurements to display screen or waveform cursors. The `CursorMeasurements`

property uses the `CursorMeasurementsSpecification`

properties.

The `CursorMeasurementsSpecification`

properties are:

`Type`

–– Type of the display cursors, specified as either`"Screen cursors"`

or`"Waveform cursors"`

.Default:

`"Waveform cursors"`

`ShowHorizontal`

–– Set this property to`true`

to show the horizontal screen cursors. This property applies when you set the`Type`

property to`"Screen cursors"`

.Default:

`true`

`ShowVertical`

–– Set this property to`true`

to show the vertical screen cursors. This property applies when you set the`Type`

property to`"Screen cursors"`

.Default:

`true`

`Cursor1TraceSource`

–– Specify the waveform cursor 1 source as a positive real scalar. This property applies when you set the`Type`

property to`"Waveform cursors"`

.Default:

`1`

`Cursor2TraceSource`

–– Specify the waveform cursor 2 source as a positive real scalar. This property applies when you set the`Type`

property to`"Waveform cursors"`

.Default:

`1`

`LockSpacing`

–– Lock spacing between cursors, specified as a logical scalar.Default:

`false`

`SnapToData`

–– Snap cursors to data, specified as a logical scalar.Default:

`true`

`XLocation`

––*x*-coordinates of the cursors, specified as a real vector of length equal to 2.Default:

`[-2500 2500]`

`YLocation`

––*y*-coordinates of the cursors, specified as a real vector of length equal to 2. This property applies when you set the`Type`

property to`"Screen cursors"`

.Default:

`[-55 5]`

`Enable`

–– Set this property to`true`

to enable cursor measurements. Valid values are`true`

or`false`

.Default:

`false`

All `CursorMeasurementsSpecification`

properties are tunable.

Open the **Cursor Measurements** pane () and modify the **Settings**
options.

`ChannelMeasurements`

— Channel measurements`ChannelMeasurementsSpecification`

objectEnable channel measurements to compute and display the occupied bandwidth or adjacent channel power ratio. The `ChannelMeasurements`

property uses the `ChannelMeasurementsSpecification`

properties.

The `ChannelMeasurementsSpecification`

properties are:

`Algorithm`

–– Type of measurement data to display, specified as either`"Occupied BW"`

or`"ACPR"`

.Default:

`"Occupied BW"`

`FrequencySpan`

–– Frequency span mode, specified as either`"Span and center frequency"`

or`"Start and stop frequencies"`

Default:

`"Span and center frequency"`

`Span`

–– Frequency span over which the channel measurements are computed, specified as a real, positive scalar in Hz. This property applies when you set the`FrequencySpan`

property to`"Span and center frequency"`

.Default:

`2000`

Hz`CenterFrequency`

–– Center frequency of the span over which the channel measurements are computed, specified as a real scalar in Hz. This property applies when you set the`FrequencySpan`

property to`"Span and center frequency"`

.Default:

`0`

Hz`StartFrequency`

–– Start frequency over which the channel measurements are computed, specified as a real scalar in Hz. This property applies when you set the`FrequencySpan`

property to`"Start and stop frequencies"`

.Default:

`-1000`

Hz`StopFrequency`

–– Stop frequency over which the channel measurements are computed, specified as a real scalar in Hz. This property applies when you set the`FrequencySpan`

property to`"Start and stop frequencies"`

.Default:

`1000`

Hz`PercentOccupiedBW`

–– Percent of power over which to compute the occupied bandwidth, specified as a positive real scalar. This property applies when you set the`Algorithm`

property to`"Occupied BW"`

.Default:

`99`

`NumOffsets`

–– Number of adjacent channel pairs, specified as a real, positive integer. This property applies when you set the`Algorithm`

property to`"ACPR"`

.Default:

`2`

`AdjacentBW`

–– Adjacent channel bandwidth, specified as a real, positive scalar. This property applies when you set the`Algorithm`

property to`"ACPR"`

.Default:

`1000`

`FilterShape`

–– Filter shape for both main and adjacent channels, specified as`"None"`

,`"Gaussian"`

, or`"RRC"`

. This property applies when you set the`Algorithm`

property to`"ACPR"`

.Default:

`"None"`

`FilterCoeff`

–– Channel filter coefficient, specified as a real scalar between`0`

and`1`

. This property applies when you set the`Algorithm`

property to`"ACPR"`

and the`FilterShape`

property to either`"Gaussian"`

or`"RRC"`

.Default:

`0.5`

`ACPROffsets`

–– Frequency of the adjacent channel relative to the center frequency of the main channel, specified as a real vector of length equal to the number of offset pairs specified in`NumOffsets`

. This property applies when you set the`Algorithm`

property to`"ACPR"`

.Default:

`[2000 3500]`

`Enable`

–– Set this property to`true`

to enable channel measurements. Valid values are`true`

or`false`

.Default:

`false`

All `ChannelMeasurementsSpecification`

properties are tunable.

Open the **Channel Measurements** pane () and modify the **Measurement**
and **Channel Settings** options.

`DistortionMeasurements`

— Distortion measurements`DistortionMeasurementsSpecification`

objectEnable distortion measurements to compute and display the harmonic distortion and intermodulation distortion. The `DistortionMeasurements`

property uses the `DistortionMeasurementsSpecification`

properties.

The `DistortionMeasurementsSpecification`

properties are:

`Algorithm`

–– Type of measurement data to display, specified as either`"Harmonic"`

or`"Intermodulation"`

.Default:

`"Harmonic"`

`NumHarmonics`

–– Number of harmonics to measure, specified as a real, positive integer. This property applies when you set the`Algorithm`

to`"Harmonic"`

.Default:

`6`

`Enable`

–– Set this property to`true`

to enable distortion measurements.Default:

`false`

All `DistortionMeasurementsSpecification`

properties are tunable.

Open the **Distortion Measurements** pane () and modify the **Distortion**
and **Harmonics** options.

`CCDFMeasurements`

— CCDF measurements`CCDFMeasurementsSpecification`

object Enable CCDF measurements to display the probability of the input signal's instantaneous power
being a certain amount of dB above the signal's average power. The
`CCDFMeasurements`

property uses the
`CCDFMeasurementsSpecification`

properties.

The `CCDFMeasurementsSpecification`

properties are:

`PlotGaussianReference`

–– Set this property to`true`

to plot a reference CCDF curve. The reference CCDF curve represents the power of a complex white Gaussian noise, calculated as a chi-squared distribution.Default:

`false`

`Enable`

–– Set this property to`true`

to enable CCDF measurements. Valid values are`true`

or`false`

.Default:

`false`

All `CCDFMeasurementsSpecification`

properties are tunable.

Open the **CCDF Measurements** pane () and enable the **Plot Gaussian
reference** option.

`Name`

— Window name`"Spectrum Analyzer"`

(default) | character vector | string scalarTitle of the scope window.

**Tunable: **Yes

**Data Types: **`char`

| `string`

`Position`

— Window positionscreen center (default) |

`[left bottom width height]`

Spectrum Analyzer window position in pixels, specified by the size and location of the scope window as a four-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.

By default, the window appears in the center of your screen with a width of `800`

pixels and height
of `450`

pixels. The exact center coordinates depend on your screen resolution.

**Tunable: **Yes

`PlotType`

— Plot type for normal traces`"Line"`

(default) | `"Stem"`

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.

**Tunable: **Yes

To enable this property, set:

ViewType to

`"Spectrum"`

or`"Spectrum and spectrogram"`

PlotNormalTrace to

`true`

Open the **Style** properties and set **Plot type**.

**Data Types: **`char`

| `string`

`PlotNormalTrace`

— Normal trace flag`true`

(default) | `false`

Set this property to `false`

to remove the display of the normal traces. These traces display the
free-running spectral estimates. Even when the traces are removed from the display, the Spectrum Analyzer continues
its spectral computations.

**Tunable: **Yes

To enable this property, set ViewType to
`"Spectrum"`

or `"Spectrum and spectrogram"`

.

Open the **Spectrum Settings**. In the **Trace options** section, select **Normal trace**.

**Data Types: **`logical`

`PlotMaxHoldTrace`

— Max-hold trace flag`false`

(default) | `true`

To compute and plot the maximum-hold spectrum of each input channel, set this property to `true`

.
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.

**Tunable: **Yes

To enable this property, set ViewType to
`"Spectrum"`

or `"Spectrum and spectrogram"`

.

Open the **Spectrum Settings**. In the **Trace options** section, select **Max-hold trace**.

**Data Types: **`logical`

`PlotMinHoldTrace`

— Min-hold trace flag`false`

(default) | `true`

To compute and plot the minimum-hold spectrum of each input channel, set this property to `true`

.
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.

**Tunable: **Yes

To enable this property, set ViewType to
`"Spectrum"`

or `"Spectrum and spectrogram"`

.

Open the **Spectrum Settings**. In the **Trace options** section, select **Min-hold trace**.

**Data Types: **`logical`

`ReducePlotRate`

— Improve performance with reduced plot rate`true`

(default) | `false`

The simulation speed is faster when this property is set to `true`

.

`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.`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.

**Tunable: **Yes

Select **Playback** > **Reduce plot rate to improve performance**.

`Title`

— Display title`''`

(default) | character vector | string scalarSpecify the display title as a character vector or string.

**Tunable: **Yes

Open the **Configuration Properties**. Set **Title**.

**Data Types: **`char`

| `string`

`YLabel`

— Y-axis label`''`

(default) | character vector | string scalarSpecify the text for the scope to display to the left of the *y*-axis.

Regardless of this property, Spectrum Analyzer always displays power units as one of the
`SpectrumUnits`

values.

**Tunable: **Yes

To enable this property, set ViewType to `"Spectrum"`

or
`"Spectrum and spectrogram"`

.

Open the **Configuration Properties**. Set **Y-label**.

**Data Types: **`char`

| `string`

`ShowLegend`

— Show legend`false`

(default) | `true`

To show a legend with the input names, set this property to `true`

.

From the legend, you can control which signals are visible. This control is equivalent to changing the visibility in
the **Style** dialog box. In the scope legend, click a signal name to hide the signal in the scope.
To show the signal, click the signal name again. To show only one signal, right-click the signal name. To show all
signals, press **Esc**.

**Note**

The legend only shows the first 20 signals. Any additional signals cannot be viewed or controlled from the legend.

**Tunable: **Yes

Open the **Configuration Properties**. On the **Display** tab, select **Show
legend**.

**Data Types: **`logical`

`ChannelNames`

— Channel namesempty cell (default) | cell array of character vectors

Specify the input channel names as a cell array of character vectors. The names appear in the legend,
**Style** dialog box, and **Measurements** panels. If you do not specify names, the
channels are labeled as `Channel 1`

, `Channel 2`

, etc.

**Tunable: **Yes

To see channel names, set `ShowLegend`

to `true`

.

On the legend, double-click the channel name.

**Data Types: **`char`

`ShowGrid`

— Grid visibility`true`

(default) | `false`

Set this property to `true`

to show gridlines on the plot.

**Tunable: **Yes

Open the **Configuration Properties**. On the **Display** tab, set
**Show grid**.

**Data Types: **`logical`

`YLimits`

— Y-axis limits`[-80, 20]`

(default) | `[ymin ymax]`

Specify the *y*-axis limits as a two-element numeric vector, `[ymin ymax]`

.

**Example: **`scope.YLimits = [-10,20]`

**Tunable: **Yes

To enable this property, set the ViewType property to

`"Spectrum"`

or`"Spectrum and spectrogram"`

.The units directly depend upon the SpectrumUnits property.

Open the **Configuration Properties**. Set **Y-limits (maximum)** and **Y-limits
(minimum)**.

`ColorLimits`

— Scale spectrogram color limits`[-80, 20]`

(default) | `[colorMin colorMax]`

Control the color limits of the spectrogram using a two-element numeric vector, ```
[colorMin
colorMax]
```

.

**Example: **`scope.ColorLimits = [-10,20]`

To enable this property, set the ViewType property to

`"Spectrogram"`

or`"Spectrum and spectrogram"`

.The units directly depend upon the

`SpectrumUnits`

property.

Open the **Configuration Properties**. Set **Color-limits (minimum)** and **Color-limits
(maximum)**.

`AxesScaling`

— Axes scaling mode`"Auto"`

(default) | `"Manual"`

| `"OnceAtStop"`

| `"Updates"`

Specify when the scope automatically scales the axes. Valid values are:

`"Auto"`

— The scope scales the axes as-needed to fit the data, both during and after simulation.`"Manual"`

— The scope does not scale the axes automatically.`"OnceAtStop"`

— The scope scales the axes when the simulation stops.`"Updates"`

— The scope scales the axes once after 10 updates.

Select **Tools** > **Axes Scaling**.

**Data Types: **`char`

| `string`

`AxesLayout`

— Orientation of the spectrum and spectrogram`"Vertical"`

(default) | `"Horizontal"`

Specify the layout type as `"Horizontal"`

or `"Vertical"`

. A vertical layout
stacks the spectrum above the spectrogram. A horizontal layout puts the two views side-by-side.

**Tunable: **Yes

To enable this property, set ViewType to ```
"Spectrum and
spectrogram"
```

.

Open the **Spectrum Settings**. Set **Axes layout**.

**Data Types: **`char`

| `string`

`scope(`

updates the spectrum of the signal in the spectrum
analyzer.`signal`

)

`scope(signal1,signal2,...,signalN)`

displays multiple signals in the spectrum analyzer. The
signals must have the same frame length, but can vary in number of channels. You must set the
`NumInputPorts`

property to enable multiple input signals.

`signal`

— Input signal or signals to visualizescalar | vector | matrix

Specify one or more input signals to visualize in the `dsp.SpectrumAnalyzer`

. Signals can have a
different number of channels, but must have the same frame length.

**Example: **`scope(signal1, signal2)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

| `fi`

To use an object function, specify the
System object as the first input argument. For
example, to release system resources of a System object named `obj`

, use
this syntax:

release(obj)

`generateScript` | Generate MATLAB script to create scope with current settings |

`getMeasurementsData` | Get the current measurement data displayed on the spectrum analyzer |

`getSpectralMaskStatus` | Get test results of current spectral mask |

`getSpectrumData` | Save spectrum data shown in spectrum analyzer |

`isNewDataReady` | Check spectrum analyzer for new data |

If you want to restart the simulation from the beginning, call `reset`

to
clear the scope window displays. Do not call `reset`

after calling
`release`

.

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

Fs = 100e6; % Sampling frequency fSz = 5000; % Frame size sin1 = dsp.SineWave(1e0, 5e6,0,'SamplesPerFrame',fSz,'SampleRate',Fs); sin2 = dsp.SineWave(1e-1,15e6,0,'SamplesPerFrame',fSz,'SampleRate',Fs); sin3 = dsp.SineWave(1e-2,25e6,0,'SamplesPerFrame',fSz,'SampleRate',Fs); sin4 = dsp.SineWave(1e-3,35e6,0,'SamplesPerFrame',fSz,'SampleRate',Fs); sin5 = dsp.SineWave(1e-4,45e6,0,'SamplesPerFrame',fSz,'SampleRate',Fs); scope = dsp.SpectrumAnalyzer; scope.SampleRate = Fs; scope.SpectralAverages = 1; scope.PlotAsTwoSidedSpectrum = false; scope.RBWSource = 'Auto'; scope.PowerUnits = 'dBW'; for idx = 1:1e2 y1 = sin1(); y2 = sin2(); y3 = sin3(); y4 = sin4(); y5 = sin5(); scope(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(scope)

Run the `clear`

function to close the Spectrum Analyzer window.

`clear('scope');`

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

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

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

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

Run the `release`

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

release(scope);

Run the MATLAB `clear`

function to close the Spectrum Analyzer window.

`clear('scope');`

Use the Spectrum Analyzer to display frequency input from spectral estimates of sinusoids embedded in white Gaussian noise.

**Initialization**

Initialize two `dsp.SpectrumEstimator`

objects to display. Set one object to use the Welch-based spectral estimation technique with a Hann window, set the other object use a filter bank estimation. Specify a noisy sine wave input signal with four sinusoids at 0.16, 0.2, 0.205, and 0.25 cycles/sample. View the spectral estimate using a third object, a spectrum analyzer, set to process frequency input.

FrameSize = 420; Fs = 1; Frequency = [0.16 0.2 0.205 0.25]; sinegen = dsp.SineWave('SampleRate',Fs,'SamplesPerFrame',FrameSize,... 'Frequency',Frequency,'Amplitude',[2e-5 1 0.05 0.5]); NoiseVar = 1e-10; numAvgs = 8; hannEstimator = dsp.SpectrumEstimator('PowerUnits','dBm',... 'Window','Hann','FrequencyRange','onesided',... 'SpectralAverages',numAvgs,'SampleRate',Fs); filterBankEstimator = dsp.SpectrumEstimator('PowerUnits','dBm',... 'Method','Filter bank','FrequencyRange','onesided',... 'SpectralAverages',numAvgs,'SampleRate',Fs); spectrumPlotter = dsp.SpectrumAnalyzer('InputDomain','Frequency',... 'SampleRate',Fs,... 'SpectrumUnits','dBm','YLimits',[-120,40],... 'PlotAsTwoSidedSpectrum',false,... 'ChannelNames',{'Hann window','Filter bank'},'ShowLegend',true);

**Streaming**

Stream the input. Compare the spectral estimates in the spectrum analyzer.

for i = 1:1000 x = sum(sinegen(),2) + sqrt(NoiseVar)*randn(FrameSize,1); Pse_hann = hannEstimator(x); Pfb = filterBankEstimator(x); spectrumPlotter([Pse_hann,Pfb]) end

`dsp.SpectrumAnalyzer`

System objectCompute and display the power spectrum of a noisy sinusoidal input signal using the `dsp.SpectrumAnalyzer`

System object™. Measure the peaks, cursor placements, adjacent channel power ratio, distortion, and CCDF values in the spectrum by enabling the following properties:

`PeakFinder`

`CursorMeasurements`

`ChannelMeasurements`

`DistortionMeasurements`

`CCDFMeasurements`

**Initialization**

The input sine wave has two frequencies: 1000 Hz and 5000 Hz. Create two `dsp.SineWave`

System objects to generate these two frequencies. Create a `dsp.SpectrumAnalyzer`

System object to compute and display the power spectrum.

Fs = 44100; Sineobject1 = dsp.SineWave('SamplesPerFrame',1024,'PhaseOffset',10,... 'SampleRate',Fs,'Frequency',1000); Sineobject2 = dsp.SineWave('SamplesPerFrame',1024,... 'SampleRate',Fs,'Frequency',5000); SA = dsp.SpectrumAnalyzer('SampleRate',Fs,'Method','Filter bank',... 'SpectrumType','Power','PlotAsTwoSidedSpectrum',false,... 'ChannelNames',{'Power spectrum of the input'},'YLimits',[-120 40],'ShowLegend',true);

**Enable Measurements Data**

To obtain the measurements, set the `Enable`

property of the measurements to `true`

.

SA.CursorMeasurements.Enable = true; SA.ChannelMeasurements.Enable = true; SA.PeakFinder.Enable = true; SA.DistortionMeasurements.Enable = true;

**Use getMeasurementsData**

Stream in the noisy sine wave input signal and estimate the power spectrum of the signal using the spectrum analyzer. Measure the characteristics of the spectrum. Use the `getMeasurementsData`

function to obtain these measurements programmatically. The `isNewDataReady`

function indicates when there is new spectrum data. The measured data is stored in the variable `data`

.

data = []; for Iter = 1:1000 Sinewave1 = Sineobject1(); Sinewave2 = Sineobject2(); Input = Sinewave1 + Sinewave2; NoisyInput = Input + 0.001*randn(1024,1); SA(NoisyInput); if SA.isNewDataReady data = [data;getMeasurementsData(SA)]; end end

The right side of the spectrum analyzer shows the enabled measurement panes. The values shown in these panes match with the values shown in the last time step of the `data`

variable. You can access the individual fields of `data`

to obtain the various measurements programmatically.

**Compare Peak Values**

Peak values are obtained by the `PeakFinder`

property. Verify that the peak values obtained in the last time step of `data`

match the values shown on the spectrum analyzer plot.

peakvalues = data.PeakFinder(end).Value

`peakvalues = `*3×1*
26.9850
24.1735
-52.3506

frequencieskHz = data.PeakFinder(end).Frequency/1000

`frequencieskHz = `*3×1*
4.9957
0.9905
7.8166

To close the scope window and clear its associated data, use the MATLAB

^{®}`clear`

function.To hide or show the scope window, use the

`hide`

and`show`

functions.Use the MATLAB

`mcc`

function to compile code containing a Spectrum Analyzer.You cannot open Spectrum Analyzer configuration dialog boxes if you have more than one compiled component in your application.

When you choose the `Welch`

method, the power spectrum
estimate is averaged modified periodograms.

Given the signal input, `x`

, the Spectrum Analyzer does the
following:

Multiplies

`x`

by the given window and scales the result by the window power. The Spectrum Analyzer uses the`RBW`

or the`Window Length`

setting in the**Spectrum Settings**pane to determine the data window length.Computes the FFT of the signal,

`Y`

, and takes the square magnitude using`Z = Y.*conj(Y)`

.Computes the current power spectrum estimate by taking the moving average of the last

*N*number of*Z*'s, and scales the answer by the sample rate. For details on the moving average methods, see Averaging Method.

Spectrum Analyzer requires that a minimum number of samples to compute 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 2.

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

The normalized effective noise bandwidth, *NENBW*, is a factor that
depends on the windowing method. Spectrum Analyzer shows the value of
*NENBW* in the **Window Options** pane of the
**Spectrum Settings** pane. Overlap percentage,
*O _{p}*, is the value of the

When in

**RBW (Hz)**mode, the window length required to compute one spectral update,*N*, is directly related to the resolution bandwidth and normalized effective noise bandwidth:_{window}$${N}_{window}=\frac{NENBW\times {F}_{s}}{RBW}$$

When in

**Window Length**mode, the window length is used as specified.The number of input samples required to compute one spectral update,

*N*, is directly related to the window length and the amount of overlap by the following equation._{samples}$${N}_{samples}=\left(1-\frac{{O}_{p}}{100}\right){N}_{window}$$

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.

*O*_{p}*N*_{samples}0% 100 50% 50 80% 20 The normalized effective noise bandwidth,

*NENBW*, is a window parameter determined by the window length,*N*, and the type of window used. If_{window}*w*(*n*) denotes the vector of*N*window coefficients, then_{window}*NENBW*is given by the following equation.$$NENBW={N}_{window}\times \frac{{\displaystyle \sum _{n=1}^{{N}_{window}}{w}^{2}(n)}}{{\left[{\displaystyle \sum _{n=1}^{{N}_{window}}w(n)}\right]}^{2}}$$

When in

**RBW (Hz)**mode, you can set the resolution bandwidth using the value of the**RBW (Hz)**parameter on the**Main options**pane of the**Spectrum Settings**pane. 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:$$\frac{span}{RBW}>2$$

By default, the

**RBW (Hz)**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. When you set**RBW (Hz)**to`Auto`

,*RBW*is calculated as:$$RB{W}_{auto}=\frac{span}{1024}$$

When in

**Window Length**mode, you specify*N*and the resulting_{window}*RBW*is:$$\frac{NENBW\times {F}_{s}}{{N}_{window}}$$

Sometimes, the number of input samples provided are not sufficient to achieve the resolution bandwidth that you specify. When this situation occurs, Spectrum Analyzer displays a message:

Spectrum Analyzer removes this message and displays a spectral estimate when enough data has been input.

**Note**

The number of FFT points (*N _{fft}*) is
independent of the window length
(

When you choose the `Filter Bank`

method, the Spectrum
Analyzer uses an analysis filter bank to estimate the power spectrum.

The filter bank splits the broadband input signal, *x(n)*, of sample
rate *fs*, into multiple narrow band signals,
*y _{0}(m)*,

The variable *M* represents the number of frequency bands in the
filter bank. When the frequency resolution method is set to
`NumFrequencyBands`

, *M* is equal to the
value you specify for the number of frequency bands. When the frequency resolution
method is set to `RBW`

, *M* is equal to the
number of data points that are needed to achieve the specified RBW value or 1024,
whichever is larger. The number of taps per frequency band specifies the number of
filter coefficients for each frequency band of the filter bank. The total number of
filter coefficients is equal to number of taps per band times the number of frequency
bands, *M*. For more information on the analysis filter bank and how it
is implemented, see the More About and the Algorithm sections in
`dsp.Channelizer`

.

After the broadband input signal is split into multiple narrow bands, the Spectrum
Analyzer computes the power in each narrow band using the following equation. Each
*Z _{i}* value becomes the estimate of the
power over that narrow frequency band.

$${Z}_{i}=\frac{1}{L}{\displaystyle \sum _{m=0}^{L-1}{\left|{y}_{i}[m]\right|}^{2}}$$

*L* is length of the narrow band signal,
*y _{i}(m)*, and

The power values in all the narrow bands (denoted by the
*Z _{i}*) form the

$$Z=[{Z}_{0},\text{\hspace{0.17em}}{Z}_{1},\text{\hspace{0.17em}}{Z}_{2},\cdots ,{Z}_{M-1}]$$

The current *Z* vector is averaged with the previous
*Z* vectors using one of the two moving average methods: Running or
Exponential weighting. The output of the averaging operation forms the spectral estimate
vector. For details on the two averaging methods, see Averaging Method.

The Spectrum Analyzer uses the **RBW (Hz)** or the **Number
of frequency band** property in the **Spectrum Settings**
pane to determine the input frame length.

Spectrum Analyzer requires a minimum number of samples to compute 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.

$${N}_{samples}=\frac{{F}_{s}}{RBW}$$

*F _{s}* is the sample rate of the input signal.
Spectrum Analyzer shows sample rate in the

When in

**RBW (Hz)**mode, you can set the resolution bandwidth using the value of the**RBW (Hz)**parameter on the**Main options**pane of the**Spectrum Settings**pane. 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:$$\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}$$When in

**Number of frequency bands**mode, you specify the input frame size. When the number of frequency bands is`Auto`

, the resulting RBW is:$$RBW=\frac{{F}_{s}}{\text{InputFrameSize}}$$

When the number of frequency bands is manually specified, the resulting RBW is:

$$RBW=\frac{{F}_{s}}{FFTLength}$$

Sometimes, the number of input samples provided are not sufficient to achieve the resolution bandwidth that you specify. When this situation occurs, Spectrum Analyzer displays a message:

Spectrum Analyzer removes this message and displays a spectral estimate when enough data has been input.

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.

Spectrum Analyzer calculates and plots the power spectrum, power spectrum density, and RMS computed by the modified
*Periodogram* estimator. For more information about the Periodogram method, see `periodogram`

.

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

$$\mathrm{PSD}\left(f\right)=\frac{1}{P}{\displaystyle \sum _{p=1}^{P}\frac{{\left|{\displaystyle \sum _{n=1}^{{N}_{FFT}}{x}^{p}\left[n\right]{e}^{-j2\pi f(n-1)T}}\right|}^{2}}{{F}_{s}\times {\displaystyle \sum _{n=1}^{{N}_{window}}{w}^{2}\left[n\right]}}}$$

In this equation, *x*[*n*] is the discrete input signal. On every input signal
frame, Spectrum Analyzer generates as many overlapping windows as possible, with each window denoted as
*x ^{(p)}*[

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

$${P}_{spectrum}\left(f\right)=\mathrm{PSD}\left(f\right)\times RBW=\mathrm{PSD}\left(f\right)\times \frac{{F}_{s}\times NENBW}{{N}_{window}}=\frac{1}{P}{\displaystyle \sum _{p=1}^{P}\frac{{\left|{\displaystyle \sum _{n=1}^{{N}_{FFT}}{x}^{p}\left[n\right]{e}^{-j2\pi f(n-1)T}}\right|}^{2}}{{\left[{\displaystyle \sum _{n=1}^{{N}_{window}}w\left[n\right]}\right]}^{2}}}$$

*Spectrogram* — You can plot any power as a 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. You then use
interpolation to calculate noninteger values of 1/*RBW*. In the spectrogram display, time scrolls
from top to bottom, so the most recent data is shown at the top of the display. The offset shows the time value at
which the center of the most current spectrogram line occurred.

When set to `Auto`

, the frequency vector for frequency-domain input is calculated by the
software.

When the PlotAsTwoSidedSpectrum property is set to true, the frequency vector is:

$$\left[-\frac{SampleRate}{2},\frac{SampleRate}{2}\right]$$

When the PlotAsTwoSidedSpectrum property is set to false, the frequency vector is:

$$\left[0,\frac{SampleRate}{2}\right]$$

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 result is

$$\frac{100-OccupiedBW\%}{2}$$

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 the result reaches

$$\frac{100-OccupiedBW\%}{2}$$

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.

Spectral content is estimated by finding peaks in the spectrum. When the algorithm detects a peak, it records the width of the peak and clears all monotonically decreasing values. That is, the algorithm treats all 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 (

*W*) is recorded._{0}The fundamental power (

*P*) is determined from the remaining maximum value of the displayed spectrum. A local estimate (_{1}*Fe*) of the fundamental frequency is made by computing the central moment of the power near the peak. The bandwidth of the fundamental power content (_{1}*W*) is recorded. Then, the power from the fundamental is removed as in step 1._{1}The power and width of the higher-order harmonics (

*P*,_{2}*W*,_{2}*P*,_{3}*W*, etc.) are determined in succession by examining the frequencies closest to the appropriate multiple of the local estimate (_{3}*Fe*). Any spectral content that decreases monotonically about the harmonic frequency is removed from the spectrum first before proceeding to the next harmonic._{1}Once the DC, fundamental, and harmonic content is removed from the spectrum, the power of the remaining spectrum is examined for its sum (

*P*), peak value (_{remaining}*P*), and median value (_{maxspur}*P*)._{estnoise}The sum of all the removed bandwidth is computed as

*W*=_{sum}*W*+_{0}*W*+_{1}*W*+...+_{2}*W*._{n}The sum of powers of the second and higher-order harmonics are computed as

*P*=_{harmonic}*P*+_{2}*P*+_{3}*P*+...+_{4}*P*._{n}The sum of the noise power is estimated as:

$${P}_{noise}=({P}_{remaining}\cdot dF+{P}_{est.noise}\cdot {W}_{sum})/RBW$$

Where

*dF*is the absolute difference between frequency bins, and*RBW*is the resolution bandwidth of the window.The metrics for SNR, THD, SINAD, and SFDR are then computed from the estimates.

$$\begin{array}{l}THD=10\cdot {\mathrm{log}}_{10}\left(\frac{{P}_{harmonic}}{{P}_{1}}\right)\\ SINAD=10\cdot {\mathrm{log}}_{10}\left(\frac{{P}_{1}}{{P}_{harmonic}+{P}_{noise}}\right)\\ SNR=10\cdot {\mathrm{log}}_{10}\left(\frac{{P}_{1}}{{P}_{noise}}\right)\\ SFDR=10\cdot {\mathrm{log}}_{10}\left(\frac{{P}_{1}}{\mathrm{max}\left({P}_{maxspur},\mathrm{max}\left({P}_{2},{P}_{3},\mathrm{...},{P}_{n}\right)\right)}\right)\end{array}$$

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**. If your application can tolerate the increased equivalent noise bandwidth (ENBW), consider using a Kaiser window with a high attenuation (up to 330 dB) to minimize spectral leakage.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.

*N*^{th}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 1 milliwatt (dBm):*TOI*=_{lower}*P*+ (_{F1}*P*-_{F2}*P*)/2_{(2F1-F2)}*TOI*=_{upper}*P*+ (_{F2}*P*-_{F1}*P*)/2_{(2F2-F1)}*TOI*= + (*TOI*+_{lower}*TOI*)/2_{upper}

The moving average is calculated using one of the two methods:

`Running`

— For each frame of input, average the last*N*-scaled*Z*vectors, which are computed by the algorithm. The variable*N*is the value you specify for the number of spectral averages. If the algorithm does not have enough*Z*vectors, the algorithm uses zeros to fill the empty elements.`Exponential`

— The moving average algorithm using the exponential weighting method updates the weights and computes the moving average recursively for each*Z*vector that comes in by using the following recursive equations:$$\begin{array}{l}{w}_{N}=\lambda {w}_{N-1}+1\\ {\overline{z}}_{N}=\left(1-\frac{1}{{w}_{N}}\right){\overline{z}}_{N-1}+\left(\frac{1}{{w}_{N}}\right){z}_{N}\end{array}$$

λ — Forgetting factor

$${w}_{N}$$ — Weighting factor applied to the current

*Z*vector$${z}_{N}$$ — Current

*Z*vector$${\overline{z}}_{N-1}$$ — Moving average until the previous

*Z*vector$$\left(1-\frac{1}{{w}_{N}}\right){\overline{z}}_{N-1}$$ — Effect of the previous

*Z*vectors on the average$${\overline{z}}_{N}$$ — Moving average including the current

*Z*vector

Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

Supports MEX code generation by treating the calls to the object as extrinsic. Does not support code generation for standalone applications.

See System Objects in MATLAB Code Generation (MATLAB Coder).

Si dispone di una versione modificata di questo esempio. Desideri aprire questo esempio con le tue modifiche?

Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:

Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web siteYou can also select a web site from the following list:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

- América Latina (Español)
- Canada (English)
- United States (English)

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)