基于双线性变换法用MATLAB设计低通、高通、带通滤波器

2024-12-01 04:42:09
推荐回答(1个)
回答1:

我当时改写的课程设计程序,希望对你有帮助(参数自己改,很容易的)
%%%%%%%%%%%%% 低通滤波 %%%%%%%%%%%%%%%%
clear;
clear clf;
%%% 对连续时间信号进行采样
f1=2;f2=5;f3=8;
fs=20;Ts=1/fs;
M=200;
k=0:M-1;
fk=cos(2*pi*f1*k*Ts)+cos(2*pi*f2*k*Ts)+cos(2*pi*f3*k*Ts);
%figure(1)
subplot(411)
plot(k,fk)%stem(k,fk)
xlabel ' '
title '滤波前的波形图';

N = M;
F = fft(fk, N);
subplot(412)
plot(2*pi*(0:N/2-1)/N/pi, 2*abs(F(1:N/2))/N);
xlabel ' '
title '滤波前的频谱曲线';

h=[0.00111829516864 -0.00389476479172 -0.01603491745519 -0.02036377118215 0.02095180705130 0.12449781344246...
0.24450683184615 0.29843741184102 0.24450683184615 0.12449781344246 0.02095180705130 -0.02036377118215...
-0.01603491745519 -0.00389476479172 0.00111829516864];
yk = conv(fk,h);

%figure(2)
subplot(413)
plot(0:M+15-2,yk,'g')%stem(0:M+15-2,yk)
xlabel ' '
title '低通滤波后的波形图';
axis([0 M -1 1])
Y = fft(yk, N);
subplot(414)
plot(2*pi*(0:N/2-1)/N/pi, 2*abs(Y(1:N/2))/N,'g');
title '低通滤波后的频谱曲线';
%===================注:与高通滤波不同之处在于h的取值
%%%%%%%%%%%%% 课程设计(2) %%%%%%%%%%%%%
%%%%%%%%%%%%% 高通滤波 %%%%%%%%%%%%%%%%
clear;
clear clf;
%%% 对连续时间信号进行采样
f1=2;f2=5;f3=8;
fs=20;Ts=1/fs;
M=200;
k=0:M-1;
fk=cos(2*pi*f1*k*Ts)+cos(2*pi*f2*k*Ts)+cos(2*pi*f3*k*Ts);
%figure(1)
subplot(411)
plot(k,fk)
xlabel ' '
title '滤波前的波形图';

N = M;
F = fft(fk, N);
subplot(412)
plot(2*pi*(0:N/2-1)/N/pi, 2*abs(F(1:N/2))/N);
xlabel ' '
title '滤波前的频谱曲线';

h=[-0.00111829516864 -0.00389476479172 0.01603491745519 -0.02036377118215 -0.02095180705130 0.12449781344246...
-0.24450683184615 0.29843741184102 -0.24450683184615 0.12449781344246 -0.02095180705130 -0.02036377118215...
0.01603491745519 -0.00389476479172 -0.00111829516864];
yk = conv(fk,h);

%figure(2)
subplot(413)
plot(0:M+15-2,yk)
xlabel ' '
title '滤波后的波形图';
axis([0 M -1 1])
Y = fft(yk, N);
subplot(414)
plot(2*pi*(0:N/2-1)/N/pi, 2*abs(Y(1:N/2))/N);
title '滤波前的频谱曲线';
%%%%%%%%%%%%% 课程设计(4) %%%%%%%%%%%%%
%%%%%%%%%%%%% 带通滤波 %%%%%%%%%%%%%%%%
clear;
clear clf;
%%% 对连续时间信号进行采样
f1=2;f2=5;f3=8;
fs=20;Ts=1/fs;
M=200;
k=0:M-1;
fk=cos(2*pi*f1*k*Ts)+cos(2*pi*f2*k*Ts)+cos(2*pi*f3*k*Ts);
subplot(411)
plot(k,fk)
xlabel ' '
title '滤波前的波形图'

N = M;
F = fft(fk, N);
subplot(412)
plot(2*pi*(0:N/2-1)/N/pi, 2*abs(F(1:N/2))/N);
xlabel ' '
title '滤波前的频谱曲线'

h=[ 0 0.00809904403983 0 0.04234583818052 0 -0.25888938815435 0 0.41372763540994 0 -0.25888938815435 0 0.04234583818052 0 0.00809904403983 0];
yk = conv(fk,h);

figure(2)
subplot(413)
plot(0:M+15-2,yk)
axis([0 M -1 1])
Y = fft(yk, N);
subplot(414)
plot(2*pi*(0:N/2-1)/N/pi, 2*abs(Y(1:N/2))/N);
title '滤波前的频谱曲线'
%%%%%%%%%%%%% 课程设计(4) %%%%%%%%%%%%%
%%%%%%%%%%%%% 带阻滤波 %%%%%%%%%%%%%%%%
clear;
clear clf;
%%% 对连续时间信号进行采样
f1=2;f2=5;f3=8;
fs=20;Ts=1/fs;
M=200;
k=0:M-1;
fk=cos(2*pi*f1*k*Ts)+cos(2*pi*f2*k*Ts)+cos(2*pi*f3*k*Ts);

subplot(411)
plot(k,fk)
xlabel ' '
title '滤波前的波形图'
N = M;
F = fft(fk, N);
subplot(412)
plot(2*pi*(0:N/2-1)/N/pi, 2*abs(F(1:N/2))/N);
xlabel ' '
title '滤波前的频谱曲线'

h=[ 0 -0.00780645449547 0 -0.04081603423850 0 0.24953663889817 0 0.59817169967160...
0 0.24953663889817 0 -0.04081603423850 0 -0.00780645449547 0];
yk = conv(fk,h);

subplot(413)
plot(0:M+15-2,yk,'r')
xlabel ' '
title '带阻滤波后前的波形图'
axis([0 M -1 1])
Y = fft(yk, N);
subplot(414)
plot(2*pi*(0:N/2-1)/N/pi, 2*abs(Y(1:N/2))/N,'r');
title '带阻滤波前的频谱曲线'