# Spectrum Estimator

Estimate power spectrum or power-density spectrum

## Library

Estimation / Power Spectrum Estimation

`dspspect3`

## Description

The Spectrum Estimator block outputs the power spectrum or power-density spectrum of a real or complex input signal, using the Welch method of averaged modified periodograms and the filter bank approach.

When you choose the filter bank approach, the block uses an analysis filter bank to estimate the power spectrum. The filter bank approach produces a spectral estimate with a higher resolution, a more accurate noise floor, and more precise peaks than the Welch method, with low or no spectral leakage. They come at the expense of increased computation and slower tracking.

When you choose the Welch method, the block computes the averaged modified periodograms to compute the spectral estimate. The block buffers the input data into overlapping segments. Use the block parameters to set the length of the data segments, the amount of data overlap between consecutive segments, and other features of the power spectrum.

For more information on the Welch method and the filter bank method, see Algorithms.

Each column of the input signal is treated as a separate channel. If the input is a two-dimensional signal, the first dimension represents the channel length (or frame size) and the second dimension represents the number of channels. If the input is a one-dimensional signal, then it is interpreted as a single channel.

## Parameters

### Main Tab

Method

Specify the spectral estimation method.

• `Filter bank` (default) — An analysis filter bank splits the broadband input signal into multiple narrow subbands. The block computes the power in each narrow frequency band, and the computed value is the spectral estimate over the respective frequency band.

• `Welch` — The block uses the Welch averaged modified periodograms method to compute the power spectrum over the narrow subbands.

Number of taps per band

Specify the number of filter coefficients, or taps, for each frequency band. This value corresponds to the number of filter coefficients per polyphase branch. The total number of filter coefficients is equal to Number of taps per band times the FFT length.

This parameter applies when you set Method to `Filter bank`. The default is 12.

Spectrum type

Type of spectrum to compute. You can set this parameter to:

• `Power` (default) — Compute the power spectrum.

• `Power density` — Compute the power spectral density.

This parameter is nontunable.

Frequency resolution method

Frequency resolution method. You can set this parameter to:

• `Auto` (default) — The Spectrum Estimator block computes the resolution bandwidth (RBW) so that the frequency span fits 1024 RBW intervals.

• Welch method — The window length, winLen, is calculated using $winLen=NENBW×Fs/RBW$. NENBW is the equivalent noise bandwidth of the window and Fs is the sample rate.

• Filter bank method — The FFT length is the ceiling of the ratio of Sample rate (Hz) to the computed resolution bandwidth.

• `RBW` — Specify the resolution bandwidth, which is used to determine the window length (Welch method) or the FFT length (filter bank method). When the block uses the Welch method, the behavior is equivalent to that of the Spectrum Analyzer block. The window length is calculated using $winLen=NENBW×Fs/RBW$. NENBW is the equivalent noise bandwidth of the window and Fs is the sample rate. The FFT length is equal to the ceiling of the ratio of Sample rate (Hz) to RBW (Hz).

• `Window length` — Specify the window or segment length to use in the Welch algorithm. This option appears when you set Method to `Welch`.

• `Number of frequency bands` — Specify the number of polyphase branches of the analysis filter bank. This value corresponds to the FFT length that the filter bank uses. This option appears when you set Method to ```Filter bank```.

This parameter is nontunable.

RBW (Hz)

Resolution bandwidth, specified as a positive scalar in Hz. The default is `5`. This parameter applies when you set Frequency resolution method to `RBW`. The ceiling of the ratio of the frequency span to RBW must be greater than `2`.

This parameter is nontunable.

Number of bands source

Source of the number of frequency bands. This parameter applies when you set Method to ```Filter bank``` and Frequency resolution method to ```Number of frequency bands```. You can set this parameter to:

• `Same as input frame length` (default) — The FFT length is set to the frame size of the input.

• `Specify on dialog` — The FFT length is the value you specify in Number of bands.

This parameter is nontunable.

Number of bands

Number of frequency bands, or the FFT length the filter bank uses to compute the power spectral estimate, specified as a positive scalar. The default is `1024`. This parameter applies when you set Method to ```Filter bank```, Frequency resolution method to `Number of frequency bands`, and Number of bands source to ```Specify on dialog```. This parameter is nontunable.

Window length source

Source of the window length value. This parameter applies when you set Method to `Welch` and Frequency resolution method to `Window length`. You can set this parameter to:

