Documentation Center

  • Trial Software
  • Product Updates

Contents

Digital Filter Design Block

Overview of the Digital Filter Design Block

You can use the Digital Filter Design block to design and implement a digital filter. The filter you design can filter single-channel or multichannel signals. The Digital Filter Design block is ideal for simulating the numerical behavior of your filter on a floating-point system, such as a personal computer or DSP chip. You can use the Simulink® Coder™ product to generate C code from your filter block. For more information on generating C code from models, see Understanding Code Generation.

Filter Design and Analysis

You perform all filter design and analysis within the Filter Design and Analysis Tool (FDATool) GUI, which opens when you double-click the Digital Filter Design block. FDATool provides extensive filter design parameters and analysis tools such as pole-zero and impulse response plots.

Filter Implementation

Once you have designed your filter using FDATool, the block automatically realizes the filter using the filter structure you specify. You can then use the block to filter signals in your model. You can also fine-tune the filter by changing the filter specification parameters during a simulation. The outputs of the Digital Filter Design block numerically match the outputs of the DSP System Toolbox™ filter function and the MATLAB® filter function.

Saving, Exporting, and Importing Filters

The Digital Filter Design block allows you to save the filters you design, export filters (to the MATLAB workspace, MAT-files, etc.), and import filters designed elsewhere.

To learn how to save your filter designs, see Saving and Opening Filter Design Sessions in the Signal Processing Toolbox™ documentation. To learn how to import and export your filter designs, see Import and Export Quantized Filters.

    Note:   You can use the Digital Filter Design block to design and implement a filter. To implement a pre-designed filter, use the Digital Filter block. Both blocks implement a filter design in the same manner and have the same behavior during simulation and code generation.

See the Digital Filter Design block reference page for more information. For information on choosing between the Digital Filter Design block and the Filter Realization Wizard, see Select a Filter Design Block.

Select a Filter Design Block

This section explains the similarities and differences between the Digital Filter Design and Filter Realization Wizard blocks.

Similarities

The Digital Filter Design block and Filter Realization Wizard are similar in the following ways:

  • Filter design and analysis options — Both blocks use the Filter Design and Analysis Tool (FDATool) GUI for filter design and analysis.

  • Output values — If the output of both blocks is double-precision floating point, single-precision floating point, or fixed point, the output values of both blocks numerically match the output of the filter method of the dfilt object.

Differences

The Digital Filter Design block and Filter Realization Wizard handle the following things differently:

  • Supported filter structures — Both blocks support many of the same basic filter structures, but the Filter Realization Wizard supports more structures than the Digital Filter Design block. This is because the block can implement filters using Sum, Gain, and Delay blocks. See the Filter Realization Wizard and Digital Filter Design block reference pages for a list of all the structures they support.

  • Data type support — The Filter Realization Wizard block supports single- and double-precision floating-point computation for all filter structures and fixed-point computation for some filter structures. The Digital Filter Design block only supports single- and double-precision floating-point computation.

  • Block versus Wizard — The Digital Filter Design block is the filter itself, but the Filter Realization Wizard block just enables you to create new filters and put them in an existing model. Thus, the Filter Realization Wizard is not a block that processes data in your model, it is a wizard that generates filter blocks (or subsystems) which you can then use to process data in your model.

When to Use Each Block

The following are specific situations where only the Digital Filter Design block or the Filter Realization Wizard is appropriate.

  • Digital Filter Design

    • Use to simulate single- and double-precision floating-point filters.

    • Use to generate highly optimized ANSI® C code that implements floating-point filters for embedded systems.

  • Filter Realization Wizard

    • Use to simulate numerical behavior of fixed-point filters in a DSP chip, a field-programmable gate array (FPGA), or an application-specific integrated circuit (ASIC).

    • Use to simulate single- and double-precision floating-point filters with structures that the Digital Filter Design block does not support.

    • Use to visualize the filter structure, as the block can build the filter from Sum, Gain, and Delay blocks.

    • Use to rapidly generate multiple filter blocks.

See Filter Realization Wizard and the Filter Realization Wizard block reference page for information.

Create a Lowpass Filter in Simulink

You can use the Digital Filter Design block to design and implement a digital FIR or IIR filter. In this topic, you use it to create an FIR lowpass filter:

  1. Open Simulink and create a new model file.

  2. From the DSP System Toolbox Filtering library, and then from the Filter Implementations library, click-and-drag a Digital Filter Design block into your model.

  3. Double-click the Digital Filter Design block.

    The Filter Design and Analysis Tool (FDATool) GUI opens.

  4. Set the parameters as follows, and then click OK:

    • Response Type = Lowpass

    • Design Method = FIR, Equiripple

    • Filter Order = Minimum order

    • Units = Normalized (0 to 1)

    • wpass = 0.2

    • wstop = 0.5

  5. Click Design Filter at the bottom of the GUI to design the filter.

    Your Digital Filter Design block now represents a filter with the parameters you specified.

  6. From the Edit menu, select Convert Structure.

    The Convert Structure dialog box opens.

  7. Select Direct-Form FIR Transposed and click OK.

  8. Rename your block Digital Filter Design - Lowpass.

The Digital Filter Design block now represents a lowpass filter with a Direct-Form FIR Transposed structure. The filter passes all frequencies up to 20% of the Nyquist frequency (half the sampling frequency), and stops frequencies greater than or equal to 50% of the Nyquist frequency as defined by the wpass and wstop parameters. In the next topic, Create a Highpass Filter in Simulink, you use a Digital Filter Design block to create a highpass filter. For more information about implementing a pre-designed filter, see Digital Filter Block.

