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.
fir2函数可以用于设计有任意频率响应的加窗FIR滤波器,对标准的低通、带通、高通和带阻滤波器的设计可使用fir1函数. b=fir2(n,f,m)可设计出一个n阶的FIR滤波器,其滤波器的频率特性由参数f和m决定.参数f为频率点矢量,且f∈[0,1],f=1对应于0.5fs.矢量f按升序排列,且第一个元素必须是0,最后一个必须为1,并可以包含重复的频率点.矢量m中包含了与f相对应的期望得到的滤波器的幅度.
f为归一化频率向量。
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')
//----------------------------------------------------------------------------------
用fir2设计一个60阶的FIR滤波器,要求滤波器0到π/4的幅度响应为0 ,π/4到π/2的幅度响应为1/4,π/2到3π/4的幅度响应为0,3π/4到1的幅度响应为1。
n=60;
f=[0 0.25 0.25 0.50 0.50 0.75 0.75 1];
m=[0 0 1/4 1/4 0 0 1 1];
%对幅频响应插值时插值点的个数
npt=1024;
%插值时不连续点转变成连续时的点数 lap=50; %衰减为30dB的切比雪夫窗函数
window=chebwin(61,30);
b=fir2(n,f,m,npt,lap,window);