当前位置:网站首页>FIR filter design
FIR filter design
2022-07-26 16:59:00 【jk_ one hundred and one】
Catalog
With infinite duration impulse response (IIR) Compared with the filter , Digital filter with finite duration impulse response ( All zero or FIR filter ) There are both advantages and disadvantages .
FIR The filter has the following main advantages :
- They can have precise linear phase
- They are always stable
- The design method is usually linear
- They can be implemented efficiently in hardware
The filter start transient has a finite duration .
FIR The main disadvantage of the filter is , To achieve the same level of performance , The required order is much higher than IIR filter . Accordingly , The delay of these filters is usually better than that of the same performance IIR The filter is much larger .
FIR filter
Filter design method | explain | Filter function |
|---|---|---|
Add windows | Apply windowing to the truncated inverse Fourier transform of the specified rectangular filter | fir1, fir2, kaiserord |
Multiband ( Including transition zone ) | Use equal ripple or least square methods for subbands in the frequency range | |
Constrained least squares | According to the maximum error constraint , Minimize the square integral error over the entire frequency range | fircls, fircls1 |
Any response | Any response , Including nonlinear phase and complex filter | cfirpm |
rrc | Low pass response with smooth sinusoidal transition | rcosdesign |
Linear phase filter
except cfirpm Outside , all FIR Filter design functions only design linear phase filters . These filter coefficients or “ Takeout ” Follow even or odd symmetry . According to this symmetry and the order of the filter n Is it even or odd , Linear phase filter ( Stored in... Length n +1 Vector b in ) There are certain inherent limitations on its frequency response .
| Linear phase filter type | The order of the filter | Symmetry of coefficients | Respond to H(f)、f = 0 | Respond to H(f)、f = 1 (Nyquist) |
|---|---|---|---|---|
I class | even numbers | even numbers : b(k)=b(n+2−k), k=1,...,n+1 | unlimited | unlimited |
II class | Odd number | even numbers : b(k)=b(n+2−k), k=1,...,n+1 | unlimited | H(1) |
III class | even numbers | Odd number : b(k)=−b(n+2−k), k=1,...,n+1 | H(0) | H(1) |
IV class | Odd number | Odd number : b(k)=−b(n+2−k), k=1,...,n+1 | H(0) | unlimited |
Linear phase FIR The phase delay and group delay of the filter are equal and constant in the whole frequency band . about n Order linear phase FIR filter , The group delay is n/2, Filtered signal delay n/2 Time steps ( The amplitude of its Fourier transform is scaled according to the amplitude response of the filter ). This attribute maintains the waveform of the signal in the passband ; in other words , No phase distortion .
By default , function fir1、fir2、firls、firpm、fircls and fircls1 Can be used for design I Classes and II Class linear phase FIR filter .rcosdesign Only for design I Class filter . In the given 'hilbert' or 'differentiator' In the case of signs ,firls and firpm Can be used for design III and IV Class linear phase FIR filter .cfirpm It can be used to design any type of linear phase filter and nonlinear phase filter .
Be careful : because II Class filter in Nyquist frequency (“ high ” frequency ) The frequency response is zero at ,fir1 Not for design II Quasi high pass and band stop filters . In these cases , If n Is an odd number ,fir1 Add steps 1, And back to I Class filter .
Windowing method
Suppose a cut-off frequency is ω0 radian / Second ideal rectangular digital low-pass filter . The filter has an amplitude less than ω0 Has amplitude at all frequencies 1, The amplitude is between ω0 and π There is an amplitude in the frequency between 0. Its impulse response sequence h(n) by :

This filter cannot be realized , Because its impulse response is infinite and non causal . To create a finite duration impulse response , Please truncate it by applying windowing . By keeping the central part of the impulse response in this truncation , Linear phase can be obtained FIR filter . for example , A low-pass cut-off frequency ω0 by 0.4 π radian / Of a second 、 The length is 51 The filter is :
b = 0.4*sinc(0.4*(-25:25));The windowing applied here is a simple rectangular window . according to Parseval Theorem , The length is 51 The filter of is closest to the ideal low-pass filter in the sense of integral least square . The following order is in FVTool The frequency response of the filter is displayed in :
fvtool(b,1)Please note that , The following figure shows y The shaft adopts the quadratic power of amplitude . You can right-click the axis tab and select Amplitude squared To set this . As shown in the figure :