Create a Highpass Filter in Simulink

In this topic, you create a highpass filter using the Digital Filter Design block:

  1. If the model you created in Create a Lowpass Filter in Simulink is not open on your desktop, you can open an equivalent model by typing

    ex_filter_ex4  

    at the MATLAB command prompt.

  2. From the DSP System Toolbox Filtering library, and then from the Filter Implementations library, click-and-drag a second Digital Filter Design block into your model.

  3. Double-click the Digital Filter Design block.

    The Filter Design and Analysis Tool (FDATool) GUI opens.

  4. Set the parameters as follows:

    • Response Type = Highpass

    • Design Method = FIR, Equiripple

    • Filter Order = Minimum order

    • Units = Normalized (0 to 1)

    • wstop = 0.2

    • wpass = 0.5

  5. Click the Design Filter button at the bottom of the GUI to design the filter.

    Your Digital Filter Design block now represents a filter with the parameters you specified.

  6. In the Edit menu, select Convert Structure.

    The Convert Structure dialog box opens.

  7. Select Direct-Form FIR Transposed and click OK.

  8. Rename your block Digital Filter Design - Highpass .

The block now implements a highpass filter with a direct form FIR transpose structure. The filter passes all frequencies greater than or equal to 50% of the Nyquist frequency (half the sampling frequency), and stops frequencies less than or equal to 20% of the Nyquist frequency as defined by the wpass and wstop parameters. This highpass filter is the opposite of the lowpass filter described in Create a Lowpass Filter in Simulink. The highpass filter passes the frequencies stopped by the lowpass filter, and stops the frequencies passed by the lowpass filter. In the next topic, Filter High-Frequency Noise in Simulink, you use these Digital Filter Design blocks to create a model capable of removing high frequency noise from a signal. For more information about implementing a pre-designed filter, see Digital Filter Block.

Filter High-Frequency Noise in Simulink

In the previous topics, you used Digital Filter Design blocks to create FIR lowpass and highpass filters. In this topic, you use these blocks to build a model that removes high frequency noise from a signal. In this model, you use the highpass filter, which is excited using a uniform random signal, to create high-frequency noise. After you add this noise to a sine wave, you use the lowpass filter to filter out the high-frequency noise:

  1. If the model you created in Create a Highpass Filter in Simulink is not open on your desktop, you can open an equivalent model by typing

    ex_filter_ex5 

    at the MATLAB command prompt.

  2. Click-and-drag the following blocks into your model.

    BlockLibraryQuantity
    Add

    Simulink Math Operations library

    1

    Random Source

    Sources

    1

    Sine Wave

    Sources

    1

    Time Scope

    Sinks

    1

  3. Set the parameters for these blocks as indicated in the following table. Leave the parameters not listed in the table at their default settings.

    Parameter Settings for the Other Blocks

    BlockParameter Setting
    Add
    • Icon shape = rectangular

    • List of signs = ++

    Random Source
    • Source type =  = Uniform

    • Minimum = 0

    • Maximum = 4

    • Sample mode = Discrete

    • Sample time = 1/1000

    • Samples per frame = 50

    Sine Wave
    • Frequency (Hz) = 75

    • Sample time = 1/1000

    • Samples per frame = 50

    Time Scope
    • File > Number of Input Ports > 3

    • File > Configuration ...

      • Open the Visuals:Time Domain Options dialog and set Time span = One frame period

  4. Connect the blocks as shown in the following figure. You might need to resize some of the blocks to accomplish this task.

  5. From the Simulation menu, select Model Configuration Parameters.

    The Configuration Parameters dialog box opens.

  6. In the Solver pane, set the parameters as follows, and then click OK:

    • Start time = 0

    • Stop time = 5

    • Type = Fixed-step

    • Solver = Discrete (no continuous states)

  7. In the model window, from the Simulation menu, choose Run.

    The model simulation begins and the scope displays the three input signals.

  8. After simulation is complete, select View > Legend from the Time Scope menu. The legend appears in the Time Scope window. You can click-and-drag it anywhere on the scope display. To change the channel names, double-click inside the legend and replace the default channel names with the following:

    • Add = Noisy Sine Wave

    • Digital Filter Design – Lowpass = Filtered Noisy Sine Wave

    • Sine Wave = Original Sine Wave

    In the next step, you will set the color, style, and marker of each channel.

  9. In the Time Scope window, select View > Line Properties, and set the following:

    LineStyleMarkerColor
    Noisy Sine Wave - NoneBlack
    Filtered Noisy Sine Wave - diamondRed
    Original Sine Wave None *Blue

  10. The Time Scope display should now appear as follows:

    You can see that the lowpass filter filters out the high-frequency noise in the noisy sine wave.

You have now used Digital Filter Design blocks to build a model that removes high frequency noise from a signal. For more information about these blocks, see the Digital Filter Design block reference page. For information on another block capable of designing and implementing filters, see Filter Realization Wizard. To learn how to save your filter designs, see Saving and Opening Filter Design Sessions in the Signal Processing Toolbox documentation. To learn how to import and export your filter designs, see Import and Export Quantized Filters in the DSP System Toolbox documentation.

Was this topic helpful?