NotchPeak Filter
Design secondorder tunable notching and peaking IIR filter
Libraries:
DSP System Toolbox /
Filtering /
Filter Designs
Description
The NotchPeak Filter block filters each channel of the input signal over time using a specified center frequency and 3 dB bandwidth. This block offers tunable filter design parameters, which enable you to tune the filter characteristics while the simulation is running. The block designs the filter according to the filter parameters set in the block dialog box. The output port properties such as datatype, complexity, and dimension, are identical to the input port properties.
Examples
Design and Implement NotchPeak IIR Filter with Tunable Center Frequency
Design and implement a notching and peaking IIR filter using the NotchPeak Filter block. Pass a noisy sinusoidal signal through the filter. Tune the center frequency of the filter during simulation. Plot the spectrum of the input and the notchpeak IIR filter output in the spectrum analyzer.
Open and inspect the NotchPeakFilterUsingTunableCF
model. The input signal in the model is a noisy sinusoidal signal with 256 samples per frame and contains two frequencies, one at 3 kHz and the other at 15 kHz. The Random Source block adds white Gaussian noise with a mean of 0 and a variance of 0.05 to this signal. The center frequency of the filter is 3 kHz and is input through the Fc port.
Pass the noisy sinusoidal signal through the notchpeak filter. Plot the input and notchpeak IIR filter output spectrum in the spectrum analyzer.
In the notch filter output, the tone at 3 kHz is attenuated as it coincides with the notch of the filter, while the tone at 15 kHz is unaffected. In the peak filter output, the tone at 3 kHz is unaffected as it coincides with the peak of the filter, while the tone at 15 kHz is attenuated.
Using the manual switch, change the center frequency of the notchpeak IIR filter to 15 kHz. The 15 kHz tone in the notch filter output is attenuated as it coincides with the new notch of the filter, while the tone at 3 kHz is unaffected. In the peak filter output, the tone at 15 kHz coincides with new peak of the filter, and therefore is unaffected, while the tone at 3 kHz is attenuated.
Smooth Tunable Center Frequency of IIR Notch Filter Using Smoothing Factor
Since R2024a
Vary the center frequency of the IIR notch filter. Smooth the center frequency value using the Parameter Smoother block. Note the smoothing behavior of the parameter in the Time Scope when you vary the smoothing factor.
Open the notchFilter_smoothingFactor.slx
model. The input is a noisy sinusoidal signal with a frequency of 2 kHz, sample rate of 44.1 kHz, and contains 1024 samples per frame. Pass this signal through a NotchPeak Filter block. The block outputs the Notch
filter output and accepts the filter center frequency through the input port Fc. The Sample rate mode parameter of the block is set to Use normalized frequency (0 to 1)
. This setting enables the block to accept frequency specifications in normalized units.
Vary the center frequency of the notch between 0.1 and 0.8 using the slider. Smooth the variation of the center frequency using the Parameter Smoother block. When the smoothing factor is 0, no smoothing occurs and the parameter changes abruptly. As the smoothing factor approaches 1, smoothing increases and the parameter changes gradually.
Run the model. The center frequency is 0.1. The frequency tone of the sinusoidal signal falls in the notch of the filter attenuating the signal.
When you change the center frequency to 0.8, with a sample rate of 44.1 kHz, the center of the notch moves to 17.64 kHz and the tone is unaffected.
Vary the smoothing factor between 0.1 and 0.9 and notice the time it takes for the center frequency to change to the new value in each of these cases.
When alpha is 0.1, the parameter takes less than 0.1 seconds to change to its new value.
When alpha is 0.9, the parameter takes around 1 second to change to its new value. This is because a higher smoothing factor changes the parameter more gradually.
Ports
Input
Input — Input signal
vector  matrix
Specify the input signal as a vector or a matrix. Each column of the input signal is treated as a separate channel. If the input is a twodimensional signal, the first dimension represents the channel length (or frame size) and the second dimension represents the number of channels. If the input is a onedimensional signal, then it is interpreted as a single channel.
This block supports variablesize input, enabling you to change the channel length during simulation. To enable variablesize input, clear the Inherit sample rate from input check box. The number of channels must remain constant.
Data Types: single
 double
Complex Number Support: Yes
Output
notch — Notch filter output
vector  matrix
Notch filter output, returned as a vector or a matrix.
Data Types: single
 double
Complex Number Support: Yes
peak — Peak filter output
vector  matrix
Peak filter output, returned as a vector or a matrix.
Data Types: single
 double
Complex Number Support: Yes
Parameters
Filter specification — Filter design specifications
Bandwidth and center
frequency
(default)  Coefficients
 Quality factor and center frequency
