Search code examples
digital-filter

Linear phase FIR notch filter and IIR notch filter


I want to isolate fundamental frequency with the help of a Linear phase FIR notch filter and a IIR notch filter in Matlab. Can anyone tell me how to do that? I know i have to set the notch frequency at fundamental frequency. But cant understand how to implement on MATLAB.


Solution

  • Things you need to know. The sampling rate. The fundamental frequency which you wish to isolate. FIR filter basic and what order do you want. I would suggest making a band stop filter, with a thin stop band. stop band frequencies fc1 and fc2. Then use the code below.

    fc1 = fundamental_freqeuncy1/sampling_rate;
    fc2 = fundamental_freqeuncy2/sampling_rate;
    N = 10; % number of taps you can change
    n = -(N/2):(N/2); % 11 order filter
    n = n+(n==0)*eps;
    [h] = sin(n*2*pi*fc1)./(n*pi) - sin(n*2*pi*fc2)./(n*pi); 
    h(0) =  1 - (2*pi*(fc2-fc1))/pi;
    %coefficient for band stop filter... which could be used % as notch filter
    [w] = 0.54 + 0.46*cos(2*pi*n/N);  % window for betterment 
    d = h.*w;  % better coefficients
    

    Now d are the filter coefficients. and your filter is

    freqz(d); % use this command to see frequency response 
    

    After this you need to filter your input using the filter designed by coefficients 'd'. so

    y = filter(d,1,X) % X is input, y is filtered output