数处实验4
function st=mstg N=1600;Fs=10000;T=1/Fs;Tp=N*T;t=0:T:(N-1)*T;k=0:N-1;f=k/Tp;fc1=Fs/10;fm1=fc1/10;fc2=Fs/20;fm2=fc2/10;fc3=Fs/40;fm3=fc3/10;xt1=cos(2*pi*fm1*t).*cos(2*pi*fc1*t);xt2=cos(2*pi*fm2*t).*cos(2*pi*fc2*t);xt3=cos(2*pi*fm3*t).*cos(2*pi*fc3*t);st=xt1+xt2+xt3;fxt=fft(st,N);subplot(2,1,1);plot(t,st);grid;xlabel("t/s");ylabel("x(t)");axis([0,Tp/16,min(st),max(st)]);title("s(t)波形")subplot(2,1,2);stem(f,abs(fxt)/max(abs(fxt)));grid;title("s(t)的频谱")axis([0,1500,0,1.2]);xlabel("f/Hz");ylabel("幅度")function myplot(B,A)[H,W]=freqz(B,A,1000);m=abs(H);plot(W/pi,20*log10(m/max(m)));grid on;axis([0,1,-80,5]);xlabel("omega/pi");ylabel("幅度(dB)")title("损耗函数曲线")% IIR数字滤波器设计及软件实现 clear all;close all Fs=10000;T=1/Fs;%采样频率 st=mstg;%产生由三路抑制载波调幅信号相加构成的复合信号st fp=280;fs=450;%低通滤波器设计与实现 wp=2*fp/Fs;ws=2*fs/Fs;rp=0.1;rs=60;%DF指标 [N,wp]=ellipord(wp,ws,rp,rs);%计算椭圆DF阶数N和通带截止频率wp [B,A]=ellip(N,rp,rs,wp);%计算椭圆带通DF系统函数系数向量B和A y1t=filter(B,A,st);%滤波器软件实现 figure(2);subplot(3,1,1);myplot(B,A);%绘制损耗函数曲线 yt="y_1(t)";subplot(3,1,2);tplot(y1t,T,yt);%绘制滤波器输出波形 N1=1600;k=0:N1-1;fftl=fft(y1t,N1);subplot(3,1,3);stem(Fs*k/N1,abs(fftl)/max(abs(fftl)));xlabel("f/Hz");ylabel("幅度");title("幅频响应(低通)");axis([1,1200,0,1.2]);grid;fpl=440;fpu=560;fsl=275;fsu=900;%带通滤波器设计与实现 wp=[2*fpl/Fs,2*fpu/Fs];ws=[2*fsl/Fs,2*fsu/Fs];rp=0.1;rs=60;[N,wp]=ellipord(wp,ws,rp,rs);[B,A]=ellip(N,rp,rs,wp);y2t=filter(B,A,st);figure(3);subplot(3,1,1);myplot(B,A);yt="y_2(t)";subplot(3,1,2);tplot(y2t,T,yt);0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01-10123t/sx(t)s(t)波 形0 200 400 600 800 1000 120000.51s(t)的 频 谱f/Hz幅度0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-80-60-40-200 / 幅度(dB)损 耗 函 数 曲 线0 0.05 0.1 0.15-101t/sy 2(t)100 200 300 400 500 600 700 800 900 1000 1100 120000.51f/Hz幅度幅 频 响 应(带 通)0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-80-60-40-200 / 幅度(dB)损 耗 函 数 曲 线0 0.05 0.1 0.15-101t/sy 3(t)100 200 300 400 500 600 700 800 900 1000 1100 120000.51f/Hz幅度幅 频 响 应(高 通)
fftb=fft(y2t,N1);subplot(3,1,3);stem(Fs*k/N1,abs(fftb)/max(abs(fftb)));xlabel("f/Hz");ylabel("幅度");title("幅频响应(带通)");axis([1,1200,0,1.2]);grid;fp=890;fs=600;%高通滤波器设计与实现 wp=2*fp/Fs;ws=2*fs/Fs;rp=0.1;rs=60;[N,wp]=ellipord(wp,ws,rp,rs);[B,A]=ellip(N,rp,rs,wp,"high");y3t=filter(B,A,st);figure(4);subplot(3,1,1);myplot(B,A);yt="y_3(t)";subplot(3,1,2);tplot(y3t,T,yt);ffth=fft(y3t,N1);subplot(3,1,3);stem(Fs*k/N1,abs(ffth)/max(abs(ffth)));xlabel("f/Hz");ylabel("幅度");title("幅频响应(高通)");axis([1,1200,0,1.2]);grid;0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-80-60-40-200 / 幅度(dB)损 耗 函 数 曲 线0 0.05 0.1 0.15-0.500.51t/sy 1(t)100 200 300 400 500 600 700 800 900 1000 1100 120000.51f/Hz幅度幅 频 响 应(低 通)
