# Spectrum Analyzer

Display frequency spectrum

**Library:**Simscape / Utilities

## Description

**Note**

The Spectrum Analyzer block in the Simscape™ product contains a subset of functionality of the DSP System Toolbox™ block with the same name. This page describes the block configuration and functionality available with a
Simscape license. If you also have a DSP System Toolbox license, then the Spectrum Analyzer block in the **Simscape** > **Utilities** library is identical to the block in the **DSP System Toolbox** > **Sinks** library. For more information, see Spectrum Analyzer (DSP System Toolbox) in the DSP System Toolbox documentation.

The Spectrum Analyzer block accepts input signals with discrete sample times and displays frequency spectra of these signals.

To use a Spectrum Analyzer block, instead of a regular scope, in a Simscape model:

Add a Spectrum Analyzer block to your block diagram.

If your model uses a variable-step solver, also add a Rate Transition block and connect it to the input of the Spectrum Analyzer, setting the

**Output port sample time**to the sample time you wish the Spectrum Analyzer to use.If your model uses a local solver, then it produces output physical signals with discrete sample times and you do not need to add a Rate Transition block. However, if you need to down-sample from the solver fixed step size, you can also use a Rate Transition block. For more information on using local solvers, see Making Optimal Solver Choices for Physical Simulation.

Use a PS-Simulink Converter block to connect the output physical signal of interest to the input of the Spectrum Analyzer block (or to the input of the Rate Transition block, if using one). For more information, see Connecting Simscape Diagrams to Simulink Sources and Scopes. You can also use additional signal processing blocks between the PS-Simulink Converter and the Spectrum Analyzer to enhance signal quality.

Run the simulation. The Spectrum Analyzer, referred to here as the scope, opens and displays the frequency spectrum of the signal.

**Note**

To prevent the scope from opening when you run your model, right-click the scope icon and select ```
Comment
Out
```

. If the scope is already open, and you comment it out in the model, the scope displays, "No data can be
shown because this scope is commented out." Select `Uncomment`

to turn the scope back on.

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

## Limitations

This reference page describes the Spectrum Analyzer block available with Simscape or RF Blockset™. If you have DSP System Toolbox, more parameters and measurements are available. For information about the full Spectrum Analyzer, see Spectrum Analyzer (DSP System Toolbox).

## Ports

### Input

`Port_1`

— Signals to visualize

scalar | vector | matrix | array

Connect the signals you want to visualize. You can have up to 96 input ports. Input signals can have these characteristics:

**Signal Domain**— Frequency or time signals**Type**— Discrete (sample-based and frame-based).**Data type**— Any data type that Simulink^{®}supports. See Data Types Supported by Simulink.**Dimension**— One dimensional (vector), two dimensional (matrix), or multidimensional (array). Input must have fixed number of channels. See Signal Dimensions and Determine Signal Dimensions.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

| `fixed point`

**Complex Number Support: **Yes

## Parameters

This section lists the parameters available in the Spectrum Analyzer when you do not have DSP System Toolbox. For the full parameter list, see Spectrum Analyzer (DSP System Toolbox).

### Spectrum Settings

The **Spectrum Settings** pane appears at the right side of the
Spectrum Analyzer window. This pane controls how the spectrum is calculated. To show the
Spectrum Settings, in the Spectrum Analyzer menu, select **View** > **Spectrum Settings** or use the button in the toolbar.

**Main**

`Type`

— Type of spectrum to display

`Power`

(default) | `Power density`

| `RMS`

`Power`

— Spectrum Analyzer shows the power spectrum.

`Power density`

— Spectrum Analyzer shows the power spectral density.
The power spectral density is the magnitude of the spectrum normalized to a bandwidth of
1 hertz.

`RMS`

— Spectrum Analyzer shows the root mean squared
spectrum.

**Tunable: **Yes

#### Programmatic Use

See `SpectrumType`

.

`Sample rate`

— Sample rate of the input signal in hertz