• `Same as input frame length` (default) — Window length is set to the frame size of the input. Specify this option to obtain behavior equivalent to that of the Periodogram block.

• `Specify on dialog` — Window length is the value you specify in the Window length parameter.

This parameter is nontunable.

Window length

Length of the window used to compute the spectrum estimate, specified as a positive integer scalar greater than `2`. The default is `1024`. This parameter applies when you set Method to `Welch`, Frequency resolution method to `Window length`, and Window length source to ```Specify on dialog```. This parameter is nontunable.

FFT length source

Source of the FFT length value. This parameter applies when you set Method to `Welch` and Frequency resolution method to `Window length`. You can set this parameter to:

• `Auto` (default) — The block sets the FFT length to the frame size of the input.

• `Property` — The block sets the FFT length to the value you specify in FFT length.

This parameter is nontunable.

FFT length

Length of the FFT used to compute the spectrum estimates, specified as a positive integer scalar. This parameter applies when you set Method to `Welch`, Frequency resolution method to `Window length`, and FFT length source to `Property`. The default is `1024`. This parameter is nontunable.

Inherit sample rate from input

When you select this check box, the block sample rate is computed as N/Ts, where N is the frame size of the input signal and Ts is the sample time of the input signal.

This check box applies when you do one of the following:

• Set Method to `Welch` and Frequency resolution method to ```Window length```.

• Set Method to ```Filter bank``` and Frequency resolution method to ```Number of frequency bands```.

When you clear this check box, the block sample rate is the value you specify in Sample rate (Hz). By default, this check box is selected. This parameter is nontunable.

Sample rate (Hz)

Sample rate of the input signal, specified as a positive scalar. The default is `44100`. This parameter applies when you do one of the following:

• Set Frequency resolution method to `Auto` or `RBW`.

• Set Method to `Welch`, Frequency resolution method to ```Window length```, and clear the Inherit sample rate from input check box.

• Set Method to ```Filter bank```, Frequency resolution method to ```Number of frequency bands```, and clear the Inherit sample rate from input check box.

This parameter is nontunable.

Window function

Window function the Welch algorithm uses, specified as one of `Chebyshev` | ```Flat Top``` | `Hamming` | `Hann` | `Kaiser` | `Rectangular`. This parameter appears when you set Method to `Welch`. The default is `Hann`. This parameter is nontunable.

Sidelobe attenuation of window (dB)

Sidelobe attenuation of the window, specified as a real positive scalar greater than or equal to `45`, in dB. The default is `60`. This parameter appears when you set Method to `Welch` and Window function to `Chebyshev` or `Kaiser`. This parameter is nontunable.

Averaging method

Specify the averaging method as `Exponential` (default) or `Running`. In the exponential method, the block computes the average over samples weighted by an exponentially decaying forgetting factor. In the running averaging method, the block computes an equally weighted average of specified number of spectrum estimates defined by Number of spectral averages parameter.

Number of spectral averages

Number of spectral averages, specified as a positive integer scalar. The default is `1`. The spectrum estimator computes the current power spectrum estimate by averaging the last N power spectrum estimates, where N is the number of spectral averages defined in Number of spectral averages. This parameter is nontunable.

This parameter applies when Averaging method is set to `Running`.

Specify forgetting factor from input port

Select this check box to specify the forgetting factor from an input port. When you do not select this check box, the forgetting factor is specified through the Forgetting factor parameter.

This parameter applies when Averaging method is set to `Exponential`.

Forgetting factor

Specify the exponential weighting forgetting factor as a scalar value greater than zero and smaller than or equal to one. The default is `0.9`.

This parameter applies when you set Averaging method to `Exponential` and clear the Specify forgetting factor from input port parameter.

Window overlap (%)

Percentage of overlap between successive data windows, specified as a scalar from `0` and `100`. The default value is `0`. To enable this parameter, on the Main Tab, set Method to `Welch`. This parameter is nontunable.

Load used as a reference to compute the power values, specified as a real positive scalar expressed in ohms. The default value is `1`. This parameter is nontunable.

Frequency range

Frequency range of the spectrum estimator. You can set this parameter to:

• `One-sided` — The spectrum estimator computes the one-sided spectrum of a real input signal. When the FFT length, `NFFT`, is even, the spectrum estimate has length (`NFFT`/`2`) + `1` and is computed over the frequency range `[0 SampleRate/2]`. `SampleRate` is the sample rate of the input signal. When `NFFT` is odd, the spectrum estimate has length (`NFFT` + 1)/`2` and is computed over the frequency range [`0 SampleRate/2`).

