(3 votes, average: 5.00 out of 5)

# Digital Notch filter

by on July 14, 2013

In some designs, it may be required to have a digital filter which attenuates a single frequency component with the rest of the frequencies pass through. Filtering out of the power line frequency of 50/60Hz or filtering of spurious correlated frequency signals in a wireless communication receivers etc are some possible scenarios. Such filters are called notch filters and this post goes over the digital notch filter described in the paper  ”Design of Digital Notch Filters,”  by Hirano, K.; Nishimura, S.; Mitra, S.K., in Communications, IEEE Transactions on , vol.22, no.7, pp.964,970, Jul 1974

## Filter Design

The transfer function of an analog notch filter is

$H(s) = \frac{s^2+\lambda^2}{s^2+bs+\lambda^2}$ , where

$\omega=\lambda$ is the notch frequency and

$b$ is the width of the notch.

Converting to a digital filter using bilinear transformation,

$s=\frac{z-1}{z+1}$

$\begin{array}{lll}G(z)&=&H(s)|_{s=\frac{z-1}{z+1}}\\&=&\frac{z^2-2z+1+\lambda^2z^2+2\lambda^2z+\lambda^2}{z^2-2z+1+bz^2-b+\lambda^2z^2+2\lambda^2z+\lambda^2}\\&=&\frac{(1+\lambda^2)-2(1-\lambda^2)z^{-1}+(1+\lambda^2)z^{-2}}{(1+\lambda^2+b)-2(1-\lambda^2)z^{-1}+(1+\lambda^2-b)z^{-2}}\end{array}$.

Let $z=\exp$$j\omega t$$$

$\begin{array}{lll}G(\exp$$j\omega t$$)&=&\frac{(1+\lambda^2)-2(1-\lambda^2)\exp$$-j\omega t$$+(1+\lambda^2)\exp$$-2j\omega t$$}{(1+\lambda^2+b)-2(1-\lambda^2)\exp$$-j\omega t$$+(1+\lambda^2-b)\exp$$-2j\omega t$$}\\&=&\frac{(1+\lambda^2)\exp$$j\omega t$$-2(1-\lambda^2)+(1+\lambda^2)\exp$$-j\omega t$$}{(1+\lambda^2+b)\exp$$j\omega t$$-2(1-\lambda^2)+(1+\lambda^2-b)\exp$$-j\omega t$$}\\\\&=&\frac{(1+\lambda^2)2\cos$$\omega t$$-2(1-\lambda^2)}{(1+\lambda^2)2\cos$$\omega t$$-2(1-\lambda^2)+2b\sin$$\omega t$$}\end{array}$.

where.

$\cos(\omega t)=\frac{\exp(j\omega t)+\exp(-j\omega t)}{2}$

$\sin(\omega t)=\frac{\exp(j\omega t)-\exp(-j\omega t)}{2}$

Summarizing,

$\Large{\begin{array}{lll}G(\exp$$j\omega t$$)&=&\frac{(1+\lambda^2)\cos$$\omega t$$-(1-\lambda^2)}{(1+\lambda^2)\cos$$\omega t$$-(1-\lambda^2)+b\sin$$\omega t$$}\end{array}}$

To find the frequency $\omega_0$ where the response becomes zero

