Tunable Lowpass FIR Filter
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
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 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
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
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
Code generation
(default) | Interpreted execution
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 toInterpreted execution
.Interpreted execution
–– Simulate model using the MATLAB® interpreter. This option shortens startup time but subsequent simulations are slower compared toCode generation
.
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
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 R2023b
See Also
Functions
Blocks
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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)