Matlab digital filter design (IIR and the FIR) (containing Matlab code)
The advantages and disadvantages of the FIR filter
advantages: good phase linearity, fast processing speed, the stability of the feedback loop is not stronger than the IIR.
Disadvantages: the FIR amplitude-frequency characteristic IIR low precision compared to
the IIR filter
advantages: better IIR filtering order at the same
drawback: a high level of non-linear phase, bi-directional filtering needs to be corrected when the correction is not easy to control.
The key is that the FIR filter window function: Here are
Hamming window:
FIR - the Hamming window
- The lower side-lobe amplitude, in particular the first side lobe;
- Sidelobe amplitude to decrease faster, in order to facilitate increased stopband attenuation;
- The width of the main lobe is narrower, so that the filter transition band is narrower.
N = 40
leakage factor of 0.04%, relative sidelobe suppression -42.1dB, 0.0625 main lobe width (the normalized frequency)
N, the longer the calculation time is, the longer group delay. Take N = 40 (according to different situations, the filter order may take different values, here we filtered audio signal of a specific period, thus taking 40)
N greater, the longer the calculation time is, the longer the group delay. Take N = 40
Filtering results show:
blue front filtered signal; the red is FIR filtered signal
using the IIR elliptic filter filtering the audio signal:
filtering result shows:
direct songs IIR_ Eliptic (oval) filter
FIR filtering (yellow), IIR filtered (purple)
for different audio signals, the original spectrum analysis, only changes to the design parameters of the filter, to implement a digital filter.
See the code below:
[x,fs]=audioread('C:\Users\a\Desktop\大三上\精密仪器\讨论课题目\新闻(加噪声).wav');
n=length(x);
y=fft(x,n); %做FFT变换
f=fs*(0:n/2-1)/n;
subplot(2,1,1);
plot(x);
axis([0 1400000 -1.5 1.5]);
title('原始新闻信号采样后的时域波形');
xlabel('时间轴')
ylabel('幅值A')
subplot(2,1,2);
plot(f,abs(y(1:n/2)));
axis([0 1000 0 5000]);
title('原始新闻信号采样后的频谱图');
xlabel('频率Hz');
ylabel('频率幅值');
% n=0:N-1;
% w=2*n*pi/N;
FIRsignal=IIR_BANDPASSCheby;
outsignal=filter(FIRsignal,x);
% IIRsignal=IIR_BANDPASSEliptic;
% outsignal2=filter(IIRsignal,outsignal);
% set(gca,'fontsize',15,'tickdir','out')
% axis([0 5.0E-4 -2 2])
% xlabel('Time');ylabel('Amplitude')
% legend('FIR低通数字滤波器后的信号')
m=fft(outsignal,n);
f=48000*(0:n/2-1)/n;
figure
subplot(211);
plot(outsignal);
axis([0 1400000 -1.5 1.5]);
title('新闻滤波信号时域波形');
xlabel('时间轴')
ylabel('幅值A')
subplot(212);
plot(f,abs(m(1:n/2)))
axis([200 2700 0 5000]);
title('新闻滤波信号频谱图');
xlabel('频率Hz');
ylabel('频率幅值');
sound(1.5*outsignal,44100);
% audiowrite('C:\Users\a\Desktop\精密仪器\讨论课题目\新闻(IIR滤波后).wav',outsignal2,44100);
% sound(x,44100);
The first issue, we welcome correction exchanges, do not like do not spray! ! ! !