Question

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.

Was it helpful?

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

OTHER TIPS

Here is one IIR notch code you would like to use.

fs = 20000;             %#sampling rate
f0 = 50;                %#notch frequency
fn = fs/2;              %#Nyquist frequency
freqRatio = f0/fn;      %#ratio of notch freq. to Nyquist freq.

notchWidth = 0.1;       %#width of the notch

#%Compute zeros
zeros = [exp( sqrt(-1)*pi*freqRatio ), exp( -sqrt(-1)*pi*freqRatio )];

%Compute poles
poles = (1-notchWidth) * zeros;

figure;
zplane(zeros.', poles.');

b = poly( zeros ); %# Get moving average filter coefficients
a = poly( poles ); %# Get autoregressive filter coefficients

figure;
freqz(b,a,32000,fs) % 32000 are the sample numbers

%filter signal x
y = filter(b,a,x);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top