# linear phase notch filter matlab

I need to filter 9 Hz from a signal sampled by 256 Hz using a linear phase filter.

If someone can bring an explanation or a code example I would greatly appreciate it.

I have tested his code

function [Hd1,Hd2]=NotchFIR(FS,F0,FG,FGAINdB) % Design
if (F0 > FS/2)
warnstr =['WARNING! The Sampling frequency is less than twice the notch frequency. Response will be inaccurate.']
end
if (FG == F0)
warnstr =['WARNING! User should not set the gain of the notch frequency. Response will be inaccurate.']
end
FGAIN = 10^(FGAINdB/20);
w0 = 2*pi*F0/FS;
wg = 2*pi*FG/FS;
GH = abs(1 - 2*cos(w0)*exp(-j*wg) + exp(-j*2*wg));
G = FGAIN/GH;
h = [1 -2*cos(w0) 1];
freqz(G*h,100,[], FS);
Hd1=G*h;
Hd2=100; end

t=0:1/256:1;
y=sin(2*pi*9*t);    [Hd1,Hd2]=NotchFIR(256,8.9,9.1,1)
x=filter(Hd1,Hd2,y);
figure
plot(t,x);


But the frequency response of the digital filter shows that the selection of the notch frequency wasn't sharp and many frequencies were attenuated.

• So, what exactly is your question that we can answer? Please edit your question to actually include a question sentence, and explain what you've researched and got in trouble with! Dec 11 '16 at 14:04
• You need to design a finite impulse response (FIR) notch filter where the center of the notch (also called "stopband") is nine Hz. Measured in Hz, what is the width of your desired notch? Measured in decibels (dB), what is the desired notch attenuation? Measured in dB, what is the allowable passband peak-to-peak ripple? Dec 11 '16 at 15:16
• - The bandwidth must be tight, 8.9Hz ~ 9.1Hz should be fine. - 80 dB attenuation - 0.01 dB peak-to-peak ripple , thank you
– omar
Dec 11 '16 at 21:25
• I have tested this code but the result was not satisfactory : 'Sr=256; fdfr1=8.9; fdfr2=9.1; fc1 = fdfr1/Sr; fc2 = fdfr2/Sr; N = 10; % taps n = -(N/2):(N/2); % order filter n = n+(n==0)*eps; [h] = sin(n*2*pifc1)./(npi) - sin(n*2*pifc2)./(npi); [w] = 0.54 + 0.46*cos(2*pi*n/N); % window for betterment d = h.*w; % better coefficients freqz(d); % use this command to see frequency response t=0:1/256:1; X=sin(2*pi*9*t); y = filter(d,1,X) % X is input, y is filtered output figure plot(t,y);'
– omar
Dec 12 '16 at 10:54