Main Content

Notch-Peak Filter

Design second-order tunable notching and peaking IIR filter

  • Notch-Peak Filter block

Libraries:
DSP System Toolbox / Filtering / Filter Designs

Description

The Notch-Peak 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

expand all

Design and implement a notching and peaking IIR filter using the Notch-Peak 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 notch-peak IIR filter output in the spectrum analyzer.

Open and inspect the NotchPeakFilterUsingTunableCF model by clicking the Open Model button. 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 notch-peak filter. Plot the input and notch-peak 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 notch-peak 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.

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 by clicking the Open Model button. 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 Notch-Peak 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

expand all

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 two-dimensional 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 one-dimensional signal, then it is interpreted as a single channel.

This block supports variable-size input, enabling you to change the channel length during simulation. To enable variable-size 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

expand all

Notch filter output, returned as a vector or a matrix.

Data Types: single | double
Complex Number Support: Yes

Peak filter output, returned as a vector or a matrix.

Data Types: single | double
Complex Number Support: Yes

Parameters

expand all

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 (Hz) 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.

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 (Hz) parameter.

Dependencies

To enable this parameter, set Filter specification to Bandwidth and center frequency.

Specify the 3-dB 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 or Inherit from input port –– The value of the 3-dB 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 3-dB bandwidth is in normalized frequency units. The value must be a positive scalar less than 1.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.

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.

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 or Inherit 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 than 1.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.

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.

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 (one-fourth 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.

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.

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.

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.

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 (Hz). 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.

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.

Since R2024a

Specify the input sample rate using one of these options:

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

  • Use normalized frequency (0 to 1) –– Specify the passband edge and the stopband edge frequencies in normalized frequency units (0 to 1).

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)

Clicking this button opens the filter visualizer and displays the magnitude response of the notch-peak 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 re-create 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.

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

Multidimensional Signals

No

Variable-Size Signals

Yes

Algorithms

The design equation for the peak filter is:

H(z)=(1b)1z212bcosw0z1+(2b1)z2

The design equation for the notch filter is:

H(z)=b12cosw0z1+z212bcosw0z1+(2b1)z2

with

b=11+tan(Δw/2)

where ω0 = 2πf0/fs is the center frequency in radians/sample (f0 is the center frequency in Hz and fs is the sampling frequency in Hz). Δω = 2πΔf/fs is the 3 dB bandwidth in radians/sample (Δf is the 3 dB bandwidth in Hz). Note that the two filters are complementary:

Hnotch(z)+Hpeak(z)=1they can be written as:Hpeak(z)=12[1A(z)]Hnotch(z)=12[1+A(z)]where A(z) is a 2nd order allpass filter.A(z)=a2+a1z1+z21+a1z1+a2z2anda1=2bcosω0a2=2b1

The filter is implemented as follows:

where

G3dB=a2=2b1Gcf=a1a1a21a22=cosw0

Notice that Gcf depends only on the center frequency, and G3dB depends only on the 3 dB bandwidth.

References

[1] Orfanidis, Sophocles J. Introduction to Signal Processing. Upper Saddle River, NJ: Prentice-Hall, 1996.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2015a

expand all