FIR和IIR滤波器的设计(MATLAB)

360影视 2025-01-04 15:16 3

摘要:%% , LPF, BPF: FIR (Kaiser, Equiripple), IIR (Butterworth, Chebyschev I,Chebyschev II, Elliptic)

Butterworth, Chebyshev I & II, Elliptic, Equiripple, and Kaiser window methods.

%% , LPF, BPF: FIR (Kaiser, Equiripple), IIR (Butterworth, Chebyschev I,Chebyschev II, Elliptic)

Type1 = {'lowpassiir','lowpassfir'}; Type2 = {'bandpassiir', 'bandpassfir'}; Desginmethod1 ={'kaiserwin','equiripple'};Desginmethod2 = {'butt','cheby1','cheby2','ellipIIR_FIR = input('Specify type of the filter. IIR = 1 or FIR = 2? ');%1 shows IIR, and 2 shows FIRLPF_BPF = input('Specify LPF = 1 or BPF1 = 2 or BPF2 = 3? ');%1 shows LPF, 2 shows BPF1, 3 shows BPF2if IIR_FIR == 1 %If you chose IIR, then, you have to chose one of the 4 given methodsfprintf('Determine the type of filter: Butt: 1, Cheby 1: 2, Cheby 2: 3, Ellip: 4\n');IIR_Type = input('Specify type of the filter ');else %If you chose FIR, then, you have to chose one of the 2 given methodsfprintf('Determine the type of filter: Kaiser win: 1 , Equiripple : 2\n');FIR_Type = input('Specify type of the filter ');endif LPF_BPF == 2 %Spec. of BPF 1 as given in the questionFstop1 = 8000;%Lower stop frequency (Hz) =10 kHzFpass2 = 20000;%Passband frequency (Hz)Fstop2 = 22000;%Upper stop frequency (Hz) >=22 kHzAstop1 = 65;%Stopband attenuation (>= 65 ) dBApass = 0.5; %Passbadn ripple 0.5 dBAstop2 = 65;%Stopband attenuation (>= 65 ) dBFs = 60000;%Sampling frequency (samples/second or Hz)elseif LPF_BPF == 3 %Spec. of BPF 2 by changing Fstop1 and Fstop2Fstop1 = 9000;%Lower stop frequency (Hz) =10 kHzFpass2 = 20000;%Passband frequency (Hz)Fstop2 = 21000;%Upper stop frequency (Hz) >=kHzAstop1 = 65;%Stopband attenuation (>= 65 ) dBApass = 0.5; %Passbadn ripple 1 dBAstop2 = 65;%Stopband attenuation (>= 65 ) dBFs = 60000;%Sampling frequency (samples/second or Hz)else %Spec. of LPFFpass = 20000;%Passband frequency (Hz) or 20 kHzFstop = 24000;%Stopband frequency (Hz) or 24 kHzApass = 0.5;%Passband ripple (dB)Astop = 65;%Stopband attenuatution (dB)Fs = 60000;%Sampling frequency (samples/second or Hz) or 60 kSamples/secondend%Now we have to design the filter based on the given information.if LPF_BPF == 1if IIR_FIR == 1%LPF, IIRIIR_filt = designfilt(Type1{1} , ...'PassbandFrequency',Fpass,'StopbandFrequency',Fstop, ...'PassbandRipple',Apass,'StopbandAttenuation',Astop, ...'DesignMethod',Desginmethod2{IIR_Type},'SampleRate',Fs); [b,a] = sos2tf(IIR_filt.Coefficients); %SOS to numerator and denominatorIIR = dsp.IIRFilter('Numerator',b,...'Denominator',a,'Structure','Direct form II');%Specify the configuration (Direct form I or II)cost(IIR) % Cost of the filter%info(IIR_filt)[z,p,k] = zpk(IIR_filt);%Zero poles of IIR filterMax_radius = max(abs(p))% The maximum radius of the poles Dis_circle = 1- Max_radius %Distance to the unit circle for the pole with max radiusgrp_samples = max(grpdelay(IIR_filt))% Computing the number of samples of group delaygrp_time = (max(grpdelay(IIR_filt))/Fs)*10^6 % Converting the samples to microSecondsfvtool(IIR_filt)else %LPF, FIRFIR_filt = designfilt(Type1{2} , ...'PassbandFrequency',Fpass,'StopbandFrequency',Fstop, ...'PassbandRipple',Apass,'StopbandAttenuation',Astop, ...'DesignMethod',Desginmethod1{FIR_Type},'SampleRate',Fs);FIR = dsp.FIRFilter(FIR_filt.Coefficients);cost(FIR)% Cost of the filtergrp_samples = max(grpdelay(FIR_filt))% Computing the number of samples of group delaygrp_time = (max(grpdelay(FIR_filt))/Fs)*10^6 % Converting the samples to microSecondsfvtool(FIR_filt)endelseif IIR_FIR == 1%BPF, IIRIIR_filt = designfilt(Type2{1}, ...'StopbandFrequency1',Fstop1,'PassbandFrequency1', Fpass1, ...'PassbandFrequency2',Fpass2,'StopbandFrequency2', Fstop2, ...'StopbandAttenuation1',Astop1,'PassbandRipple', Apass, ...'StopbandAttenuation2',Astop2, ...'DesignMethod',Desginmethod2{IIR_Type},'SampleRate',Fs);[b,a] = sos2tf(IIR_filt.Coefficients); %SOS to numerator and denominatorIIR = dsp.IIRFilter('Numerator',b,...'Denominator',a,'Structure','Direct form II');%Specify the configuration (Direct form I or II)cost(IIR) % Cost of the filter%info(IIR_filt)[z,p,k] = zpk(IIR_filt);%Zero poles of IIR filterMax_radius = max(abs(p))% The maximum radius of the poles Dis_circle = 1- Max_radius %Distance to the unit circle for the pole with max radiusgrp_samples = max(grpdelay(IIR_filt))% Computing the number of samples of group delaygrp_time = (max(grpdelay(IIR_filt))/Fs)*10^6 % Converting the samples to microSecondsfvtool(IIR_filt)else%BPF, FIRFIR_filt = designfilt(Type2{2}, ...'StopbandFrequency1',Fstop1,'PassbandFrequency1', Fpass1, ...'PassbandFrequency2',Fpass2,'StopbandFrequency2', Fstop2, ...'StopbandAttenuation1',Astop1,'PassbandRipple', Apass, ...'StopbandAttenuation2',Astop2, ...'DesignMethod',Desginmethod1{FIR_Type},'SampleRate',Fs); FIR = dsp.FIRFilter(FIR_filt.Coefficients);cost(FIR)% Cost of the filtergrp_samples = max(grpdelay(FIR_filt))% Computing the number of samples of group delaygrp_time = (max(grpdelay(FIR_filt))/Fs)*10^6 % Converting the samples to microSecondsfvtool(FIR_filt)endend

知乎学术咨询:

https://www.zhihu.com/consult/people/792359672131756032?isMe=1

担任《Mechanical System and Signal Processing》《中国电机工程学报》等期刊审稿专家,擅长领域:信号滤波/降噪,机器学习/深度学习,时间序列预分析/预测,设备故障诊断/缺陷检测/异常检测。

分割线分割线分割线

基于小波分析的时间序列降噪(Python,ipynb文件)

完整代码:

基于连续小波变换的信号滤波方法(Python,ipynb文件)

完整代码:

信号的时域、频域和时频域特征提取(Python)

完整代码:

不同小波族的优缺点

完整代码:

基于优化Morlet小波的一维信号瞬态特征提取方法(MATLAB )

程序运行环境为MATLAB R2018A,利用优化Morlet小波对一维信号进行瞬态特征提取。程序测试了模拟信号,地震信号,发动机销子活塞故障振动信号,发动机气门正常振动信号,发动机排气门故障振动信号,结果如下。

完整代码可通过知乎付费咨询获得

来源:水桃教育

相关推荐