线性相位FIR陷波滤波器和IIR陷波滤波器

时间:2014-03-20 04:19:33

标签: digital-filter

我希望借助Matlab中的线性相位FIR陷波滤波器和IIR陷波滤波器来隔离基频。谁能告诉我怎么做?我知道我必须将陷波频率设置为基频。但是无法理解如何在MATLAB上实现。

2 个答案:

答案 0 :(得分:1)

你需要知道的事情。 采样率。 您希望隔离的基本频率。 FIR滤波器基本和您想要的顺序。 我建议制作带阻滤波器,带有一个薄的阻带。 阻带频率fc1和fc2。 然后使用下面的代码。

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

现在d是滤波器系数。 你的过滤器是

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

在此之后,您需要使用系数' d'设计的过滤器过滤输入。 所以

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

答案 1 :(得分:1)

这是您想要使用的一个IIR缺口代码。

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);
相关问题