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,
The Spectrum Analyzer example opens, and the variables,
are loaded into the MATLAB workspace.
Double-click the Signal From Workspace block. Set the block parameters as follows, and then click OK:
Sample time =
Samples per frame =
Form output after final data value =
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 =
Concatenate dimension =
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
Select the Full frequency span check box.
Set RBW (Hz) to
Expand the Trace options pane, if it is not already expanded.
Set Units to
Set Averages to
Expand the Window options pane, if it is not already expanded.
Set Overlap (%) to
Set Window to
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.
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.
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.