1
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ 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! $\endgroup$ – Marcus Müller Dec 11 '16 at 14:04
  • 1
    $\begingroup$ 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? $\endgroup$ – Richard Lyons Dec 11 '16 at 15:16
  • $\begingroup$ - The bandwidth must be tight, 8.9Hz ~ 9.1Hz should be fine. - 80 dB attenuation - 0.01 dB peak-to-peak ripple , thank you $\endgroup$ – omar Dec 11 '16 at 21:25
  • $\begingroup$ 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);' $\endgroup$ – omar Dec 12 '16 at 10:54
1
$\begingroup$

@omar: I don't know how you obtained your expression for the 'h' coefficients but it's wildly incorrect. Study the MATLAB documentation regarding the 'firpm()' and 'fir1()' filter design commands. Experiment, experiment, and experiment again until you understand those commands. Then when you try to use one of those commands to design your desired filter you'll find that your filter needs a truly HUGE number of taps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.