The Filter Realization Wizard is another DSP System Toolbox™ block that can be used to design and implement digital filters. You can use this tool to filter single-channel floating-point or fixed-point signals. Like the Digital Filter Design block, double-clicking a Filter Realization Wizard block opens filter designer. Unlike the Digital Filter Design block, the Filter Realization Wizard starts filter designer with the Realize Model panel selected. This panel is optimized for use with DSP System Toolbox software.
For more information, see the Filter Realization Wizard block reference page. For information on choosing between the Digital Filter Design block and the Filter Realization Wizard, see Select a Filter Design Block.
In this section, a tutorial guides you through creating a fixed-point filter with the Filter Realization Wizard. You will use the Filter Realization Wizard to remove noise from a signal. This tutorial has the following parts:
In this section of the tutorial, you will create a signal with added noise. Later in the tutorial, you will filter this signal with a fixed-point filter that you design with the Filter Realization Wizard.
load mtlb soundsc(mtlb,Fs)
at the MATLAB® command line. You should hear a voice say “MATLAB.” This is the signal to which you will add noise.
Create a noise signal by typing
noise = cos(2*pi*3*Fs/8*(0:length(mtlb)-1)/Fs)';
at the command line. You can hear the noise signal by typing
Add the noise to the original signal by typing
u = mtlb + noise;
at the command line.
Scale the signal with noise by typing
u = u/max(abs(u));
at the command line. You scale the signal to try to avoid overflows later on. You can hear the scaled signal with noise by typing
View the scaled signal with noise by typing
at the command line.
The spectrogram appears as follows.
In the spectrogram, you can see the noise signal as a line at about 2800 Hz, which is
Next you will create a fixed-point filter using the Filter Realization Wizard. You will create a filter that reduces the effects of the noise on the signal.
Open a new Simulink® model, and drag-and-drop a Filter Realization Wizard block from the Filtering / Filter Implementations library into the model.
You do not have to place a Filter Realization Wizard block in a model in order to use it. You can open the app from within a library. However, for purposes of this tutorial, we will keep the Filter Realization Wizard block in the model.
Double-click the Filter Realization Wizard block in your model. The Realize Model panel of the filter designer appears.
Click the Design Filter button () on the bottom left of filter designer. This brings forward the Design filter panel of the tool.
Set the following fields in the Design filter panel:
Set Design Method to
IIR -- Constrained
Set Fs to
Set Fpass to
Set Fstop to
Set Max pole radius to
Click the Design Filter button
The Design filter panel should now appear as follows.
Click the Set quantization parameters button on the bottom left of filter designer (). This brings forward the Set quantization parameters panel of the tool.
Set the following fields in the Set quantization parameters panel:
Fixed-point for the Filter
Make sure the Best precision fraction lengths check box is selected on the Coefficients pane.
The Set quantization parameters panel should appear as follows.
Click the Realize Model button on the left side of filter designer (). This brings forward the Realize Model panel of the tool.
Select the Build model using basic elements check box, then click the Realize Model button on the bottom of filter designer. A subsystem block for the new filter appears in your model.
You do not have to keep the Filter Realization Wizard block in the same model as the generated Filter block. However, for this tutorial, we will keep the blocks in the same model.
Filter subsystem block in
your model to view the filter implementation.
In this section of the tutorial, you will filter noise from a signal in your Simulink model.
Connect a Signal From Workspace block from the Sources library to the input port of your filter block.
Connect a To Workspace block from the Sinks library to the output port of your filter block. Your blocks should now be connected as follows.
Open the Signal From Workspace block dialog box and set the
Signal parameter to
OK to save your changes and close the dialog box.
Open the Model Configuration Parameters dialog box from the Simulation menu of the model. In the Solver pane of the dialog, set the following fields:
Stop time =
Click OK to save your changes and close the dialog box.
Run the model.
From the Display menu of the model,
select Signals & Ports > Port Data Types. You can now see that the input to the Filter block is a signal of type
double and the output of the Filter block has a data type of
Now you can listen to and look at the results of the fixed-point filter you designed and implemented.
at the command line to hear the output of the filter. You should hear a voice say “MATLAB.” The noise portion of the signal should be close to inaudible.
at the command line.
From the colorbars at the side of the input and output spectrograms, you can see that the noise has been reduced by about 40 dB.
The Current Filter Information region of filter designer shows the structure and the number of second-order sections in your filter.
Change the filter structure and number of filter sections of your filter as follows:
Select Convert Structure from the Edit menu to open the Convert Structure dialog box. For details, see “Converting to a New Structure” in the Signal Processing Toolbox™ documentation.
Select Convert to Second-Order Sections from the Edit menu to open the Convert to SOS dialog box. For details, see “Converting to Second-Order Sections” in the Signal Processing Toolbox documentation.
The Filter Realization Wizard can implement a digital filter using either digital filter blocks from the DSP System Toolbox library or by creating a subsystem (Simulink) block that implements the filter using Sum, Gain, and Delay blocks. The following procedure shows you how to optimize the filter implementation:
Open the Realize Model pane of filter designer by clicking the Realize Model button in the lower-left corner of filter designer.
Select the desired optimizations in the Optimization region of the Realize Model pane. See the following descriptions and illustrations of each optimization option.
Optimize for zero gains — Remove zero-gain paths.
Optimize for unity gains — Substitute gains equal to one with a wire (short circuit).
Optimize for negative gains — Substitute gains
-1 with a wire (short circuit), and change the corresponding
sums to subtractions.
Optimize delay chains — Substitute any delay chain made up of n unit delays with a single delay by n.
Optimize for unity scale values — Remove all scale value multiplications by 1 from the filter structure.
The following diagram illustrates the results of each of these optimizations.