Main Content

Bandstop FIR Filter Design

Design bandstop FIR filter with tunable filter specifications

Since R2023b

  • Bandstop FIR Filter Design block icon

Libraries:
DSP System Toolbox / Filtering / Filter Sources

Description

Use the Bandstop FIR Filter Design block to design a bandstop FIR filter using the Hann, Hamming, Blackman, Blackman-Harris, Chebyshev, and Kaiser windowing methods. You can tune the filter order, center frequency, bandwidth, and the sidelobe attenuation during simulation. 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 bandwidth of the bandstop 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 bandstop FIR filter. Visualize the frequency spectra of the input and the output signals.

Open and Inspect Model

Open the tunable_bandstop_filter model.

The input signal in the model is a sum of two sine waves with the frequencies of 3 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 Bandstop FIR Filter Design block designs the filter and the Discrete FIR Filter block implements the filter. The filter order and the filter bandwidth specifications are input through the input ports of the Bandstop FIR Filter Design block.

Run Model

Visualize the spectra of the original signal and the filtered signal in the Spectrum Analyzer. Both the input tones are unaffected since the frequencies fall in the passband region of the filter.

Tune the Filter Order and Filter Bandwidth

Change the filter order to 90 and the filter bandwidth to 0.5 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 Bandstop 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 bandwidth, you can see the magnitude response of the filter change in the Filter Visualizer output. The second tone at 15 kHz is now attenuated as it falls outside 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.

Dependency

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 center frequency of the filter in the normalized frequency units as a positive scalar less than or equal to 1. You can change the center frequency you input through this port during simulation.

Dependency

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

Data Types: single | double

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

Dependency

To enable this port, select the Specify bandwidth 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.

Dependency

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.

Dependency

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 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

Since R2024a

When you select this check box, the block updates the tunable filter parameters such as the filter order, center frequency, bandwidth, 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.

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.

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

Dependency

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 center frequency from the input port Fc. When you clear this parameter, you can specify the center frequency in the block dialog box using the Center frequency parameter.

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

Tunable: Yes

Dependency

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

Data Types: single | double

Select this parameter to specify the bandwidth from the input port BW. When you clear this parameter, you can specify the bandwidth in the block dialog box using the Bandwidth parameter.

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

Tunable: Yes

Dependency

To enable this parameter, clear the Specify bandwidth 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.

Dependency

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

Dependency

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.

Dependency

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

Specify the Kaiser window parameter as a nonnegative scalar.

Tunable: Yes

Dependency

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. 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

double | integer | single

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

More About

expand all

Extended Capabilities

Version History

Introduced in R2023b

expand all