Ringing and ripple will appear in the response , Especially near the edge of the band . such “ Gibbs effect ” It will not disappear with the increase of filter length , But non rectangular windows will reduce their amplitude . Multiplying the signal by a window function in the time domain will make the signal convolute or smooth in the frequency domain . The length will be 51 Of Hamming Windows should be used for filters , And use FVTool Show results :
b = 0.4*sinc(0.4*(-25:25));
b = b.*hamming(51)';
fvtool(b,1)Please note that , The following figure shows y The shaft adopts the quadratic power of amplitude . You can right-click the axis tab and select Amplitude squared To set this . As shown in the figure :

Use Hamming Windows can greatly reduce ringing . This improvement comes at the cost of transition width and optimality : Windowed filters take longer to fall from passband to stopband , And the square error integral cannot be minimized .
Standard frequency band FIR Filter design :fir1
fir1 Use least square approximation to calculate filter coefficients , Then the impulse response is smoothed by windowing . An overview of windowing and its properties , You can refer to Windowing .fir1 Be similar to IIR Design function of filter , Because it is used to design standard band configuration ( Lowpass 、 Bandpass 、 High pass and band stop ) Filter under . The following sentence :
n = 50;
Wn = 0.4;
b = fir1(n,Wn);Create a row vector b, It includes n rank Hamming Window filter coefficients . This is a low-pass linear phase FIR filter , The cut-off frequency is Wn.Wn Is between 0 and 1 Number between , among 1 Corresponding to Nyquist frequency , That is, half the sampling frequency .( Different from other methods , here Wn Corresponding to 6 dB spot .) To get a high pass filter , Just put the 'high' Add to the parameter list of the function . To obtain a bandpass or bandstop filter , take Wn Specified as a two element vector containing the passband edge frequency . Add 'stop'.
b = fir1(n,Wn,window) Use column vectors window Design the window specified in . vector window The length of must be n+1 Elements . If no window is specified ,fir1 Will be applied Hamming window .
Kaiser Window order estimation . kaiserord Function estimation filter order 、 Cut off frequency and Kaiser window β Parameters , Make it meet a given set of filter settings . Given the frequency band edge vector, the corresponding amplitude vector and the maximum allowable ripple ,kaiserord by fir1 Function returns the appropriate input parameters .
Multiband FIR Filter design :fir2
fir2 Function can also be used to design windowed FIR filter , But it has piecewise linear frequency response of arbitrary shape . This is related to fir1 Different , The latter is only designed with standard low-pass 、 qualcomm 、 Bandpass and bandstop configured filters . The following command :
n = 50;
f = [0 .4 .5 1];
m = [1 1 0 0];
b = fir2(n,f,m);Returns the row vector b, It includes n rank FIR The filter n+1 A coefficient of , Its frequency amplitude characteristic and vector f and m The given frequency amplitude characteristics match .f Is the vector of the frequency point , Range from 0 To 1, among 1 representative Nyquist frequency .m It's a vector , contain f The specified amplitude response of the specified point in .( The corresponding of this function IIR The function is yulewalk, The latter can also design filters based on arbitrary piecewise linear amplitude response .)
Reference code :
author : Master fat cat
link :https://zhuanlan.zhihu.com/p/337397832
source : You know
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
%% The original signal
fs = 1000; % sampling frequency
t = 0:1/fs:2-1/fs; % Time
singal0 = sin(2*pi*1*t); % A signal without noise
SNR = 15; % Signal to noise ratio
singal = awgn(singal0,SNR); % After adding Gaussian white noise
%% IIR wave filtering (butterworth filter )
fstop = 20; % Low pass cut-off frequency
wn = fstop/(fs/2); % Normalized cut-off frequency
N_IIR = 5; % IIR Order
[b_iir,a_iir] = butter(N_IIR,wn) % IIR Filter parameters
singal_iir = filter(b_iir,a_iir,singal); %IIR wave filtering
%% FIR wave filtering (hamming window )
N_FIR = 15; % FIR Order
b_fir = fir1(N_IIR,wn) % FIR Filter parameters
singal_fir = filter(b_fir,1,singal); %FIR wave filtering
%% moving average ( Smoothing constant M=10;)
wsize = 10; % Smoothing constant
b_avg = ones(1,wsize)/wsize; % A weight
singal_avg = filter(b_avg,1,singal); % Moving average filtering
%% Output comparison
figure
subplot(2,2,1)
plot(t,singal)
title('\fontname{ Song style }\fontsize{12} The original signal ');
xlabel('\fontname{Arial}\fontsize{12}t');
ylabel('\fontname{Arial}\fontsize{12}singal');
grid on;
subplot(2,2,2)
plot(t,singal_iir)
title('\fontname{ Song style }\fontsize{12}5 rank IIR wave filtering ');
xlabel('\fontname{Arial}\fontsize{12}t');
ylabel('\fontname{Arial}\fontsize{12}singal(iir)');
grid on;
subplot(2,2,3)
plot(t,singal_fir)
title('\fontname{ Song style }\fontsize{12}15 rank FIR wave filtering ');
xlabel('\fontname{Arial}\fontsize{12}t');
ylabel('\fontname{Arial}\fontsize{12}singal(fir)');
grid on;
subplot(2,2,4)
plot(t,singal_avg)
title('\fontname{ Song style }\fontsize{12} moving average ( constant 10)');
xlabel('\fontname{Arial}\fontsize{12}t');
ylabel('\fontname{Arial}\fontsize{12}singal(avg)');
grid on;As shown in the figure :

