实验四代码
- 格式:doc
- 大小:99.50 KB
- 文档页数:5
tr0401.m
clear,close all;
Wp=0.2*pi;Ws=0.3*pi;Rp=1;Rs=15;
T=2;Fs=1/T;
wp=2*tan(Wp/2)/T;ws=2*tan(Ws/2)/T; %预畸变
[N,wc]=buttord(wp,ws,Rp,Rs,'s'); %计算过渡模拟滤波器阶数N和3dB截止频率
[B,A]=butter(N,wc,'s'); %计算模拟滤波器系统函数
[Bz,Az]=bilinear(B,A,Fs); %用双线性变换法将模拟滤波器转换为数字滤波器
w=linspace(0,pi,1024); %将0到π之间均分1024个频率采样点
h=freqz(Bz,Az,w); %计算数字滤波器的复频响h,频率点由向量w指定
plot(w/pi,20*log10(abs(h)),'k');grid on;
set(gca,'ytick',[-15,-1,0]); %在衰减1dB和15dB处标明纵坐标
set(gca,'xtick',[0,0.2,0.3,0.5]); %在通带和阻带截止频率处标明横坐标
axis([0,0.5,-50,0]);
xlabel('ω/π');ylabel('幅度(dB)');
(3)
clear,close all;
Wp=0.2*pi;Ws=0.3*pi;Rp=1;Rs=15;
T=2;Fs=1/T;
wp=2*tan(Wp/2)/T;ws=2*tan(Ws/2)/T; %预畸变
[N,wc]=buttord(wp,ws,Rp,Rs,'s'); %计算过渡模拟滤波器阶数N和3dB截止频率
[B,A]=butter(N,wc,'s'); %计算模拟滤波器系统函数
[Bz,Az]=bilinear(B,A,Fs); %用双线性变换法将模拟滤波器转换为数字滤波器
x=[-4, -2, 0, -4, -6, -4, -2, -4, -6, -6, -4, -4, -6, -6, -2, 6, 12, 8, ...
0, -16, -38, -60, -84, -90, -66, -32, -4, -2, -4, 8, 12, 12, 10, 6, 6, 6,... 4, 0, 0, 0, 0, 0, -2, -4, 0, 0, 0, -2, -2, 0, 0, -2, -2, -2, -2, 0];
subplot(2, 2, 1)
stem(n, x, '.');
axis([0 56 -100 50]);
xlabel('n');
ylabel('x(n)');
title('心电图信号采样序列x(n)');
subplot(2, 2, 2)
w=linspace(0,pi,1024); %将0到π之间均分1024个频率采样点
h=freqz(Bz,Az,w); %计算数字滤波器的复频响h,频率点由向量w 指定
plot(w/pi,20*log10(abs(h)),'k');grid on ;
set(gca,'ytick',[-15,-1,0]); %在衰减1dB 和15dB 处标明纵坐标
set(gca,'xtick',[0,0.2,0.3,0.5]); %在通带和阻带截止频率处标明横坐标
axis([0,0.5,-50,0]);
xlabel('ω/π');ylabel('幅度(dB)');
title('滤波器的幅频响应曲线');
y=filter(Bz, Az, x);
subplot(2, 2, 3)
stem(n, y, '.');
axis([0 56 -100 50]);
xlabel('n');
ylabel('y(n)');
title('滤波后的心电图信号');
(4)
用窗函数法设计一个满足下列指标的线性相位低通FIR 滤波器。
通带截止频率0.2p
ωπ=rad ,通带最大衰减1d B p α=;
阻带截止频率0.3s ωπ=rad ,阻带最小衰减15dB s α=。
分析:理想滤波器的截止频率()/20.25c p s rad ωωωπ=+=
根据要求的阻带最小衰减15dB s α=,查表可知矩形窗和三角窗均可提供大于15dB 的衰减。
这里选择海明窗,因为过渡带窄些,从而具有较小的阶数。
由于要求的过渡带宽0.1s p B ∆ωωπ=-=,而矩形窗的精确过渡带宽满足 1.8B N
π∆=,因此有1.80.1N ππ≤,解之可得18N ≥,取18N =,则滤波器阶次为N-1=17
tr0404.m
wc=0.25;
N=18;
win=boxcar(N); %产生长度为N 的矩形窗
h=fir1(N-1,wc,win); %采用窗函数法设计FIR 滤波器,截止频率为0.25π
w=linspace(0,pi,512); %在0~π之间均匀采样512次,取512个频率采样值
mag=freqz(h,[1],w); %系统函数的分子系数向量为h ,分母只有常数项1
%数字滤波器的复频率响应mag ,频率点由向量w 指定
magdb=20*log10(abs(mag));
figure;
subplot(211);plot(w/pi,magdb,'k');title('幅频特性');
axis([0 1 -100 0]);grid;
set(gca,'ytick',[-15,0]); %在衰减0dB 和15dB 处标明纵坐标
set(gca,'xtick',[0.2,0.3]); %在通带和阻带截止频率处标明横坐标
xlabel('ω/π');ylabel('幅度(dB)');
pha=angle(mag);
subplot(212);plot(w/pi, pha,'k');title('相频特性');
xlabel('ω/π');
ylabel('相位(rad)');
axis([0 1 -4 4]);
(5)
tr0405.m
clear,close all;
wc=0.25;
N=18;
win=boxcar(N); %产生长度为N的矩形窗
h=fir1(N-1,wc,win); %采用窗函数法设计FIR滤波器,截止频率为0.25π
x=[-4, -2, 0, -4, -6, -4, -2, -4, -6, -6, -4, -4, -6, -6, -2, 6, 12, 8, ...
0, -16, -38, -60, -84, -90, -66, -32, -4, -2, -4, 8, 12, 12, 10, 6, 6, 6,... 4, 0, 0, 0, 0, 0, -2, -4, 0, 0, 0, -2, -2, 0, 0, -2, -2, -2, -2, 0];
subplot(221)
n=0:55;
stem(n, x, '.');
axis([0 56 -100 50]);
xlabel('n');
ylabel('x(n)');
title('心电图信号采样序列x(n)');
subplot(222)
w=linspace(0,pi,512); %在0~π之间均匀采样512次,取512个频率采样值
mag=freqz(h,[1],w); %系统函数的分子系数向量为h,分母只有常数项1
%数字滤波器的复频率响应mag,频率点由向量w指定
magdb=20*log10(abs(mag));
plot(w/pi,magdb,'k')
axis([0 1 -100 0]);grid;
set(gca,'ytick',[-15,0]); %在衰减0dB和15dB处标明纵坐标
set(gca,'xtick',[0.2,0.3]); %在通带和阻带截止频率处标明横坐标
xlabel('ω/π');ylabel('幅度(dB)'); title('滤波器的幅频响应曲线');
y=filter(h,[1], x);
subplot(223)
stem(n, y, '.');
axis([0 56 -100 50]);
xlabel('n');
ylabel('y(n)');
title('滤波后的心电图信号');。