如何利用窗函数设计fir滤波器

职业培训 培训职业 2025-01-04
Matlab中,函数fir1()和fir2()利用加窗傅里叶级数法设计FIR滤波器。函数fir1()用来设计传统的LP(低通)、HP(高通)、BP(带通)、BS(带阻)和多频带FIR滤波器;而函数fir2()用来设计具有任意幅度响应的的FIR滤波器。一、函数fir1的各种形式如下: b = fir1(N,Wn)

Matlab中,函数fir1()和fir2()利用加窗傅里叶级数法设计FIR滤波器。函数fir1()用来设计传统的LP(低通)、HP(高通)、BP(带通)、BS(带阻)和多频带FIR滤波器;而函数fir2()用来设计具有任意幅度响应的的FIR滤波器。

一、函数fir1的各种形式如下:

b = fir1(N,Wn)

b = fir1(N,Wn,'ftype')

b = fir1(N,Wn,window)

b = fir1(N,Wn,'ftype',window)

b = fir1(...,'normalization')

其中,1、N为滤波器节点个数;

2、Wn(0<Wn<1)为归一化截止频率;

3、ftype为滤波器类型(默认(缺省时)是low):

'high' for a highpass filter with cutoff frequency Wn.

'stop' for a bandstop filter, if Wn = [w1 w2]. The stopband frequency range is specified by this interval.

'DC-1' to make the first band of a multiband filter a passband.

'DC-0' to make the first band of a multiband filter a stopband.

4、window为所加窗的类型(默认的是hamming窗),e.g hamming、chebwin、blackman、hanning、kaiser等。

5、normalization为是否将滤波器的幅度进行归一化:

f is a vector of frequency points in the range from 0 to 1, where 1 corresponds to the Nyquist frequency.The frequency points must be in increasing order.

m is a vector containing the desired magnitude response at the points specified in f.

Duplicate frequency points are allowed, corresponding to steps in the frequency response.

'scale' (default): Normalize the filter so that the magnitude response of the filter at the center frequency of the passband is 0 dB.

'noscale': Do not normalize the filter.

fir1()举例:设计一个低通滤波器

t = 0:0.01:2;

f =2*sin(2*pi*20*t)+4*sin(2*pi*60*t);

N = 11; %滤波器节点个数

wc = 0.5; %归一化截止频率

hd = fir1(N,wc,'low'); % 基于加窗函数的FIR滤波器设计

ft = conv(f,hd);

figure(1)

plot(abs(fft(f)));

title('原始信号f');

figure(2)

plot(abs(fft(ft)));

title('滤波后信号ft');

二、函数fir2的各种形式如下:

b = fir2(n,f,m)

b = fir2(n,f,m,window)

b = fir2(n,f,m,npt)

b = fir2(n,f,m,npt,window)

b = fir2(n,f,m,npt,lap)

b = fir2(n,f,m,npt,lap,window)

其中,向量f是指定频率点的幅度响应样本,与m定义的幅度响应样本对应;f和m具有相同的长度,并且f的第一个和最后一个分量分别是0和1;可以对f中的频点进行复制,从而跳变地逼近幅度响应指标。

npt指定了函数fir2()进行内插得频率响应的栅格点数目,默认值为512。

lap指定了在f中重复频率点间插入的区域大小。

举例:设计一个30阶的低通滤波器

f = [0 0.6 0.6 1]; m = [1 1 0 0];

b = fir2(30,f,m);

[h,w] = freqz(b,1,128);

plot(f,m,w/pi,abs(h))

legend('Ideal','fir2 Designed')

title('Comparison of Frequency Response Magnitudes')

标签

版权声明:本文由哟品培原创或收集发布,如需转载请注明出处。

本文链接:http://www.yopinpei.com/20250104/2/1176187

猜你喜欢
其他标签