FIR滤波器设计

设计特定频率响应的FIR滤波器

firpm函数:

    firpm使用Parks-McClellan算法设计线性相位FIR滤波器[1]。 Parks-McClellan算法使用Remez交换算法和Chebyshev逼近理论来设计滤波器,使其在期望和实际频率响应之间具有最佳拟合。 在使所需频率响应和实际频率响应之间的最大误差最小的意义上,滤波器是最佳的。 以这种方式设计的滤波器在其频率响应中表现出等波纹特性,有时也称为等波纹滤波器。 由于这种等波纹的性质,firpm在其冲激响应的头部和尾部表现出不连续性。

b = firpm(n,f,a) 返回FIR滤波器的n + 1个系数的行向量b,其频率-振幅特性与向量f和a给出的相匹配。

b中的输出滤波器系数(抽头)服从对称关系:  b(k)= b(n + 2-k),k = 1,...,n + 1

向量f和a指定滤波器的频率幅度特性:

f是一组归一化的频率点的向量,指定在0到1之间的范围内,其中1对应于奈奎斯特频率。 频率必须按升序排列。

a是在f中指定的点处包含所需幅度的向量。f和a的长度必须相同。 长度必须是偶数。

  • 当k是奇数时,在点对(f(k),f(k + 1))之间的频率处的期望幅度是连接点(f(k),a(k))和(f(k + 1),a(k + 1))的直线段。
  • 当k是偶数时,(f(k),f(k + 1))之间的频率之间的期望幅度是不确定的,这些点之间的区域是过渡区域或“无关”区域

下图显示了在定义所需频率响应时f与向量之间的关系。

                          

b = firpm(n,f,a,w)使用向量w中的权重来加权每个频段的拟合度。 w的长度是f和a长度的一半,因此每条带正好有一个权重。

f = [0 0.2 0.5 0.9];
a = [1 1 0 0];
b = firpm(31,f,a);
[h,w] = freqz(b,1,512); %分别系统函数H(z)的分子、分母多项式的系数向量、N个频率等分点的频率响
plot(f,a,w/pi,abs(h));
legend('Ideal','firpm Design')
xlabel 'Radian Frequency (\omega/\pi)', ylabel 'Magnitude'