$\begin{array}{lll}\|G(\exp$$j\omega_0 t$$)\|^2&=&0\\\|\frac{(1+\lambda^2)\cos$$\omega_0 t$$-(1-\lambda^2)}{(1+\lambda^2)\cos$$\omega_0 t$$-(1-\lambda^2)+b\sin$$\omega_0 t$$}\|^2&=&0\$$1+\lambda^2)\cos\(\omega_0 t$$-(1-\lambda^2)&=&0\\\cos$$\omega_0 t$$&=&\frac{(1-\lambda^2)}{(1+\lambda^2)}\end{array}$.

Re-arranging and representing in terms of $\lambda$,

$\begin{array}{lll}\lambda^2&=&\frac{1-\cos$$\omega_0 t$$}{1+\cos$$\omega_0 t$$}\\&=&\tan^2$$\omega_0t/2$$\end{array}$.

The value is,

$\Large{\begin{array}{lll}\lambda&=&\tan$$\omega_0t/2$$\end{array}}$.

To find the -3dB bandwidth frequency $\Delta$

$\begin{array}{lll}\|G(\exp$$j\omega t$$)\|^2&=&\frac{1}{2}\\\|\frac{(1+\lambda^2)\cos$$\omega t$$-(1-\lambda^2)}{(1+\lambda^2)\cos$$\omega t$$-(1-\lambda^2)+b\sin$$\omega t$$}\|^2&=&\frac{1}{2}\$$1+\lambda^2)\cos\(\omega t$$-(1-\lambda^2)&=&b\sin$$\omega t$$\end{array}$.

After some math**,

$\begin{array}{lll}\cos$$\Delta t$$&=&\cos$$\omega_2 - \omega_1 t$$&=&\frac{(1+\lambda^2)^2-b^2}{(1+\lambda^2)^2+b^2}\end{array}$

** Note : Did not figure out the math.

Re-arranging and representing in terms of $b$,

$\begin{array}{lll}b^2&=&$$1+\lambda^2$$^2\frac{$$1-\cos\(\Delta t$$\)}{$$1+\cos\(\Delta t$$\)}\\&=&$$1+\lambda^2$$^2\tan^2$$\Delta t/2$$\end{array}$.

The value is,

$\Large{\begin{array}{lll}b&=&$$1+\lambda^2$$\tan$$\Delta t/2$$\end{array}}$.

## Representing as an All-Pass structure

The transfer function $G(z)$ represented with $\lambda$ and $b$ is,

$\begin{array}{lll}G(z)&=&\frac{(1+\lambda^2)-2(1-\lambda^2)z^{-1}+(1+\lambda^2)z^{-2}}{(1+\lambda^2+b)-2(1-\lambda^2)z^{-1}+(1+\lambda^2-b)z^{-2}}\end{array}$.

This can be alternately represented as,

$\begin{array}{lll}G(z)&=&\frac{1}{2}\frac{(1+a_2)-2a_1z^{-1}+(1+a_2)z^{-2}}{1-a_1z^{-1}+a_2z^{-2}}\end{array}$,

where

$\begin{array}a_1&=&\frac{2$$1-\lambda^2$$}{1+\lambda^2+b}\\a_2&=&\frac{$$1+\lambda^2-b$$}{1+\lambda^2+b}\end{array}$

Re-arranging,

$\Huge{\begin{array}{lll}G(z)&=&\frac{1}{2}$$1+\underbrace{\frac{z^{-2}-a_1z^{-1}+a_2}{1-a_1z^{-1}+a_2z^{-2}}}_{\mbox{all pass}}$$\end{array}}$,

Replacing $\lambda$ and $b$,

$\begin{array}{lll}a_1&=&$$1+a_2)\cos(\omega_0t$$\\a_2&=&\frac{1-\tan$$\Delta t/2$$}{1+\tan$$\Delta t/2$$}\end{array}$

Block diagram

Multiple structures to implement the above equation is possible. One possible candidate having two delay elements and two multipliers is shown below.

Figure : Block diagram notch filter (Reference Figure 3(a) Hirano, K.; Nishimura, S.; Mitra, S.K., “Design of Digital Notch Filters,” Communications, IEEE Transactions on , vol.22, no.7, pp.964,970, Jul 1974)

Matab code

% Matlab code for plotting the frequency response of digital notch filter
% Implemented as all pass filter section
clear; close all
fs = 1e6;
fn = 200e3;
fb = 50e3;
omega0T = fn/(fs/2)*pi;
deltaT  = fb/(fs/2)*pi;
a2 = (1-tan(deltaT/2))./(1+tan(deltaT/2));
a1 = (1+a2).*cos(omega0T);
B = [1 -a1 a2];
A = [a2 -a1 1];
[H1 W1] = freqz(B,A,1024,'whole');
[H2 W2] = freqz(1,1,1024,'whole');
H3 = (H1+H2)/2;

h = figure(1);
subplot(2,1,1);
plot([-512:511]/1024*fs/1e6,20*log10(fftshift(abs(H3))),'b-','LineWidth',4);
grid on; ylabel('amplitude, dB');
title('notch filter, fs=1MHz, fn=200kHz, fb=50kHz');
axis([-0.5 0.5 -50 10]);
subplot(2,1,2);
plot([-512:511]/1024*fs/1e6,(fftshift(angle(H3)*180/pi)),'m-','LineWidth',4);
grid on; xlabel('freq, MHz'); ylabel('angle, deg');
title('phase response');
axis([-0.5 0.5 -180 180]);

Figure  : Notch filter – frequency and phase response

## Reference

Hirano, K.; Nishimura, S.; Mitra, S.K., “Design of Digital Notch Filters,” Communications, IEEE Transactions on , vol.22, no.7, pp.964,970, Jul 1974
doi: 10.1109/TCOM.1974.1092311
URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=1092311&isnumber=23820

D id you like this article? Make sure that you do not miss a new article by subscribing to RSS feed OR subscribing to e-mail newsletter. Note: Subscribing via e-mail entitles you to download the free e-Book on BER of BPSK/QPSK/16QAM/16PSK in AWGN.

Chien Wang July 15, 2013 at 10:36 am

Hi Krishna,
I enjoyed reading your articles a lot, however, lately I could not see the math equations due to mimetex error, the actual error message is something like “Only dsplog.com may use mimetex…”. I looked up the mimeTeX site and found the following solution:

If you install mimeTeX on one server and try to use it from another, you may instead see messages like

In this case, compile mimetex.cgi with the -DNOREFCHECK switch, e.g.,
cc -DAA -DNOREFCHECK mimetex.c gifsave.c -lm -o mimetex.cgi
and read the -DREFLEVELS=n discussion under compile options.

Please try and update your local mimeTeX server with -DNOREFCHECK, if you intent to us see the math equations.
Thanks and best regards,
Chien

Can you please mail me the screenshot of the error – krishna < $AT$> dsplog.com