• `Two-sided` — The spectrum estimator computes the two-sided spectrum of a complex or real input signal. The length of the spectrum estimate is equal to the FFT length. The spectrum estimate is computed over the frequency range [`0 SampleRate`), where `SampleRate` is the sample rate of the input signal.

• `Centered` (default) — The spectrum estimator computes the centered two-sided spectrum of a complex or real input signal. The length of the spectrum estimate is equal to the FFT length. The spectrum estimate is computed over the frequency range (`-SampleRate/2 SampleRate/2`] when the FFT length is even and `(-SampleRate/2 SampleRate/2)` when the FFT length is odd.

This parameter is nontunable.

Power units

Units used to measure power. You can set this parameter to:

• `'Watts'` (default) — The spectrum estimator measures power in watts.

• `'dBw'` — The spectrum estimator measures power in decibel-watts.

• `'dBm'` — The spectrum estimator measures power in decibel-milliwatts.

This parameter is nontunable.

Output max-hold spectrum

When you select this check box, the block computes the max-hold spectrum of the input signal by keeping, at each frequency bin, the maximum value of all the power spectrum estimates. By default, this check box is not selected. This parameter is nontunable.

Output min-hold spectrum

When you select this check box, the block computes the min-hold spectrum of the input signal by keeping, at each frequency bin, the minimum value of all the power spectrum estimates. By default, this check box is not selected. This parameter is nontunable.

Output frequency vector

When you select this check box, the block outputs the frequency vector. By default, this check box is not selected. This parameter is nontunable.

Output effective RBW

When you select this check box, the block computes the effective resolution bandwidth. By default, this check box is not selected. This parameter is nontunable.

Simulate using

Type of simulation to run. You can set this parameter to:

• `Code generation` (default) — Simulate model using generated C code. The first time you run a simulation, Simulink® generates C code for the block. The C code is reused for subsequent simulations, as long as the model does not change. This option requires additional startup time but provides faster simulation speed than ```Interpreted execution```.

• `Interpreted execution` — Simulate model using the MATLAB®  interpreter. This option shortens startup time but has slower simulation speed than ```Code generation```.

## Example

Estimate the Power Spectral Density (PSD) of a chirp signal using the Spectrum Estimator block. Compare the PSD data with a Bluetooth® spectral mask and determine if the PSD data complies with the mask.

To view the complete model, enter `ex_psd_spectralmask` in the MATLAB command prompt.

Input Signal

The input to the Spectrum Estimator block is a chirp signal embedded in Gaussian noise with zero mean and a variance of `0.01`. The chirp signal is amplified with a gain factor in the range [`0 1`].

The Spectral mask is created using the MATLAB Function (Simulink) block. The mask is based on the Bluetooth standard described in [5].

Live Processing

The Spectrum Estimator block estimates the PSD of the chirp. In this example, the PSD data is compared with the spectral mask. The Display block shows a `1` or `0`, depending on whether the spectral data is within the mask or not. During simulation, you can change the power in the input signal by moving the slider in the Slider Gain block. Simultaneously, you can view this change in the Array Plot block.

## Supported Data Types

PortSupported Data Types

Input

• Double-precision floating point

• Single-precision floating point

Output

• Double-precision floating point

• Single-precision floating point

expand all

## References

[1] Hayes, Monson H. Statistical Digital Signal Processing and Modeling. Hoboken, NJ: John Wiley & Sons, 1996.

[2] Kay, Steven M. Modern Spectral Estimation: Theory and Application. Englewood Cliffs, NJ: Prentice Hall, 1999.

[3] Stoica, Petre, and Randolph L. Moses. Spectral Analysis of Signals. Englewood Cliffs, NJ: Prentice Hall, 2005.

[4] Welch, P. D. “The Use of Fast Fourier Transform for the Estimation of Power Spectra: A Method Based on Time Averaging Over Short, Modified Periodograms.” IEEE Transactions on Audio and Electroacoustics. Vol. 15, No. 2, June 1967, pp. 70–73.

[5] Bluetooth Specification Version 4.2. Bluetooth SIG. December 2014, p. 217. Specification of the Bluetooth System

## Version History

Introduced in R2015b