这里代码里设计了一个0-0.2范围通带,0.5-0.9阻带的低通滤波器,0.2-0.5之间是线性衰减区间(怎么不是过渡区域或“无关”区域??不明白

都知道的内容:衰减越快,则响应函数越起伏,衰减越慢,则响应函数越平稳.

                    

                                                   f = [0 0.2 0.5 1];                                                     f = [0 0.2 0.3 1];

有个疑问:当滤波器阶数设置的过大时,频率响应函数好像就失效了。例如当n=111,131时,频率响应曲线如下图所示。原因是什么我也不知道,欢迎大家在评论区留意指教!

                                   

那么如何选取合适的滤波器阶数呢?

firpmord函数:查找满足输入f,a和dev的近似阶数,归一化的频带边缘,频带幅度和权重。

[n,fo,ao,w] = firpmord(f,a,dev)
[n,fo,ao,w] = firpmord(f,a,dev,fs)

f是频带边缘的向量(在0和Fs / 2之间,其中Fs是采样频率), 例如低通滤波器 就是截至频率和阻带开始频率。而a是在f定义的频带上指定所需幅度的向量。 f的长度比a的长度小两倍。所需函数为分段常数。dev是一个与向量a大小相同的向量,它指定每个频带的频率响应与输出滤波器的期望幅度之间的最大允许偏差或波动,通带波动 p 和阻带衰减s所组成向量。fs用于指定采样频率Fs。 fs的默认值为2 Hz,这意味着奈奎斯特频率为1 Hz。因此可以指定缩放到特定应用程序采样频率的频带边缘。

                                    

将firpm函数使用得到的阶数n,频率矢量fo,幅度响应矢量ao和权重w,以设计滤波器b,该滤波器大约满足firpmord输入参数f,a和dev给出的规格。

rp = 3;           % 通带波动
rs = 40;          % 阻带波动
fs = 2000;        % 采样率
f = [500 600];    % 截止频率
a = [1 0];        % 期望幅值

dev = [(10^(rp/20)-1)/(10^(rp/20)+1)  10^(-rs/20)];
[n,fo,ao,w] = firpmord(f,a,dev,fs);
b = firpm(n,fo,ao,w);
freqz(b,1,1024,fs)
title('Lowpass Filter Designed to Specifications')

 

频率响应特性

freqz函数:

[H,w]=freqz(B,A,N);  %用默认区间 0:pi

[H,w]=freqz(B,A,N,'whole'); %调用主值区间 -pi:pi

[H,w]=freqz(B,A,[自定义区间]) %自定义区间,如[0:2*pi/n:2*pi]

B和A分别为离散系统的系统函数分子、分母多项式的系数向量,B=[b1,b2,...];  A=[a1,a2,...];N为正整数,默认值为512。返回量H则包含了离散系统频响 在 0—pi范围内N个频率等分点的响应值,向量w为N个频率等分点的值。最后利用abs()和angle()函数及plot()函数,即可绘制出系统在频率区间的频响曲线。

dsp.FIRFilter系统对象

FIRFilter对象使用静态或时变FIR滤波器实现对输入的每个通道进行过滤。

要过滤输入的每个通道:首先定义并设置你的FIR滤波器;然后根据dsp.FIRFilter的属性过滤输入的每个通道。

1、H = dsp.FIRFilter返回默认的FIR过滤器对象H,该对象使用指定的FIR过滤器实现在对step方法的连续调用中,独立过滤输入的每个通道。

2、H = dsp.FIRFilter('PropertyName',PropertyValue,...)返回FIR过滤器系统对象H,每个属性均设置为指定值。

Properties

Structure

指定过滤器结构。可以将过滤器结构指定为 | Direct form | Direct form symmetric | Direct form antisymmetric | Direct form transposed | Lattice MA |之一。默认值为Direct form

NumeratorSource

滤波器系数的来源,将滤波器系数的来源指定为| Property | Input port之一,默认值为Property。当指定Input port时,过滤器对象每帧更新一次随时间变化的过滤器。

ReflectionCoefficientsSource

Source of filter coefficients

Specify the source of the Lattice filter coefficients as one of | Property | Input port |. The default is Property. When you specify Input port, the filter object updates the time-varying filter once every frame.

This applies when you set the Structure to Lattice MA .

Numerator

分子系数,将滤波器系数指定为实数或复数行向量。当将NumeratorSource属性设置为Property,并且Structure属性设置为Direct formDirect form symmetricDirect form antisymmetric, or Direct form transposed时,此属性适用。默认值为[0.5 0.5]。

ReflectionCoefficients

Reflection coefficients of lattice filter structure

Specify the reflection coefficients of a lattice filter as a real or complex numeric row vector. This property applies when you set the Structureproperty to Lattice MA, and the ReflectionCoefficientsSource property to Property. The default is [0.5 0.5]. This property is tunable.

InitialConditions

Initial conditions for the FIR filter

Specify the initial conditions of the filter states. The number of states or delay elements equals the number of reflection coefficients for the lattice structure, or the number of filter coefficients–1 for the other direct form structures.

You can specify the initial conditions as a scalar, vector, or matrix. If you specify a scalar value, the FIR filter object initializes all delay elements in the filter to that value. If you specify a vector whose length equals the number of delay elements in the filter, each vector element specifies a unique initial condition for the corresponding delay element. The object applies the same vector of initial conditions to each channel of the input signal.

If you specify a vector whose length equals the product of the number of input channels and the number of delay elements in the filter, each element specifies a unique initial condition for the corresponding delay element in the corresponding channel. 

If you specify a matrix with the same number of rows as the number of delay elements in the filter, and one column for each channel of the input signal, each element specifies a unique initial condition for the corresponding delay element in the corresponding channel. The default is 0.

N = 10;  
Fc = 0.4;
B = fir1(N,Fc);
Hf1 = dsp.FIRFilter('Numerator',B);
fvtool(Hf1)

 

  • 8
    点赞
  • 83
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值