`Inherited`

(default) | positive scalar

Sample rate of the input signal in hertz, specified as either

`Inherited`

to use the same sample rate as the input signal.Positive scalar. The specified sample rate must be at least twice the input signal sample rate. Otherwise, you might see unexpected behavior in your signal visualization due to aliasing.

#### Programmatic Use

See SampleRate (DSP System Toolbox).

`RBW (Hz)`

— Resolution bandwidth

`Auto`

(default) | positive scalar

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.

If you set this parameter to a numeric value, the value must allow at least two RBW intervals over the specified frequency span. In other words, the ratio of the overall frequency span to RBW must be greater than two:

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

**Tunable: **Yes

#### Programmatic Use

See RBW (DSP System Toolbox).

`Samples/update`

— Required number of input samples

positive scalar

This property is read-only.

The number of input samples required to compute one spectral update. You cannot modify this parameter; it is shown in the spectrum analyzer for informational purposes only. This parameter is directly related to **RBW (Hz)/Window length/Number of frequency bands**. For more details, see Algorithms (DSP System Toolbox).

If the input does not have enough samples to achieve the resolution bandwidth that you specify, Spectrum Analyzer produces a message on the display.

**Window**

`Overlap (%)`

— Segment overlap percentage

0 (default) | scalar between 0 and 100

This parameter defines the amount of 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.

**Tunable: **Yes

#### Programmatic Use

See `OverlapPercent`

(DSP System Toolbox).

`Window`

— Windowing method

`Hann`

(default) | `Rectangular`

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 window length required to achieve a resolution bandwidth and the required number of samples per update. For more information about windowing, see Windows (Signal Processing Toolbox).

**Tunable: **Yes

#### Programmatic Use

See Window (DSP System Toolbox).

`NENBW`

— Normalized effective noise bandwidth

scalar

This property is read-only.

The normalized effective noise bandwidth of the window. You cannot modify this parameter; it is shown for informational purposes only. This parameter is a measure of the noise performance of the window. The value is the width of a rectangular filter that accumulates the same noise power with the same peak power gain.

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

`Units`

— Spectrum units

`dBm`

(default)

This property is read-only.

The units of the spectrum. To change units, you must have the DSP System Toolbox.

**Tunable: **Yes

#### Programmatic Use

See SpectrumUnits (DSP System Toolbox).

`Averaging method`

— Smoothing method

`Exponential`

(default) | `Running`

Specify the smoothing method as:

`Exponential`

— Weighted average of samples. Use the`Forgetting factor`

property to specify the weighted forgetting factor.`Running`

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

property to specify*n*.

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

#### Programmatic Use

See `AveragingMethod`

.

`Averages`

— Number of spectral averages

`1`

(default) | positive integer

Specify the number of spectral averages as a positive integer. The spectrum analyzer
computes the current power spectrum estimate by computing a running average of the last
*N* power spectrum estimates. This parameter defines the number of
spectral averages, *N*.

#### Dependency

This parameter applies only when **Averaging method** is
`Running`

.

#### Programmatic Use

See `SpectralAverages`

.

`Forgetting factor`

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

#### Dependency

This parameter applies only when the **Averaging method** is
`Exponential`

.

#### Programmatic Use

See `ForgettingFactor`

.

`Reference load`

— Reference load

`1`

(default) | positive real scalar

The reference load in ohms that the Spectrum Analyzer uses as a reference to compute power values.

#### Programmatic Use

See `ReferenceLoad`

(DSP System Toolbox).

`Scale`

— Scale of frequency axis

`Linear`

(default) | `Logarithmic`

Choose a linear or logarithm scale for the frequency axis. When the frequency span contains negative frequency values, you cannot choose the logarithmic option.

#### Programmatic Use

See `FrequencyScale`

(DSP System Toolbox).

`Offset`

— Constant frequency offset

`0`

(default) | scalar