Specify the parameter or the coefficients the block uses to design the filter:
Bandwidth and center frequency
(default) — Design the filter using 3 dB bandwidth and Center frequency of notch or peak.Coefficients
— Design the filter using Bandwidth coefficient and Center frequency coefficient.Quality factor and center frequency
— Design the filter using Quality factor and Center frequency of notch or peak.
Specify bandwidth from input port — Option to specify 3 dB bandwidth from input port
off
(default)  on
When you select this check box, the 3 dB bandwidth is input through the BW port. When you clear this check box, the 3 dB bandwidth is specified in the block dialog box through the 3 dB bandwidth parameter.
Dependencies
To enable this parameter, set Filter
specification to Bandwidth and center
frequency
.
3 dB bandwidth — 3dB bandwidth
2205
(default)  positive scalar
Specify the 3dB bandwidth of the filter as a positive scalar in Hz or in normalized frequency units (since R2024a).
If you set the Sample rate mode parameter to:
Specify on dialog
orInherit from input port
–– The value of the 3dB bandwidth is in Hz and must be less than half the sample rate of the input signal.Use normalized frequency (0 to 1)
–– The value of the 3dB bandwidth is in normalized frequency units. The value must be a positive scalar less than1.0
.
(since R2024a)
Tunable: Yes
Dependencies
To enable this parameter, set Filter
specification to Bandwidth and center
frequency
, and clear the Specify bandwidth
from input port parameter.
Specify center frequency from input port — Option to specify center frequency from input port
off
(default)  on
When you select this check box, the center frequency is input through the Fc port. When you clear this check box, the center frequency is specified in the block dialog box through the Center frequency of notch or peak parameter.
Dependencies
To enable this parameter, set Filter
specification to Bandwidth and center
frequency
or Quality factor and center
frequency
.
Center frequency of notch or peak — Notch or peak center frequency
11025
(default)  positive scalar
Specify the center frequency of the notch and peak of the filter as a positive numeric scalar in Hz or in normalized frequency units (since R2024a).
If you set the Sample rate mode parameter to:
Specify on dialog
orInherit from input port
–– The value of the center frequency is in Hz and must be less than half the sample rate of the input signal.Use normalized frequency (0 to 1)
–– The value of the center frequency is in normalized frequency units. The value must be a positive scalar less than1.0
.
(since R2024a)
Tunable: Yes
Dependencies
To enable this parameter, set Filter
specification to Bandwidth and center
frequency
or Quality factor and center
frequency
, and clear the Specify center
frequency from input port parameter.
Specify bandwidth coefficient from input port — Option to specify bandwidth coefficient from input port
off
(default)  on
When you select this check box, the bandwidth coefficient is input through the port, BWCoeff. When you clear this check box, the bandwidth coefficient is specified in the block dialog box through the Bandwidth coefficient parameter.
Dependencies
To enable this parameter, set Filter
specification to
Coefficients
.
Bandwidth coefficient — Bandwidth coefficient
0.72654
(default)  real scalar in the range [−1
1
]
Specify the coefficient that determines the 3 dB bandwidth of the filter
as a finite numeric scalar in the range [−1
1
].
1
corresponds to the maximum 3 dB bandwidth (onefourth the sample rate of the input signal).1
corresponds to the minimum bandwidth (0 Hz, that is, an allpass filter).
Tunable: Yes
Dependencies
To enable this parameter, set Filter
specification to Coefficients
and clear the Specify bandwidth coefficient from input
port parameter.
Specify center frequency coefficient from input port — Option to specify center frequency coefficient from input port
off
(default)  on
When you select this check box, the center frequency coefficient is input through the FcCoeff port. When you clear this check box, the center frequency coefficient is specified in the block dialog box through the Center frequency coefficient parameter.
Dependencies
To enable this parameter, set Filter
specification to
Coefficients
.
Center frequency coefficient — Center frequency coefficient
0
(default)  real scalar in the range [−1
1
]
Specify the coefficient that determines the center frequency of the filter
as a finite numeric scalar in the range [−1
1
].
1
corresponds to the minimum center frequency (0
Hz).1
corresponds to the maximum center frequency (half the sample rate of the input signal).
The default value of 0
corresponds to quarter the
sample rate of the input signal.
Tunable: Yes
Dependencies
To enable this parameter, set Filter
specification to Coefficients
and clear the Specify center frequency coefficient from input
port parameter.
Specify quality factor from input port — Option to specify quality factor from input port
off
(default)  on
When you select this check box, the quality factor is input through the Q port. When you clear this check box, the quality factor is specified in the block dialog box through the Quality factor parameter.
Dependencies
To enable this parameter, set Filter
specification to Quality factor and center
frequency
.
Quality factor — Quality factor for notch or peak filter
5
(default)  positive scalar
Specify the quality factor of the notch and peak filter as a real positive scalar. The quality factor is defined as Center frequency of notch or peak / 3 dB bandwidth. A higher quality factor corresponds to a narrower peak or dip.
Tunable: Yes
Dependencies
To enable this parameter, set Filter
specification to Quality factor and center
frequency
and clear the Specify quality
factor from input port parameter.
Filter output — Filter response to output
Notch and Peak
(default)  Notch
 Peak
