Lowpass FIR Filter Design
Libraries:
DSP System Toolbox /
Filtering /
Filter Sources
Description
Use the Lowpass FIR Filter Design 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
Design and Implement Lowpass Filter with Tunable Frequency Specifications in Simulink
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.
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 Lowpass FIR Filter Design 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 Lowpass FIR Filter Design 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. To change the parameter values more gradually during simulation, select the Smooth tuned filter parameters check box and specify a smoothing factor in the Lowpass FIR Filter Design block dialog box. The smoothing factor determines the speed at which the parameter values change until they match the desired new value. If you specify a smoothing factor of 0, the block does not smooth the parameter and immediately sets the parameter to the new value. As the smoothing factor approaches 1, the number of smoothing operations, and consequently, the number of filter redesigns increase. This example uses a smoothing factor of 0.6.
When you change the filter order and the filter cutoff frequency, you can see the magnitude response of the filter change in the Filter Visualizer output. The second tone at 15 kHz is now unaffected as it falls in the passband region of the filter.
Ports
Input
N — Filter order
even positive integer
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
Fcut — Filter cutoff frequency
positive scalar ≤ 1
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
r — Sidelobe attenuation in dB
positive scalar
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
beta — Kaiser window parameter
nonnegative scalar
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
Num — Numerator coefficients
row vector
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.
This equation represents the FIR filter in the transfer function form.
When the actual filter order N is less than the maximum filter order Nmax, the last Nmax − N 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
Smooth tuned filter parameters — Smooth tuned filter parameters
off
(default) |
on
Since R2024a
When you select this check box, the block updates the tunable filter parameters such as the filter order, cutoff frequency, sidelobe attenuation, and Kaiser window parameter gradually by repeatedly designing the filter with intermediate values of the parameter until the parameter reaches the desired value. This process is called parameter smoothing. For more information, see Parameter Smoothing.
When you clear this check box, the block redesigns the filter with the new parameter value immediately.
Smoothing factor — Smoothing factor
0.6 (default) | nonnegative scalar less than 1
Since R2024a
Specify the smoothing factor α as a nonnegative scalar less than 1. When α = 0, no smoothing occurs. As α approaches 1, the number of smoothing operations, and consequently, the number of filter redesigns increase.
Tunable: Yes
Dependencies
To enable this parameter, select the Smooth tuned filter parameters parameter.
Specify filter order from input port — Flag to specify filter order from input port
off
(default) |
on
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.
Filter order (must be even) — Filter order
100
(default) | even positive integer
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
Filter maximum order (must be even) — Maximum order of filter
100
(default) | even positive integer
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
Specify cutoff frequency from input port — Flag to specify cutoff frequency from input port
off
(default) |
on
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.
Cutoff frequency — Cutoff frequency
0.5
(default) | positive scalar ≤ 1
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
Window function — Window function
Hann
(default) | Hamming
| Blackman
| Blackman-Harris
| Chebyshev
| Kaiser
Specify the window function to use to design the filter:
Hann
Hamming
Blackman
Blackman-Harris
Chebyshev
Kaiser
Specify sidelobe attenuation from input port — Flag to specify sidelobe attenuation from input port
off
(default) |
on
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
.
Sidelobe attenuation (dB) — Sidelobe attenuation in dB
60
(default) | positive scalar
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
Specify kaiser window parameter from input port — Flag to specify Kaiser window parameter from input port
off
(default) |
on
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
.
Kaiser window parameter — Kaiser window parameter
0.5
(default) | nonnegative scalar
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
Sample time (−1 for inherited) — Sample time in seconds
-1
(default) | positive scalar |
Inf
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
Output data type — Data type of filter coefficients
double
(default) |
single
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
.
Simulate using — Type of simulation to run
Interpreted execution
(default) | Code generation
Specify the type of simulation to run. You can set this parameter to:
Interpreted execution
–– Simulate model using the MATLAB® interpreter. This option shortens startup time.Code generation
–– Simulate model using generated C code. The first time you run a simulation, Simulink® generates C code for the block. The C code is reused for subsequent simulations as long as the model does not change. This option requires additional startup time but provides faster subsequent simulations.
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
More About
Parameter Smoothing
Parameter smoothing gradually changes the values of filter parameters until the desired value is reached.
If you select the Smooth tuned filter parameters check box and update the value of tunable filter parameters during simulation, the block repeatedly redesigns the filter with intermediate values of the parameter until the parameter reaches the desired value. The block uses a first-order IIR filter to smooth the parameter.
where:
g[n] is the instantaneous smoothed parameter
t[n] is the discontinuous target parameter
α is the smoothing factor. When α = 0, no smoothing occurs. As α approaches 1, the number of smoothing operations, and consequently, the number of filter redesigns increase.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
When you generate code from this block, you can tune the filter design specifications in the generated code.
Version History
Introduced in R2023bR2024a: Change in the default value of Simulate using parameter
The default value of the Simulate using parameter is now
Interpreted execution
. With this change, the block uses the
MATLAB interpreter for simulation by default.
R2024a: Tunable Lowpass FIR Filter block renamed
The Tunable Lowpass FIR Filter has been renamed as Lowpass FIR Filter Design block.
R2024a: Support for smoothing tunable filter parameters
When tunable filter parameters such as the filter order, cutoff frequency, sidelobe attenuation, and Kaiser window parameter change during simulation, the block can smooth these parameters until the parameters reach the desired value. For more information, see Parameter Smoothing.
See Also
Functions
Blocks
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)