Main Content

Tunable Lowpass FIR Filter

Design lowpass FIR filter with tunable filter specifications

Since R2023b

  • Tunable Lowpass FIR Filter block icon

Libraries:
DSP System Toolbox / Filtering / Filter Sources

Description

Use the Tunable Lowpass FIR Filter block to design a lowpass FIR filter using the Hann, Hamming, Blackman, Blackman-Harris, Chebyshev, and Kaiser windowing methods. You can tune the filter order, filter cutoff frequency, and the sidelobe attenuation while the simulation is running. When the values of these parameters change, the block redesigns the filter and outputs the numerator coefficients in vector form.

Examples

expand all

Vary the order and the cutoff frequency of the lowpass FIR filter during simulation. Design the filter every time the frequency specifications update. Visualize the magnitude response of this varying filter.

Pass a noisy sinusoidal signal through the lowpass FIR filter. Visualize the frequency spectra of the input and the output signals.

Open and Inspect Model

Open the tunable_lowpass_filter model by clicking the Open Model button.

The input signal in the model is a sum of two sine waves with the frequencies of 1 kHz and 15 kHz. The Random Source block adds zero-mean white Gaussian noise with a variance of 0.05 to the sum of sine waves.

The Tunable Lowpass FIR Filter block designs the filter and the Discrete FIR Filter block implements the filter. The filter order and the filter cutoff frequency specifications are input through the input ports of the Tunable Lowpass FIR Filter block.

Run Model

Visualize the spectra of the original signal and the filtered signal in the Spectrum Analyzer. The second tone at 15 kHz is attenuated since it falls in the stopband region of the filter.

Tune the Filter Order and Filter Cutoff Frequency

Change the filter order to 90 and the filter cutoff frequency to 0.7 during simulation. You can see the magnitude response of the filter change in the Filter Visualizer output. Also, the second tone at 15 kHz is now unaffected since it falls in the passband region of the filter.

Ports

Input

expand all

Specify the filter order as an even positive integer less than or equal to Nmax, where Nmax is the value you specify in the Filter maximum order (must be even) parameter. You can change the filter order you input through this port during simulation.

Dependencies

To enable this port, select the Specify filter order from input port parameter.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Specify the cutoff frequency of the filter in the normalized frequency units as a positive scalar less than or equal to 1. You can change the cutoff frequency you input through this port during simulation.

Dependencies

To enable this port, select the Specify cutoff frequency from input port parameter.

Data Types: single | double

Specify the sidelobe attenuation of the Chebyshev type filter as a positive scalar in dB. You can change the sidelobe attenuation you input through this port during simulation.

Dependencies

To enable this port:

  • Set the Window function parameter to Chebyshev.

  • Select the Specify sidelobe attenuation from input port parameter.

Data Types: single | double

Specify the Kaiser window parameter as a nonnegative scalar. You can change the Kaiser window parameter you input through this port during simulation.

Dependencies

To enable this port:

  • Set the Window function parameter to Kaiser.

  • Select the Specify kaiser window parameter from input port parameter.

Data Types: single | double

Output

expand all

Numerator coefficients, returned as a row vector of length Nmax + 1, where Nmax is the maximum filter order that you specify using the Filter maximum order (must be even) parameter.

This equation represents the vector of numerator coefficients b.

b=[b0,b1,b2,...,bNmax]

This equation represents the FIR filter in the transfer function form.

H(z)=b0+b1z1+b2z2+...+bNmaxzNmax

When the actual filter order N is less than the maximum filter order Nmax, the last NmaxN elements in the numerator coefficients vector are trivial with a value of 0.

The data type of this port depends on the value of the Output data type parameter.

Data Types: single | double

Parameters

expand all

Select this parameter to specify the filter order from the input port N. When you clear this parameter, you can specify the filter order in the block dialog box using the Filter order (must be even) parameter.

Specify the filter order as an even positive integer that is less than or equal to the value of the Filter maximum order (must be even) parameter.

Tunable: Yes

Dependencies

To enable this parameter, clear the Specify filter order from input port parameter.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Specify the maximum order of the filter as an even positive integer. The value you specify in the Filter order (must be even) parameter must be less than or equal to the value you specify in the Filter maximum order (must be even) parameter.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Select this parameter to specify the filter cutoff frequency from the input port Fcut. When you clear this parameter, you can specify the cutoff frequency in the block dialog box using the Cutoff frequency parameter.

Specify the cutoff frequency of the filter in the normalized frequency units as a positive scalar less than or equal to 1.

Tunable: Yes

Dependencies

To enable this parameter, clear the Specify cutoff frequency from input port parameter.

Data Types: single | double

Specify the window function to use to design the filter:

  • Hann

  • Hamming

  • Blackman

  • Blackman-Harris

  • Chebyshev

  • Kaiser

Select this parameter to specify the sidelobe attenuation from the input port r. When you clear this parameter, you can specify the sidelobe attenuation in the block dialog box using the Sidelobe attenuation (dB) parameter.

Dependencies

To enable this parameter, set the Window function parameter to Chebyshev.

Specify the sidelobe attenuation of the Chebyshev type FIR filter as a positive scalar in dB.

Tunable: Yes

Dependencies

To enable this parameter:

  • Set the Window function parameter to Chebyshev.

  • Clear the Specify sidelobe attenuation from input port parameter.

Data Types: single | double

Select this parameter to specify the Kaiser window parameter from the input port beta. When you clear this parameter, you can specify the Kaiser window parameter in the block dialog box using Kaiser window parameter.

Dependencies

To enable this parameter, set the Window function parameter to Kaiser.

Specify the Kaiser window parameter as a nonnegative scalar.

Tunable: Yes

Dependencies

To enable this parameter:

  • Set the Window function parameter to Kaiser.

  • Clear the Specify kaiser window parameter from input port parameter.

Data Types: single | double

Specify the sample time as -1 (inherited), Inf (constant sample time), or a positive scalar. This parameter determines when the block produces the output and updates its internal state during simulation. For more details, see What Is Sample Time? (Simulink).

Data Types: single | double

Specify the data type of the filter coefficients that the block outputs through the Num port. You can set the data type to double or single.

Specify the type of simulation to run as one of the following:

  • Code generation –– Simulate model using generated C code. The first time you run a simulation, Simulink® generates C code for the block. Simulink reuses the C code in subsequent simulations as long as the model does not change. This option requires additional startup time but subsequent simulations are faster compared to Interpreted execution.

  • Interpreted execution –– Simulate model using the MATLAB®  interpreter. This option shortens startup time but subsequent simulations are slower compared to Code generation.

Block Characteristics

Data Types

double | integer | single

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

Extended Capabilities

Version History

Introduced in R2023b