Documentation

This is machine translation

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

dsp.SpectrumEstimator System object

Package: dsp

Estimate power spectrum or power density spectrum

Description

The dsp.SpectrumEstimator computes the power spectrum or the power density spectrum of a signal, using the Welch algorithm and the filter bank approach.

When you choose the Welch method, the object computes the averaged modified periodograms to compute the spectral estimate. When you choose the filter bank approach, an analysis filter bank splits the broadband input signal into multiple narrow subbands. The object computes the power in each narrow frequency band and the computed value is the spectral estimate over the respective frequency band. 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. These results are for signals with relatively small FFT lengths. They come at the expense of increased computation and slower tracking.

The spectrum can be expressed in Watts or in decibels. This object can also estimate the max-hold and min-hold spectra of the signal. The object supports C and C++ code generation.

To estimate the power density spectrum:

  1. Define and set up your spectrum estimator object. See Construction.

  2. Call step to estimate the power density spectrum according to the properties of the object.

    Note:   Starting in R2016b, instead of using the step method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, y = step(obj,x) and y = obj(x) perform equivalent operations.

Construction

SE = dsp.SpectrumEstimator returns a System object, SE, that computes the frequency power spectrum or the power density spectrum of real or complex signals. This System object uses the Welch's averaged modified periodogram method and filter bank based spectral estimation method.

SE = dsp.SpectrumEstimator('PropertyName',PropertyValue,...) returns a Spectrum Estimator System object, SE, with each specified property name set to the specified value. You can specify additional name-value pair arguments in any order as (Name1,Value1, ..., NameN,ValueN).

Properties

SampleRate

Sample rate of input

Specify the sample rate of the input in, hertz, as a finite numeric scalar. The default value is 1 Hz. The sample rate is the rate at which the signal is sampled in time.

SpectrumType

Spectrum type

Specify the spectrum type as one of 'Power' | 'Power density'. When the spectrum type is 'Power', the power density spectrum is scaled by the equivalent noise bandwidth of the window (in Hz). The default value is 'Power'. This property is tunable.

SpectralAverages

Number of spectral averages

Specify the number of spectral averages as a positive, integer scalar. The Spectrum Estimator computes the current power spectrum or power density spectrum estimate by averaging the last N estimates. N is the number of spectral averages defined in the SpectralAverages property. The default value is 8.

FFTLengthSource

Source of the FFT length value

Specify the source of the FFT length value as one of 'Auto' | 'Property'. The default value is 'Auto'. If you set this property to 'Auto', the Spectrum Estimator sets the FFT length to the input frame size. If you set this property to 'Property', then you specify the number of FFT points using the FFTLength property.

FFTLength

FFT Length

Specify the length of the FFT that the Spectrum Estimator uses to compute spectral estimates as a positive, integer scalar. This property applies when you set the FFTLengthSource property to 'Property'. The default value is 128.

Method

Welch or filter bank

Specify the spectral estimation method as one of 'Welch' | 'Filter bank'.

  • 'Welch' — The object uses Welch's averaged modified periodograms method.

  • 'Filter bank' — An analysis filter bank splits the broadband input signal into multiple narrow subbands. The object computes the power in each narrow frequency band and the computed value is the spectral estimate over the respective frequency band. 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. These results are for signals with relatively small FFT lengths. They come at the expense of increased computation and slower tracking.

    The default is 'Welch'.

NumTapsPerBand

Number of filter taps per frequency 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 given by NumTapsPerBand × FFTLength. This property applies when you set Method to 'Filter bank'. The default is 12.

Window

Window function

Specify a window function for the spectral estimator as one of 'Rectangular' | 'Chebyshev' | 'Flat Top' | 'Hamming' | 'Hann' | 'Kaiser'. The default value is 'Hann'.

SidelobeAttenuation

Side lobe attenuation of window

Specify the side lobe attenuation of the window as a real, positive scalar, in decibels (dB). This property applies when you set the Window property to 'Chebyshev' or 'Kaiser'. The default value is 60 dB.

FrequencyRange

Frequency range of the spectrum estimate

Specify the frequency range of the spectrum estimator as one of 'twosided' | 'onesided' | 'centered'.

If you set the FrequencyRange to 'onesided', then 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], where 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).

If you set the FrequencyRange to 'twosided', then 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.

If you set the FrequencyRange to 'centered', then 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.

The default value is 'twosided'.

PowerUnits

Power units

Specify the units used to measure power as one of 'Watts' | 'dBW' | 'dBm'. The default value is 'Watts'.

ReferenceLoad

Reference load

Specify the load that the spectrum estimator uses as a reference to compute power values as a real, positive scalar in ohms. The default value is 1 ohm.

