# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# dsp.NotchPeakFilter System object

Package: dsp

Second-order tunable notching and peaking IIR filter

## Description

The `NotchPeakFilter` object filters each channel of the input using IIR filter implementation.

To filter each channel of the input:

1. Define and set up your NotchPeak filter. See Construction.

2. Call `step` to filter each channel of the input according to the properties of `dsp.NotchPeakFilter`. The behavior of `step` is specific to each object in the toolbox.

 Note:   Starting in R2016b, instead of using the `step` method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, ```y = step(obj,x)``` and `y = obj(x)` perform equivalent operations.

## Construction

`npFilter = dsp.NotchPeakFilter` returns a second-order notching and peaking IIR filter which independently filters each channel of the input over time, using a specified center frequency and 3 dB bandwidth. Both of these properties are specified in Hz and are tunable. Both of these values must be scalars between `0` and half the sample rate.

```npFilter = dsp.NotchPeakFilter('PropertyName',PropertyValue, ...)``` returns a notch filter with each specified property name set to the specified value. You can specify additional name-value pair arguments in any order as `(Name1,Value1,...,NameN,ValueN)`.

```npFilter = dsp.NotchPeakFilter('specification','Quality factor and center frequency')``` specifies the quality factor (Q factor) of the notch or peak filter instead of the `3` dB bandwidth. The Q factor is defined as the center frequency divided by the bandwidth. A higher Q factor corresponds to a narrower notch or peak. The Q factor should be a scalar value greater than 0. The Q factor is tunable.

`npFilter = dsp.NotchPeakFilter('Specification','Coefficients')` specifies the coefficient values that affect bandwidth and center frequency directly, rather than specifying the design parameters in Hz. This removes the trigonometry calculations involved when the properties are tuned. The `CenterFrequencyCoefficients` should be a scalar between `-1` and `1`, with `-1` corresponding to `0` Hz and `1` corresponding to the Nyquist frequency. The `BandwidthCoefficient` should be a scalar between `-1` and `1`, with `-1` corresponding to the largest `3` dB bandwidth and `1` corresponding to the smallest `3` dB bandwidth. Both coefficient values are tunable.

## Properties

 `Specification` Filter specification Set the specification as one of ```'Bandwidth and center frequency'``` | `'Quality factor and center frequency'` | `'Coefficients'`. The default is `'Bandwidth and center frequency'`. `Bandwidth` 3 dB bandwidth Specify the filter's `3` dB bandwidth as a finite positive numeric scalar in Hertz. This property is applicable only if `specification` is ```'Bandwidth and center frequency'```. The default is `2205` Hz. This property is tunable. `CenterFrequency` Notch or Peak center frequency Specify the filter's center frequency (for both the notch and the peak) as a finite positive numeric scalar in Hertz. This property is applicable only if `specification` is ```'Bandwidth and center frequency'``` | ```'Quality factor and center frequency'```. The default is `11025` Hz. This property is tunable. `QualityFactor` Quality factor for notch or peak filter Specify the quality factor (Q factor) for both the notch and the peak filters. The Q factor is defined as the center frequency divided by the bandwidth. This property is applicable only if `specification` is set to `'Quality factor and center frequency'`. The default value is `5`. This property is tunable. `SampleRate` Sample rate of input Specify the sample rate of the input in Hertz as a finite numeric scalar. The default is `44100` Hz. `BandwidthCoefficient` Bandwidth coefficient Specify the value that determines the filter's `3` dB bandwidth as a finite numeric scalar in the range `[-1 1]`. Where `-1` corresponds to the maximum `3` dB bandwidth (SampleRate/4), and `1` corresponds to the minimum `3` dB bandwidth (0 Hz, an allpass filter). The default is `0.72654`. This property is only applicable if `specification` is set to `'Coefficients'`. This property is tunable. `CenterFrequencyCoefficient` Center frequency coefficient Specify the coefficient that determines the filter's center frequency as a finite numeric scalar between `-1` and `1`. Where `-1` corresponds to the minimum center frequency (0 Hz), and 1 corresponds to the maximum center frequency (`SampleRate/2` Hz). This property is only applicable if `specification` is set to `'Coefficients'`. The default is 0 which corresponds to` SampleRate/4` Hz. This property is tunable.

## Methods

 getBandwidth Get 3 dB bandwidth getCenterFrequency Get center frequency getOctaveBandwidth Bandwidth in number of octaves getQualityFactor Get quality factor reset Reset the internal states of notch or peak filter step Process input using the notch or peak filter algorithm tf Transfer function
Common to All System Objects
`clone`

Create System object with same property values

`getNumInputs`

Expected number of inputs to a System object

`getNumOutputs`

Expected number of outputs of a System object

`isLocked`

Check locked states of a System object (logical)

`release`

Allow System object property value changes

## Examples

expand all

This example shows how to use dsp.NotchPeakFilter as a notch filter with center frequency of 5000 Hz and a 3 dB bandwidth of 500 Hz.

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent `step` syntax. For example, myObject(x) becomes step(myObject,x).

```npFilter = dsp.NotchPeakFilter('CenterFrequency',5000,'Bandwidth',500); sa = dsp.SpectrumAnalyzer('SampleRate',44100,... 'PlotAsTwoSidedSpectrum',false,'SpectralAverages',50); for i=1:5000 y = npFilter(randn(1024,1)); sa(y); if (i==2500) % Tune center frequency to 10000 npFilter.CenterFrequency = 10000; end end release(npFilter) release(sa) ```

## Algorithms

The design equations for this filter are:

`$H\left(z\right)=\left(1-b\right)\frac{1-{z}^{-2}}{1-2b\mathrm{cos}{w}_{0}{z}^{-1}+\left(2b-1\right){z}^{-2}}$`

The previous equation is for peak filter, and the following equation is for notch filter.

`$H\left(z\right)=b\frac{1-2\mathrm{cos}{w}_{0}{z}^{-1}+{z}^{-2}}{1-2b\mathrm{cos}{w}_{0}{z}^{-1}+\left(2b-1\right){z}^{-2}}$`

With

`$b=\frac{1}{1+\mathrm{tan}\left(\Delta w/2\right)}$`

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:

The filter is implemented as follows:

where

`$\begin{array}{l}{G}_{3dB}={a}_{2}=2b-1\\ {G}_{cf}=\frac{{a}_{1}-{a}_{1}{a}_{2}}{1-{a}_{2}{}^{2}}=-\mathrm{cos}{w}_{0}\end{array}$`

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.