Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

You can use DSP System Toolbox™ blocks to work with signals in both the time and frequency domain. To display frequency-domain signals, you can use blocks from the Sinks library, such as the Vector Scope, Spectrum Analyzer, Matrix Viewer, and Waterfall Scope blocks.

With the Spectrum Analyzer block, you can display the frequency spectra of time-domain input data. In contrast to the Vector Scope block, the Spectrum Analyzer block computes the Fast Fourier Transform (FFT) of the input signal internally, transforming the signal into the frequency domain.

This example shows how you can use a Spectrum Analyzer block to display the frequency content of two frame-based signals simultaneously:

At the MATLAB

^{®}command prompt, type`ex_spectrumanalyzer_tut`

.The Spectrum Analyzer example opens, and the variables,

`Fs`

and`mtlb`

, are loaded into the MATLAB workspace.Double-click the Signal From Workspace block. Set the block parameters as follows, and then click

**OK**:**Signal**=`mtlb`

**Sample time**=`1`

**Samples per frame**=`16`

**Form output after final data value**=`Cyclic Repetition`

Based on these parameters, the Signal From Workspace block repeatedly outputs the input signal,

`mtlb`

, as a frame-based signal with a sample period of 1 second.Create two distinct signals to send to the Spectrum Analyzer block. Use the Digital Filter Design block to filter the input signal, using the default parameters.

Double-click the Matrix Concatenate block. Set the block parameters as follows, and then click

**OK**:**Number of inputs**=`2`

**Mode**=`Multidimensional array`

**Concatenate dimension**=`2`

The Matrix Concatenate block combines the two signals so that each column corresponds to a different signal.

Double-click the Spectrum Analyzer block. The Spectrum Analyzer figure appears. In the menu, select

**View**>**Spectrum Settings**. The Spectrum Settings panel opens.Expand the

**Main options**pane, if it is not already expanded.Set

**Type**to`Power`

.Select the

**Full frequency span**check box.Set

**RBW (Hz)**to`5.91e-3`

.

Expand the

**Trace options**pane, if it is not already expanded.Set

**Units**to`dBW`

.Set

**Averages**to`2`

.

Expand the

**Window options**pane, if it is not already expanded.Set

**Overlap (%)**to`50`

.Set

**Window**to`Hann`

.

Based on these parameters, the Spectrum Analyzer uses 128 samples from each input channel to calculate a new windowed data segment, as shown in the following equation.

$$D=\frac{NENBW\times {F}_{s}}{RBW}=\frac{1.512\times 1Hz}{11.8125\times {10}^{-3}Hz}=128samples$$

There are also 128 frequency points in the FFT. Also, because

**Overlap (%)**is set to`50`

, there is a buffer overlap length of 64 samples in each spectral estimate, as shown in the following equation.$${O}_{L}=\frac{{O}_{P}}{100}\times L=\frac{50}{100}\times 128=64samples$$

Every time the scope updates the display, 64 points are plotted for each channel. At 16 samples per frame, Spectrum Analyzer waits for 3 frames or 48 samples before displaying the first power spectral estimate.

Fit all the calculated data points into the display. In the Spectrum Analyzer menu, select

**Tools**>**Automatically Scale Axes Limits**.In the Spectrum Analyzer menu, select

**View**>**Configuration Properties**. Then, select the**Show legend**check box.Run the model. The Spectrum Analyzer block computes the FFT of each of the input signals. It then displays the power spectra of the frequency-domain signals in the Spectrum Analyzer window.

The power spectrum of the first input signal, from column one, is the yellow line. The power spectrum of the second input signal, from column two, is the blue line.

Was this topic helpful?