The constant frequency offset to apply to the entire spectrum, or a vector of frequencies to apply to each spectrum for multiple inputs. The offset parameter is added to the values on the Frequency axis in the Spectrum Analyzer window. This parameter is not used in any spectral computations. You must take the parameter into consideration when you set the **Span (Hz)** and **CF (Hz)** parameters to ensure that the frequency span is within the Nyquist frequency interval (DSP System Toolbox).

#### Dependency

To use this parameter, set Input domain (DSP System Toolbox) to `Time`

.

#### Programmatic Use

See `FrequencyOffset`

(DSP System Toolbox).

`Two-sided spectrum`

— Enable two-sided spectrum view

off (default) | on

Select this check box to enable a 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.

#### Programmatic Use

See `PlotAsTwoSidedSpectrum`

(DSP System Toolbox).

### Configuration Properties

The **Configuration Properties** dialog box controls visual aspects of the Spectrum Analyzer. To open the Configuration Properties, in the Spectrum Analyzer menu, select **View** > **Configuration Properties** or select the button in the toolbar dropdown.

`Title`

— Display title

character vector | string

Specify the display title. Enter `%<SignalLabel>`

to use the signal labels in the Simulink model as the axes titles.

**Tunable: **Yes

#### Programmatic Use

See `Title`

(DSP System Toolbox).

`Show legend`

— Display signal legend

off (default) | on

Show signal legend. The names listed in the legend are the signal names from the model. For signals with multiple channels, a channel index is appended after the signal name. Continuous signals have straight lines before their names and discrete signals have step-shaped lines.

From the legend, you can control which signals are visible. This control is equivalent to
changing the visibility in the **Style** parameters. 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, which hides
all other signals. 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.

#### Dependency

To enable this parameter, set View (DSP System Toolbox) to `Spectrum`

or `Spectrum and spectrogram`

.

#### Programmatic Use

See `ShowLegend`

(DSP System Toolbox).

`Show grid`

— Show internal grid lines

on (default) | off

`Y-limits (minimum)`

— Y-axis minimum

`-80`

(default) | scalar

`Y-limits (maximum)`

— Y-axis maximum

`20`

(default) | scalar

`Y-label`

— Y-axis label

character vector | string

To display signal units, add `(%<SignalUnits>)`

to the label. At the beginning of a simulation, Simulink replaces `(%SignalUnits)`

with the units associated with the signals. For example, if you have a signal for velocity with units of m/s enter

Velocity (%<SignalUnits>)

#### Programmatic Use

See `YLabel`

(DSP System Toolbox).

### Style

The **Style** dialog box controls how to Spectrum Analyzer appears. To open
the Style properties, in the Spectrum Analyzer
menu, select **View** > **Style** or select the button in the toolbar
drop-down.

`Figure color`

— Window background

gray (default) | color picker

Specify the color that you want to apply to the background of the scope figure.

`Plot type`

— Plot type

`Line`

(default) | `Stem`

`Axes colors`

— Axes background color

black (default) | color picker

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

`Properties for line`

— Channel for visual property settings

channel names

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

`Visible`

— Channel visibility

on (default) | off

Specify whether the selected channel is visible. If you clear this check box, the line disappears. You can also change signal visibility using the scope legend.

`Line`

— Line style

line, 0.5, yellow (default)

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

`Marker`

— Data point markers

`none`

(default)

Specify marks for the selected channel to show at its data points. This parameter is similar to the Marker property for plots. You can choose any of the marker symbols from the drop-down.

### Axes Scaling

The **Axes Scaling** dialog box controls the axes limits of the Spectrum Analyzer. To open the Axes Scaling properties, in the Spectrum Analyzer menu, select **Tools** > **Axes Scaling** > **Axes Scaling Properties**.

`Axes scaling`

— Automatic axes scaling

`Auto`

(default) | `Manual`

| `After N Updates`

Specify when the scope automatically scales the y-axis. By default, this parameter is set to `Auto`

, and the scope does not shrink the y-axis limits when scaling the axes. You can select one of the following options:

`Auto`

— The scope scales the axes as needed, both during and after simulation. Selecting this option shows the**Do not allow Y-axis limits to shrink**.`Manual`

— When you select this option, the scope does not automatically scale the axes. You can manually scale the axes 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+A**.

`After N Updates`

— Selecting this option causes the scope to scale the axes after a specified number of updates. This option is useful, and most efficient, when your frequency signal values quickly reach steady-state after a short period. Selecting this option shows the**Number of updates**edit box where you can modify the number of updates to wait before scaling.

**Tunable: **Yes

#### Programmatic Use

See AxesScaling (DSP System Toolbox).

`Do not allow Y-axis limits to shrink`

— Axes scaling limits

on (default) | off

When you select this parameter, the y-axis is allowed to grow during axes scaling operations. If you clear this check box, the y-axis limits can shrink during axes scaling operations.

#### Dependency

This parameter appears only when you select `Auto`

for the **Axis scaling** parameter. When you set the **Axes scaling** parameter to `Manual`

or `After N Updates`

, the *y*-axis limits can shrink.

`Number of updates`

— Number of updates before scaling

`10`

(default) | positive number

The number of updates after which the axes scale, specified as a positive integer. If the spectrogram is displayed, this parameter specifies the number of updates after which the color axes scales.

**Tunable: **Yes

#### Dependency

This parameter appears only when you set Axes scaling/Color scaling (DSP System Toolbox) to `After N Updates`

.

#### Programmatic Use

`Scale limits at stop`

— Scale axes at stop

off (default) | on

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.

`Data range (%)`

— Percent of axes

100 (default) | number in the range [1,100]

Set the percentage of the 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 parameter to `100`

, the scope scales the axis limits such that your data uses the entire axis range. If you then set this parameter to `30`

, the scope increases the *y*-axis or color range such that your data uses only 30% of the axis range.

**Tunable: **Yes

`Align`

— Alignment along axes

`Center`

(default) | `Bottom`

| `Top`

| `Left`

| `Right`

Specify where the scope aligns your data along the axis when it scales the axes. If the spectrogram is displayed, specify where the scope aligns your data along the axis when it scales the color. If you are using CCDF Measurements (DSP System Toolbox), the x axis is also configurable.

**Tunable: **Yes

## Algorithms

### Spectrum Estimation — Welch's Method

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

**Overlap %**parameter in the

**Window Options**pane of the

**Spectrum Settings**pane.

*F*is the sample rate of the input signal. Spectrum Analyzer shows sample rate in the

_{s}**Main Options**pane of the

**Spectrum Settings**pane.

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
(

*N*). You can set them to different values if

_{window}*N*is greater than or equal to

_{fft}*N*.

_{window}### Nyquist frequency interval

When the PlotAsTwoSidedSpectrum (DSP System Toolbox) 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.

### Periodogram and Spectrogram

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`

(Signal Processing Toolbox).

*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)}*[

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

$${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}}}$$

### Frequency Vector

When set to `Auto`

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

When the PlotAsTwoSidedSpectrum (DSP System Toolbox) property is set to true, the frequency vector is:

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

When the PlotAsTwoSidedSpectrum (DSP System Toolbox) property is set to false, the frequency vector is:

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

### Occupied BW

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.

### Distortion Measurements

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}$$

### Harmonic 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**. 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}

### Averaging Method

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

## Extended Capabilities

### C/C++ Code Generation

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

## Version History

**Introduced in R2016b**

## See Also

`SpectrumAnalyzerConfiguration`

| Spectrum Analyzer (DSP System Toolbox) | `dsp.SpectrumAnalyzer`

(DSP System Toolbox)

## MATLAB コマンド

次の MATLAB コマンドに対応するリンクがクリックされました。

コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。

# Select a Web Site

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

You can also select a web site from the following list:

## How to Get Best Site Performance

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

### Americas

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

### Europe

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

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