OutputMaxHoldSpectrum

Output max-hold spectrum

Set this property to true so that the Spectrum Estimator computes and outputs the max-hold spectrum of each input channel. The max-hold spectrum is computed by keeping, at each frequency bin, the maximum value of all the power spectrum estimates. The default is false.

OutputMinHoldSpectrum

Output min-hold spectrum

Set this property to true so that the Spectrum Estimator computes and outputs the min-hold spectrum of each input channel. The min-hold spectrum is computed by keeping, at each frequency bin, the minimum value of all the power spectrum estimates. The default is false.

Methods

cloneCreate spectrum estimator object with same property values
getFrequencyVectorGet the vector of frequencies at which the spectrum is estimated
getRBWGet the resolution bandwidth of the spectrum
isLockedLocked status for input attributes and nontunable properties
resetReset the internal states of the spectrum estimator
stepEstimate the power spectrum or power-density spectrum of a signal

Examples

expand all

Compare spectral estimates of sinusoids embedded in white Gaussian noise using a Hann window based Welch method and filter bank method.

Initialization

Initialize two dsp.SpectrumEstimator objects. Specify one estimator to use the Welch-based spectral estimation technique with a Hann window. Specify the other estimator to use an analysis filter bank to perform the spectral estimation. Specify a noisy sine wave input signal with 4 sinusoids at 0.16, 0.2, 0.205, and 0.25 cycles/sample. View the spectral estimate using an array plot.

FrameSize = 420;
Fs = 1;
sinegen = dsp.SineWave('SampleRate',Fs,...
    'SamplesPerFrame',FrameSize,...
    'Frequency',[0.16 0.2 0.205 0.25],...
    '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.ArrayPlot(...
    'PlotType','Line','SampleIncrement',Fs/FrameSize,...
    'YLimits',[-250,50],'YLabel','dBm',...
    'ShowLegend',true,'ChannelNames',{'Hann window','Filter bank'});

Streaming

Stream the input. Compare the spectral estimates computed using the Hann window and the analysis filter bank

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

The Hann window misses the peak at 0.205 cycles/sample. In addition, the window has a significant spectral leakage that makes the peak at 0.16 cycles/sample hard to distinguish, and the noise floor is not correct.

The filter bank estimate has a very good resolution with no spectral leakage.

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent step syntax. For example, myObject(x) becomes step(myObject,x).

Generate a sine wave.

SINE = dsp.SineWave('Frequency',100,'SampleRate',1000, ...
    'SamplesPerFrame',1000);

Use the Spectrum Estimator to compute the power spectrum and the max-hold spectrum of the sine wave. Use the Array Plot to display the spectra.

SE = dsp.SpectrumEstimator('SampleRate',SINE.SampleRate, ...
    'SpectrumType','Power','PowerUnits','dBm', ...
    'FrequencyRange','centered','OutputMaxHoldSpectrum',true);
PLOTTER = dsp.ArrayPlot('PlotType','Line','XOffset',-500, ...
    'YLimits',[-60 30], 'Title','Power Spectrum of 100 Hz Sine Wave', ...
    'YLabel','Power Spectrum (dBm)','XLabel','Frequency (Hz)');

Add random noise to the sine wave. Stream in the data, and plot the power spectrum of the signal.

for ii = 1:10
    x = SINE() + 0.05*randn(1000,1);
    [Pxx,Pmax] = SE(x);
    PLOTTER([Pxx Pmax]);
end

Algorithms

Welch's Method of Averaged Modified Periodograms

Let x be the input frame. We first multiply x by the window, and scale it by the window power. We then take FFT of the signal, calling it Y, and take the square magnitude using Z = Y*conj(Y). We average the last N Zs and scale the answer by the sample rate.

For further information refer to the Algorithms section in Spectrum Analyzer, which uses the same algorithm.

Filter Bank

The spectrum estimator uses an analysis filter bank to estimate the power spectrum. For more details on the implementation, see the Algorithm section in dsp.Channelizer.

The filter bank based spectrum estimator splits the broadband input signal, x(n), into multiple narrow bands and computes the power in each band. Each value becomes the estimate of the power over that narrow frequency band. The power in all the narrow bands forms the spectral estimate vector.

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. Upper Saddle River, NJ: Prentice Hall, 2005

[4] Welch, P. D. "The use of fast Fourier transforms for the estimation of power spectra: A method based on time averaging over short modified periodograms," IEEE Transactions on Audio and Electroacoustics, Vol. 15, 1967, pp. 70–73.

[5] Harris, F.J. Multirate Signal Processing for Communication Systems. Prentice Hall. 2004, pp. 208–209.

Introduced in R2013b

Was this topic helpful?