From: mark sam on
Hi
I try to design a 60Hz digital notch filter with 120kHz sampling rate.
The z transform function is:
hd= (0.9986 z^2 - 1.997 z + 0.9986)/( z^2 - 1.997 z + 0.9971)

After that I run following:
t=0:ts:0.09
in=sin(60*2*pi*t);
lsim(hd,'b',in,t);

In time domain, it shows perfect result that 60Hz signal gets removed. With bode(hd), the it has correct frequency response in frequency domain too.

But furthermore, when I run following, the filter output 60hz signal is as big as half of the 1V 60Hz input signal. This is very confused.

Ts=1/120000;
t=0:Ts:0.05;
ypd=[0;0]
ynotch=[0;0]
wu=2*pi*60;
u=sin(wu*t) %input sig
for n = 2:0.05/Ts
ypd(n+1)=u(n);
ynotch(n+1)=1.997*ynotch(n)-0.9871*ynotch(n-1)+0.9986*ypd(n+1)-1.997*ypd(n)+0.9986*ypd(n-1);
end
plot(t,u,t,ynotch);

Thank you for help,
Mark