## Spectral Analysis

Spectral analysis is the process of estimating the power spectrum (PS) of a signal from its time-domain representation. Spectral density characterizes the frequency content of a signal or a stochastic process. Intuitively, the spectrum decomposes the signal or the stochastic process into the different frequencies, and identifies periodicities. The most commonly used instrument for performing spectral analysis is the spectrum analyzer.

Spectral analysis is done based on the nonparametric methods and the parametric methods. Nonparametric methods are based on dividing the time-domain data into segments, applying Fourier transform on each segment, computing the squared-magnitude of the transform, and summing and averaging the transform. Nonparametric methods such as modified periodogram, Bartlett, Welch, and the Blackman-Tukey methods, are a variation of this approach. These methods are based on measured data and do not require prior knowledge about the data or the model. Parametric methods are model-based approaches. The model for generating the signal can be constructed with a number of parameters that can estimated from the observed data. From the model and estimated parameters, the algorithm computes the power spectrum implied by the model.

The spectrum analyzer in DSP System Toolbox™ uses the Welch’s nonparametric method of averaging modified periodogram and the filter bank method to estimate the power spectrum of a streaming signal in real time. You can launch the spectrum analyzer using the `dsp.SpectrumAnalyzer` System object™ in MATLAB® and the Spectrum Analyzer block in Simulink®.

### Welch’s Algorithm of Averaging Modified Periodograms

To use the Welch method in the spectrum analyzer, set the Method parameter to `Welch`. The Welch's technique to reduce the variance of the periodogram breaks the time series into overlapping segments. This method computes a modified periodogram for each segment and then averages these estimates to produce the estimate of the power spectrum. Because the process is wide-sense stationary and Welch's method uses PS estimates of different segments of the time series, the modified periodograms represent approximately uncorrelated estimates of the true PS. The averaging reduces the variability.

The segments are multiplied by a window function, such as a Hann window, so that Welch's method amounts to averaging modified periodograms. Because the segments usually overlap, data values at the beginning and end of the segment tapered by the window in one segment, occur away from the ends of adjacent segments. The overlap guards against the loss of information caused by windowing. In the Spectrum Analyzer block, you can specify the window using the Window parameter.

The algorithm in the Spectrum Analyzer block consists of these steps:

1. The block buffers the input into N point data segments. Each data segment is split up into L overlapping data segments, each of length M, overlapping by D points. The data segments can be represented as:

`$\begin{array}{l}{x}_{i}\left(n\right)=x\left(n+iD\right),\text{ }\text{ }n=0,1,...,M-1\\ \text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }i=0,1,...,L-1\end{array}$`

• If D = M/2, the overlap is 50%.

• If D = 0, the overlap is 0%.

The block uses the `RBW` or the `Window Length` setting in the Spectrum Settings pane to determine the data window length. Then, it partitions the input signal into a number of windowed data segments.

The spectrum analyzer requires a minimum number of samples (Nsamples) 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 the resolution bandwidth, RBW, by the following equation:

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

• Op, the amount of overlap (%) between the previous and current buffered data segments, is specified through the Overlap (%) parameter in the Window options pane.

• NENBW, the normalized effective noise bandwidth of the window depends on the windowing method. This parameter is shown in the Window options pane.

• Fs is the sample rate of the input signal.

When in `RBW` mode, the window length required to compute one spectral update, Nwindow, is directly related to the resolution bandwidth and normalized effective noise bandwidth:

${N}_{window}=\frac{NENBW×{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, Nsamples, is directly related to the window length and the amount of overlap:

${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, the table shows the number of input samples required to compute one spectral update when the window length is 100.

OverlapNsamples
0%100
50%50
80%20

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

$NENBW={N}_{window}×\frac{\sum _{n=1}^{{N}_{window}}{w}^{2}\left(n\right)}{{\left[\sum _{n=1}^{{N}_{window}}w\left(n\right)\right]}^{2}}$

When in RBW mode, you can set the resolution bandwidth using the value of the RBW parameter on the Main options pane. You must specify a value so 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 so that there are 1024 RBW intervals over the specified frequency span. Thus, when you set RBW to `Auto`, RBW is calculated by: $RB{W}_{auto}=\frac{span}{1024}$

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

$\frac{NENBW×{F}_{s}}{{N}_{window}}$.

2. Apply a window to each of the L overlapping data segments in the time domain. Most window functions afford more influence to the data at the center of the set than to the data at the edges, which represents a loss of information. To mitigate that loss, the individual data sets are commonly overlapped in time. For each windowed segment, compute the periodogram by computing the discrete Fourier transform. Then compute the squared magnitude of the result, and divide the result by M.

`${P}_{xx}^{i}\left(f\right)=\frac{1}{MU}{|\sum _{n=0}^{M-1}{x}_{i}\left(n\right)w\left(n\right){e}^{-j2\pi fn}|}^{2},\text{ }\text{ }i=0,1,...,L-1$`

where U is a normalization factor for the power in the window function and is given by

`$U=\frac{1}{M}\sum _{n=0}^{M-1}{w}^{2}\left(n\right)$`

.

You can specify the window using the Window parameter.

3. To determine the Welch power spectrum estimate, the Spectrum Analyzer block averages the result of the periodograms for the last L data segments. The averaging reduces the variance, compared to the original N point data segment.

`${P}_{xx}^{W}\left(f\right)=\frac{1}{L}\sum _{i=0}^{L-1}{P}_{xx}^{i}\left(f\right)$`

L is specified through the Averages parameter in the Trace options pane.

4. The Spectrum Analyzer block computes the power spectral density using:

`${P}_{xx}^{W}\left(f\right)=\frac{1}{L*{F}_{s}}\sum _{i=0}^{L-1}{P}_{xx}^{i}\left(f\right)$`

.

### Filter Bank

To use the filter bank approach in the spectrum analyzer, set the Method parameter to `Filter bank`. In the filter bank approach, the analysis filter bank splits the broadband input signal into multiple narrow subbands. The spectrum analyzer computes the power in each narrow frequency band and the computed value is the spectral estimate over the respective frequency band. For signals with relatively small length, the filter bank approach produces a spectral estimate with a higher resolution, a more accurate noise floor, and peaks more precise than the Welch method, with low or no spectral leakage. These advantages come at the expense of increased computation and slower tracking.

For information on how the filter bank computes the power, see the Algorithms section in `dsp.SpectrumEstimator`. For more information on the analysis filter bank and how it is implemented, see the More About and the Algorithm sections in `dsp.Channelizer`.

## References

[1] Proakis, John G., and Dimitris G. Manolakis. Digital Signal Processing. 3rd ed. Upper Saddle River, NJ: Prentice Hall, 1996.

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