Specify the response to output as one of these:
Notch and Peak
— The block outputs the notch and peak responses of the filter.Notch
— The block outputs the notch response of the filter.Peak
— The block outputs the peak response of the filter.
Sample rate mode — Mode to specify the input sample rate
Use normalized frequency (0 to
1)
(default)  Specify on dialog
 Inherit from input port
Since R2024a
Specify the input sample rate using one of these options:
Use normalized frequency (0 to 1)
–– Specify the passband edge and the stopband edge frequencies in normalized frequency units (0 to 1).Specify on dialog
–– Specify the input sample rate in the block dialog box using the Input sample rate (Hz) parameter.Inherit from input port
–– The block inherits the sample rate from the input signal. The block computes the sample rate as N/Ts, where N is the frame size of the input signal and Ts is the sample time of the input signal.
Input sample rate (Hz) — Sample rate of input
44100
(default)  positive scalar
Specify the sample rate of the input signal as a positive scalar value.
Dependencies
To enable this parameter, set:
Filter specification to any accepted value except
Coefficients
.Sample rate mode to
Specify on dialog
. (since R2024a)
View Filter Response — View filter response
button (default)
Clicking this button opens the filter visualizer and displays the magnitude response of the notchpeak filter. The response is based on the parameters you select in the block dialog box. To update the response while the visualizer is running, modify the parameters in the dialog box and click Apply.
You can configure the plot settings and the frequency response measurements from the interface of the visualizer.
On the Scope tab, you can enable the legend, specify to plot both magnitude and phase responses of the filter, modify the plot settings, generate a script to recreate the plot, and even save or share the settings. On the Measurements tab, you can enable data cursors, and display the peak values of the filter response.
For more details on the filter visualizer interface and its tools, see Configure Filter Visualizer.
Dependencies
To enable this button, do not specify any filter specifications from the input port.
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 

Multidimensional Signals 

VariableSize Signals 

Algorithms
The design equation for the peak filter is:
$$H(z)=(1b)\frac{1{z}^{2}}{12b\mathrm{cos}{w}_{0}{z}^{1}+(2b1){z}^{2}}$$
The design equation for the notch filter is:
$$H(z)=b\frac{12\mathrm{cos}{w}_{0}{z}^{1}+{z}^{2}}{12b\mathrm{cos}{w}_{0}{z}^{1}+(2b1){z}^{2}}$$
with
$$b=\frac{1}{1+\mathrm{tan}(\Delta w/2)}$$
where ω_{0} = 2πf_{0}/f_{s} is the center frequency in radians/sample (f_{0} is the center frequency in Hz and f_{s} is the sampling frequency in Hz). Δω = 2πΔf/f_{s} is the 3 dB bandwidth in radians/sample (Δf is the 3 dB bandwidth in Hz). Note that the two filters are complementary:
$$\begin{array}{l}{H}_{\text{notch}}(z)+{H}_{\text{peak}}(z)=1\\ \text{theycanbewrittenas:}\\ {H}_{\text{peak}}(z)=\frac{1}{2}\left[1A(z)\right]\\ {H}_{\text{notch}}(z)=\frac{1}{2}\left[1+A(z)\right]\\ \text{where}A\text{(z)isa}{2}^{\text{nd}}\text{orderallpassfilter}\text{.}\\ A(z)=\frac{{a}_{2}+{a}_{1}{z}^{1}+{z}^{2}}{1+{a}_{1}{z}^{1}+{a}_{2}{z}^{2}}\\ \text{and}\\ {a}_{1}=2b\mathrm{cos}{\omega}_{0}\\ {a}_{2}=2b1\end{array}$$
The filter is implemented as follows:
where
$$\begin{array}{l}{G}_{\text{3dB}}={a}_{2}=2b1\\ {G}_{\text{cf}}=\frac{{a}_{1}{a}_{1}{a}_{2}}{1{a}_{2}{}^{2}}=\mathrm{cos}{w}_{0}\end{array}$$
Notice that G_{cf} depends only on the center frequency, and G_{3dB} depends only on the 3 dB bandwidth.
References
[1] Orfanidis, Sophocles J. Introduction to Signal Processing. Upper Saddle River, NJ: PrenticeHall, 1996.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2015aR2024a: 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.
R2023b: Support for normalized frequencies
When you set the Sample rate mode parameter to
Use normalized frequency (0 to 1)
, you can specify
the 3 dB bandwidth and center frequency in normalized frequency units (0 to
1).
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)