目录
一、设计FIR滤波器
Program your own function for digital low pass FIR filter design, using the windowing
method.
Experiment Content
①. The process of Programming
Step1: Choose a pass band edge frequency in Hz for the filter in the middle of the transition width:
Step2:Calculate.and substitute this value into
.
Step3: Choose a window that will satisfy the stop band attenuation. Calculate the number of terms N that will meet the transition width requirement. Choose an odd number so that the impulse response will be perfectly symmetrical.
Step4: Calculate the finite impulse response:.
Step5: Shift the impulse response values to ensure the causality.
function b=firwindow(f_pass,f_stop,fs,A_stop)
fc=(f_pass+f_stop)/2;
wc=2*pi*fc/fs;%设计的理想滤波器的截止频率
%根据阻带衰减选择合适的窗函数
if(A_stop<=21)
N=0.91*fs/(f_stop-f_pass)
window=1
elseif(A_stop<=44)
N=3.32*fs/(f_stop-f_pass)
window=2
elseif (A_stop<=55)
N=3.44*fs/(f_stop-f_pass)
window=3
else (A_stop<=75)
N=5.98*fs/(f_stop-f_pass)
window=4
end
%窗函数点数N向上取整,且要求必须为奇数
if(mod(ceil(N),2))
N=ceil(N)
else N=ceil(N)+1
end
n=-(N-1)/2:(N-1)/2;
switch window
case 1
window=ones(1,N);
case 2
window=0.5+0.5*cos(2*pi*n/(N-1));
case 3
window=0.54+0.46*cos(2*pi*n/(N-1));
case 4
window=0.42+0.5*cos(2*pi*n/(N-1))+0.08*cos(4*pi*n/(N-1));
end
%与理想低通滤波器的时域表达式相乘,得到加窗后的低通滤波器
b=window.*sin(wc*n)./(pi*n);
%n=0处MATLAB计算有问题,需要手动调整,同时相当于向右调整为因果序列
b=[b(1:(N-1)/2) wc/pi b((N+1)/2+1:N)];
end
二、设计IIR滤波器
Program your own function for first order Butterworth digital IIR filter design, using the
Bilinear Transformation with prewarping.
function [b, a] = iirbutter(fp1,fs)
wp1=2*pi*fp1/fs;
Wc=2*fs*tan(wp1/2);
a=[1,(Wc-2*fs)/(Wc+2*fs)];
b=[Wc/(Wc+2*fs) Wc/(Wc+2*fs)];
end
三、最终实验报告
实验分数应该会很不错,有兴趣的学弟可以学习一下