DSP System Toolbox Getting Started Guide
DSP System Toolbox Getting Started Guide
R2024b
How to Contact MathWorks
Phone: 508-647-7000
Introduction
1
DSP System Toolbox Product Description . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
v
1
Introduction
DSP System Toolbox provides algorithms, apps, and scopes for designing, simulating, and analyzing
signal processing systems in MATLAB® and Simulink®. You can model real-time DSP systems for
communications, radar, audio, medical devices, IoT, and other applications.
With DSP System Toolbox you can design and analyze FIR, IIR, multirate, multistage, and adaptive
filters. You can stream signals from variables, data files, and network devices for system development
and verification. The Time Scope, Spectrum Analyzer, and Logic Analyzer let you dynamically
visualize and measure streaming signals. For desktop prototyping and deployment to embedded
processors, including ARM® Cortex® architectures, the toolbox supports C/C++ code generation. It
also supports bit-accurate fixed-point modeling and HDL code generation from filters, FFT, IFFT, and
other algorithms.
Algorithms are available as MATLAB functions, System objects, and Simulink blocks.
Key Features
• Signal processing and linear algebra blocks for Simulink
• Streaming signal processing in MATLAB
• Single-rate, multirate, FIR, IIR, and adaptive filter design
• Time Scope, Spectrum Analyzer, and Logic Analyzer for visualizing and measuring streaming
signals
• Fixed-point modeling and simulation of signal processing algorithms
• Support for C and C++ code generation
• Support for HDL code generation
1-2
Configure Simulink Environment for Signal Processing Models
For more information on Simulink model templates, see “Create Template from Model” (Simulink).
1 On the MATLAB Home tab, in the File section, click New > Simulink Model. The Simulink
Start Page opens with built-in Simulink model templates.
2 Click one of the templates under DSP System Toolbox to create a model with settings suitable
for use with DSP System Toolbox. A new model using the template settings and contents appears
in the Simulink Editor. The model is only in memory until you save it.
1-3
1 Introduction
3 To access the library browser, click Library Browser on the model toolstrip.
Basic Filter
Click on Basic Filter to create a basic filtering model configured with settings recommended for DSP
System Toolbox.
This model implements a lowpass filter and enables you to compare the filtered signal with the
original signal. The model acts as a starting point for modeling filtering algorithms in Simulink using
DSP System Toolbox.
1-4
Configure Simulink Environment for Signal Processing Models
Here is the Spectrum Analyzer output showing the original signal and the filtered signal. The input
signal contains tones at 1 kHz and 15 kHz. The 1 kHz tone gets passed in the filtered output while the
15 kHz tone gets attenuated.
Design and implement FIR and IIR filters with tunable filter specifications using the Tunable FIR
and IIR Filters template.
This model shows how to design FIR and IIR filters using the Lowpass FIR Filter Design and the
Lowpass IIR Filter Design design blocks. You can tune the filter cutoff frequency using the Knob
1-5
1 Introduction
block. The magnitude response of the designed filters varies as you tune the filter cutoff frequency
during simulation. Visualize the magnitude response of the designed filters using the Filter Visualizer
block. As with the Basic Filter model template, the input is a noisy sinusoidal signal with tones at 1
kHz and 15 kHz.
The Discrete FIR Filter block and the Second-Order Section Filter block implement a lowpass FIR
filter and a highpass IIR filter using the coefficients from the design blocks.
The Filter Visualizer output shows the varying magnitude response of the FIR filter and the IIR filter,
and the Spectrum Analyzer output shows the spectra of the original and the filtered signals. In the
Spectrum Analyzer output, both tones get attenuated. The 1 kHz tone gets attenuated by the IIR filter
and the 15 kHz tone gets attenuated by the FIR filter.
The Interpolated FIR Filter template provides an efficient alternative to a single-stage high-order
FIR filter, as it filters the signal at a lower sampling rate. This implementation processes the input
signal in multiple stages. A noisy input first passes through an FIR decimator, which lowers the
sampling rate of the signal. The signal is then filtered by an FIR filter at this lower sampling rate. An
FIR interpolator at the end converts the sampling rate of the filtered output back to its original value.
1-6
Configure Simulink Environment for Signal Processing Models
The Spectrum Analyzer block in the model shows the spectrum of the filtered signal.
Mixed-Signal System
Click the Mixed-Signal System template to create a basic A/D converter model configured with
settings recommended for DSP System Toolbox and mixed-signal systems. This model performs A/D
conversion by implementing an analog anti aliasing filter followed by a zero-order hold circuit. The
model acts as a starting point for modeling mixed-signal systems in Simulink using DSP System
Toolbox. All discrete-time signals are colored in red to indicate the fastest sample rate. Continuous-
time signals are colored in black. For additional sample time options, in the Debug tab, select
Information Overlays > Colors.
1-7
1 Introduction
The Scope block in the model plots the continuous-time signal and the discrete-time signal.
The Spectrum Analyzer block shows the spectrum of the discrete-time signal.
1-8
Configure Simulink Environment for Signal Processing Models
See Also
• “Filter Frames of a Noisy Sine Wave Signal in Simulink”
1-9
2
Design a digital lowpass filter using the Digital Filter Design block and incorporate the block into
your model to simulate the presence of low frequency noise.
You can design lowpass, highpass, bandpass, and bandstop filters using either the Digital Filter
Design block or the Filter Realization Wizard. These blocks are capable of calculating filter
coefficients for various filter structures. This topic uses the Digital Filter Design block to convert
white noise to low frequency noise so you can simulate its effect on your system.
As a practical application, suppose a pilot is speaking into a microphone within the cockpit of an
airplane. The noise of the wind passing over the fuselage is also reaching the microphone. A sensor is
measuring the noise of the wind on the outside of the plane. You want to estimate the wind noise
inside the cockpit and subtract it from the input to the microphone so that only the pilot's voice is
transmitted.
In the first section of this topic, you learn how to model the low frequency noise that is reaching the
microphone. In the second section of the topic, you learn how to remove this noise so that only the
pilot's voice is heard.
In this section, you use a Digital Filter Design block to create low frequency noise, which models the
wind noise inside the cockpit.
Open the ex_gstut3 model. This model contains a Scope block that displays the original sine wave
and the sine wave with white noise added.
Open the DSP System Toolbox™ library by typing dsplib at the MATLAB® command prompt.
Convert white noise to low frequency noise by introducing a Digital Filter Design block into your
model. In the airplane scenario, the air passing over the fuselage creates white noise that is
measured by a sensor. The Random Source block models this noise. The fuselage of the airplane
converts this white noise to low frequency noise, a type of colored noise, which is heard inside the
2-2
Design and Implement a Filter
cockpit. This noise contains only certain frequencies and is more difficult to eliminate. In this
example, you model the low frequency noise using a Digital Filter Design block. This block uses the
functionality of the Filter Design and Analysis Tool (FDATool) to design a filter.
Double-click the Filtering library, and then double-click the Filter Implementations sublibrary. Click-
and-drag the Digital Filter Design block into your model.
Set the Digital Filter Design block parameters to design a lowpass filter and create low frequency
noise. Open the block parameters dialog box by double-clicking the block. Set the parameters as
follows:
Based on these parameters, the Digital Filter Design block designs a lowpass FIR filter with 32
coefficients and a cutoff frequency of 0.5. The block multiplies the time-domain response of your filter
by a 32 sample Hamming window.
Click Design Filter at the bottom center of the dialog box to view the magnitude response of your
filter in the Magnitude Response pane. The Digital Filter Design dialog box should now look similar
to the following figure.
2-3
2 Design Filters in Simulink
You have now designed a digital lowpass filter using the Digital Filter Design block.
You can experiment with the Digital Filter Design block in order to design a filter of your own. For
more information on the block functionality, see the Digital Filter Design block reference page.
In this section, you add the lowpass filter you designed in “Design a Digital Filter in Simulink” on
page 2-2 to your block diagram. Use this filter, which converts white noise to colored noise, to
simulate the low frequency wind noise inside the cockpit:
If the model you created in “Design a Digital Filter in Simulink” on page 2-2 is not open on your
desktop, open ex_gstut4 which is an equivalent model.
2-4
Design and Implement a Filter
Incorporate the Digital Filter Design block into your block diagram by placing it between the Random
Source block and the Sum block.
Run your model and view the results in the Scope window. This window shows the original input
signal and the signal with low frequency noise added to it.
2-5
2 Design Filters in Simulink
You have now built a digital filter and used it to model the presence of colored noise in your signal.
This is analogous to modeling the low frequency noise reaching the microphone in the cockpit of the
aircraft. Now that you have added noise to your system, you can experiment with methods to
eliminate it.
See Also
Blocks
Digital Filter Design | Filter Realization Wizard
Related Examples
• “Remove Low Frequency Noise in Simulink Using Normalized LMS Adaptive Filter” on page 2-
7
• “Using Filter Designer”
2-6
Remove Low Frequency Noise in Simulink Using Normalized LMS Adaptive Filter
Adaptive filters track the dynamic nature of a system and allow you to eliminate time-varying signals.
The DSP System Toolbox libraries contain blocks that implement least-mean-square (LMS), block
LMS, fast block LMS, and recursive least squares (RLS) adaptive filter algorithms. These filters
minimize the difference between the output signal and the desired signal by altering their filter
coefficients. Over time, the adaptive filter's output signal more closely approximates the signal you
want to reproduce.
In this example, you design an LMS adaptive filter to remove the low frequency noise in your signal:
If the model you created in “Add a Digital Filter to Your Model” on page 2-4 is not open on your
desktop, open ex_gstut5 which is an equivalent model.
Open the DSP System Toolbox™ library by typing dsplib at the MATLAB® command prompt.
Remove the low frequency noise from your signal by adding an LMS Filter block to your system. In
the airplane scenario, this is equivalent to subtracting the wind noise inside the cockpit from the
input to the microphone. Double-click the Filtering library, and then double-click the Adaptive Filters
library. Add the LMS Filter block into your model.
2-7
2 Design Filters in Simulink
Set the LMS Filter block parameters to model the output of the Digital Filter Design block. Open the
LMS Filter dialog box by double-clicking the block. Set and apply the block parameters as follows:
Based on these parameters, the LMS Filter block computes the filter weights using the normalized
LMS equations. The filter order you specified is the same as the filter order of the Digital Filter
Design block. The Step size (mu) parameter defines the granularity of the filter update steps.
Because you set the Leakage factor (0 to 1) parameter to 1.0, the current filter coefficient values
depend on the filter's initial conditions and all of the previous input values. The initial value of the
filter weights (coefficients) is zero. Since you selected the Output filter weights check box, the Wts
port appears on the block. The block outputs the filter weights from this port.
Now that you have set the block parameters of the LMS Filter block, you can incorporate this block
into your block diagram.
In this example, you recover your original sinusoidal signal by incorporating the adaptive filter you
designed in “Design an Adaptive Filter in Simulink” on page 2-7 into your system. In the aircraft
scenario, the adaptive filter models the low frequency noise heard inside the cockpit. As a result, you
can remove the noise so that the pilot's voice is the only input to the microphone:
If the model you created in “Design an Adaptive Filter in Simulink” on page 2-7 is not open on your
desktop, open ex_gstut6 which is an equivalent model.
2-8
Remove Low Frequency Noise in Simulink Using Normalized LMS Adaptive Filter
Add a Sum block to your model to subtract the output of the adaptive filter from the sinusoidal signal
with low frequency noise. From the Simulink® Math Operations library, drag a Sum block into your
model. Open the Sum dialog box by double-clicking this block. Change the List of signs parameter
to |+- and then click OK.
• Connect the output of the Random Source block to the Input port of the LMS Filter block. In the
aircraft scenario, the random noise is the white noise measured by the sensor on the outside of
the airplane. The LMS Filter block models the effect of the airplane's fuselage on the noise.
• Connect the output of the Digital Filter Design block to the Desired port on the LMS Filter block.
This is the signal you want the LMS block to reproduce.
• Connect the output of the LMS Filter block to the negative port of the Sum block you added in
step 2.
• Connect the output of the first Sum block to the positive port of the second Sum block. Your model
should now look similar to the following figure.
2-9
2 Design Filters in Simulink
The positive input to the second Sum block is the sum of the input signal and the low frequency noise,
s(n) + y. The negative input to the second Sum block is the LMS Filter block's best estimation of the
low frequency noise, y'. When you subtract the two signals, you are left with an approximation of the
input signal.
sn approx = s n + y − y′
In this equation:
Because the LMS Filter block can only approximate the noise, there is still a difference between the
input signal and the approximation of the input signal. In subsequent steps, you set up the Scope
block so you can compare the original sinusoidal signal with its approximation.
Add two additional inputs and axes to the Scope block. Open the Scope dialog box by double-clicking
the Scope block. Click the Parameters button. For the Number of input ports parameter, enter 4.
Close the dialog box by clicking OK.
Label the new Scope axes. In the Scope window, right-click on the third axes and select Axes
properties. The Scope properties: axis 3 dialog box opens. In the Title box, enter Approximation
of Input Signal. Close the dialog box by clicking OK. Repeat this procedure for the fourth axes
and label it Error.
Connect the output of the second Sum block to the third port of the Scope block.
2-10
Remove Low Frequency Noise in Simulink Using Normalized LMS Adaptive Filter
Connect the output of the Error port on the LMS Filter block to the fourth port of the Scope block.
Your model should now look similar to the following figure.
In this example, the output of the Error port is the difference between the LMS filter's desired signal
and its output signal. Because the error is never zero, the filter continues to modify the filter
coefficients in order to better approximate the low frequency noise. The better the approximation, the
more low frequency noise that can be removed from the sinusoidal signal. In the next topic, “View the
Coefficients of Your Adaptive Filter” on page 2-11, you learn how to view the coefficients of your
adaptive filter as they change with time.
The coefficients of an adaptive filter change with time in accordance with a chosen algorithm. Once
the algorithm optimizes the filter's performance, these filter coefficients reach their steady-state
values. You can view the variation of your coefficients, while the simulation is running, to see them
settle to their steady-state values. Then, you can determine whether you can implement these values
in your actual system:
If the model you created in Add an “Add an Adaptive Filter to Your Model” on page 2-8 is not open on
your desktop, open ex_gstut7 which is an equivalent model.
Note that the Wts port of the adaptive filter, which outputs the filter weights, still needs to be
connected.
2-11
2 Design Filters in Simulink
Open the DSP System Toolbox™ library by typing dsplib at the MATLAB® command prompt.
View the filter coefficients by connecting a Time Scope block to the Wts port of the LMS Filter block.
2-12
Remove Low Frequency Noise in Simulink Using Normalized LMS Adaptive Filter
Open Model Settings. In the Modeling tab, click Model Settings. In the Solver pane, set these
configuration parameters:
We recommend these configuration parameters for models that contain DSP System Toolbox blocks.
Because these blocks calculate values directly rather than solving differential equations, you must
configure the Simulink® Solver to behave like a scheduler. The Solver, while in scheduler mode, uses
a block's sample time to determine when the code behind each block is executed. For example, the
sample time of the Sine Wave and Random Source blocks in this model is 0.05. The Solver executes
the code behind these blocks, and every other block with this sample time, once every 0.05 second.
Note: When working with models that contain DSP System Toolbox blocks, use source blocks that
enable you to specify their sample time. If your source block does not have a Sample time
parameter, you must add a Zero-Order Hold block in your model and use it to specify the sample time.
For more information, see “Continuous-Time Source Blocks”. The exception to this rule is the
Constant block, which can have a constant sample time. When it does, Simulink executes this block
and records the constant value once at the start of the simulation and any time you tune a parameter.
This allows for faster simulations and more compact generated code.
Run your model and view the behavior of your filter coefficients in the Time Scope, which opens
automatically when your simulation starts. Over time, the filter coefficients approach their steady-
state values.
2-13
2 Design Filters in Simulink
You can also view the behavior of the system in the Scope window. Over time, you see the error
decrease and the approximation of the input signal more closely match the original sinusoidal input
signal.
2-14
Remove Low Frequency Noise in Simulink Using Normalized LMS Adaptive Filter
Summary
You have learned how to design a lowpass filter using the Digital Filter Design block. You also learned
how to create an adaptive filter using the LMS Filter block. The DSP System Toolbox product has
other blocks capable of designing and implementing digital and adaptive filters. For more information
on the filtering capabilities of this product, see “Filter Design” and “Filter Analysis”.
Because all blocks in this model have the same sample time, this model is single rate, and Simulink
ran it in SingleTasking solver mode. If the blocks in your model have different sample times, your
model is multirate and Simulink might run it in MultiTasking solver mode. For more information on
solver modes, see “Recommended Settings for Discrete-Time Simulations”.
To learn how to generate code from your model using the Simulink Coder™ product, see “Generate C
Code from Simulink Model”.
See Also
LMS Filter | Digital Filter Design
More About
• “Filter Design”
• “Filter Analysis”
2-15