边栏推荐
- Re7: reading papers fla/mlac learning to predict charges for critical cases with legal basis
- How to balance open utilization and privacy security compliance of public data?
- Tensorflow Lite source code analysis
- mysql锁机制(举例说明)
- Idea Alibaba cloud multi module deployment
- Nacos win10 安装配置教程
- Win11自动删除文件设置方法
- Comprehensively design an oppe homepage -- layout and initialization
- 【开发教程9】疯壳·ARM功能手机-I2C教程
- Marxan model, reserve optimization and protection vacancy selection technology, application in invest ecosystem
猜你喜欢

【Flutter -- 进阶】打包
![[flight control development basic tutorial 3] crazy shell · open source formation UAV - serial port (basic transceiver)](/img/25/160b827d74f7902ec0d6be4683b1e5.png)
[flight control development basic tutorial 3] crazy shell · open source formation UAV - serial port (basic transceiver)

Oracle创建表分区后,查询的时候不给出partition,但是会给分区字段指定的值,会不会自动按照分区查询?

【Express接收Get、Post、路由请求参数】

NUC 11构建 ESXi 7.0.3f安装网卡驱动-V2(2022年7月升级版)

Take you a minute to learn about symmetric encryption and asymmetric encryption

浅谈云原生边缘计算框架演进

【飞控开发基础教程2】疯壳·开源编队无人机-定时器(LED 航情灯、指示灯闪烁)

The difference and efficiency comparison of three methods of C # conversion integer

My SQL is OK. Why is it still so slow? MySQL locking rules
随机推荐
Pyqt5 rapid development and practice 3.2 introduction to layout management and 3.3 practical application of QT Designer
After Oracle creates a table partition, the partition is not given during the query, but the value specified for the partition field will be automatically queried according to the partition?
操作系统迁移实战之在openEuler上部署MySQL数据库
Interface comparator
Differences between the use of structs and classes
[fluent -- advanced] packaging
Take you a minute to learn about symmetric encryption and asymmetric encryption
The Ministry of Public Security issued a traffic safety warning for summer tourism passenger transport: hold the steering wheel and tighten the safety string
营销指南 | 几种常见的微博营销打法
广东首例!广州一公司未履行数据安全保护义务被警方处罚
结构体和类使用的区别
公共数据如何兼顾开放利用和隐私安全合规?
TensorFlow Lite源码解析
利用MySQL主从复制延迟拯救误删数据
极大似然估计
How to implement Devops with automation tools | including low code and Devops application practice
抓包与发流软件与网络诊断
“青出于蓝胜于蓝”,为何藏宝计划(TPC)是持币生息最后的一朵白莲花
Guetzli simple to use
【无标题】