现代信号处理技术(上机实验报告)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验一系统响应与系统稳定性一实验程序:
1.调用filter函数接差分方程:
>> A=[1,-0.9];B=[0.05,0.05];
>> x1n=[1 1 1 1 1 1 1 1 zeros(1,50)];
>> x2n=ones(1,128);
>> hn=impz(B,A,58);
>> subplot(1,1,1);y='h(n)';tstem(hn,y);
>> title(' (a)系统单位脉冲响应h(n)')
>> y1n=filter(B,A,x1n);
>> title('(b)系统对R8(n)的响应y1n');
>> y2n=filter(B,A,x2n);
>> subplot(1,1,1);y='y2(n)';tstem(y2n,y);
>> title('(c) 系统对u(n)的响应y2(n)');
2.调用conv函数计算卷积:
>> x1n=[1 1 1 1 1 1 ];
>> h1n=[ones(1,10) zeros(1,10)];
>> h2n=[1 2.5 2.5 1 zeros(1,10)];
>> y21n=conv(h1n,x1n);
>> y22n=conv(h2n,x1n);
>> subplot(1,1,1);y='h1(n)';tstem(h1n,y);
>> title('(1) 系统单位脉冲响应h1(n)')
>> subplot(1,1,1);y='y21n';tsttem(y21n,y);
>> subplot(1,1,1);y='y21n';tstem(y21n,y);
>> title('(2) h1n与R8(n)的卷积y21(n)')
>> subplot(1,1,1);y='h2(n)';tstem(h2n,y);
>> title('(3) 系统单位脉冲响应h2(n)')
>> subplot(1,1,1);y='y22(n)';tstem(y22n,y);
>> title('(4) h2(n)与R8(n)的卷积y22(n)')
3.谐振器分析:
>> un=ones(1,256);
>> n=0:255;
>> xsin=sin(0.014*n)+sin(0.4*n);
>> A=[1,-1.8237,0.9801];B=[1/100.49,0,-1/100.49]; >> y31n=filter(B,A,un);
>> y32n=filter(B,A,xsin);
>> subplot(1,1,1);y='y31(n)';tstem(y31n,y);
>> title('(1) 谐振器对u(n)的响应y31(n)')
>> subplot(1,1,1);y='y32(n)';tstem(y32n,y);
>> title('(2) 谐振器对正弦信号的响应y32(n)') 二试验程序运行结果:
实验二用FFT对信号作频谱分析一实验程序:
1.调用函数fft计算序列x(n)的DFT
>>x1n=[ones(1,4)];
>> M=8;xa=1:(M/2);xb=(M/2):(-1):1;x2n=[xa,xb];
>> M=8;xa=1:(M/2);xb=(M/2):-1:1;x2n=[xa,xb];
>> x3n=[xb,xa];
>> X1k8=fft(x1n,8);
>> X1K16=fft(x1n,16);
>> X1k16=fft(x1n,16);
>> X2k8=fft(x2n,8);
>> X2k16=fft(x2n,16);
>> X3k8=fft(x3n,8);
>> X3k16=fft(x3n,16);
%以下为绘图程序
>> subplot(1,1,1);mstem(X1k8)
>> title('(a)8点DFT[x_1(n)]');
>> axis([0,2,0,1.2*max(abs(X1k8))])
>> subplot(1,1,1);mstem(X1k16);
>> title('(b)16点DFT[x_1(n)]');
>> axis([0,2,0,1.2*max(abs(X1k16))])
>> subplot(1,1,1);mstem(X2k8)
>> title('(c) 8点DFT[X_2(n)]');
>> axis([0,2,0,1.2*max(abs(X2k8))])
>> subplot(1,1,1);mstem(X2k16)
>> title('(d) 16点DFT[x_2(n)]');
>> axis([0,2,0,1.2*max(abs(X2k16))])
>> subplot(1,1,1);mstem(X3k8);
>> title('(e) 8点DFT[x_3(n)]');
>> axis([0,2,0,1.2*max(abs(X3k8))])
>> subplot(1,1,1);mstem(X3k16);
>> title('(f) 16点DFT[x_3(n)]');
>> axis([0,2,0,1.2*max(abs(X3k16))])
2.周期序列谱分析:
>> N=8;n=0:N-1;
>> x4n=cos(pi*n/4);
>> x5n=cos(pi*n/4)+cos(pi*n/8);
>> X4k8=fft(x4n);
>> x5k8=fft(x5n);
>> N=16;n=0:N-1;
>> x4n=cos(pi*n/4);
>> x5n=cos(pi*n/4)+cos(pi*n/8);
>> X4k16=fft(x4n);
>> x5k16=fft(x5n);
>> subplot(1,1,1);mstem(X4k8);
>> title('(g) 8点DFT[x_4(n)]');
>> axis([0,2,0,1.2*max(abs(X4k8))])
>> subplot(1,1,1);mstem(X4k16);
>> title('(h) 16点DFT[x_4(n)]');
>> axis([0,2,0,1.2*max(abs(X4k16))])
>> subplot(1,1,1);mstem(X5k8);
Undefined function or variable 'X5k8'.
>> subplot(1,1,1);mstem(x5k8);
>> title('(i) 8点DFT[x_5(n)]');
>> axis([0,2,0,1.2*max(abs(x5k8))])
>> subplot(1,1,1);mstem(X5k16);
Undefined function or variable 'X5k16'.
>> subplot(1,1,1);mstem(x5k16);
>> title('(j) 16点DFT[x_5(n)]');
>> axis([0,2,0,1.2*max(abs(x5k16))])
3.模拟周期信号谱分析:
>> Fs=64;T=1/Fs;
>> N=16;n=0:N-1;
>> x6nT=cos(8*pi*n*T)+cos(16*pi*n*T)+cos(20*pi*n*T);
>> X6k16=fft(x6nT);
>> X6k16=fftshift(X6k16);
>> Tp=N*T;F=1/Tp;
>> k=-N/2:N/2-1;fk=k*F;
>> subplot(1,1,1);stem(fk,abs(X6k16),'.');box on
>> title('(a) 16点|DFT[x_6(nT)]|');xlabel('f(Hz)');ylabel('幅度'); >> axis([-N*F/2-1,N*F/2-1,0,1.2*max(abs(X6k16))])
>> N=32;n=0:N-1;
>> x6nT=cos(8*pi*n*T)+cos(16*pi*n*T)+cos(20*pi*n*T);
>> X6k32=fft(x6nT);
>> X6k32=fftshift(X6k32);
>> Tp=N*T;F=1/Tp;
>> k=-N/2:N/2-1;fk=k*F;
>> subplot(1,1,1);stem(fk,abs(X6k32),'.');box on
>> title('(b) 32点|DFT[x_6(nT)]|');xlabel('f(Hz)');ylabel('幅度'); >> axis([-N*F/2-1,N*F/2-1,0,1.2*max(abs(X6k32))])
>> N=64;n=0:N-1;
>> x6nT=cos(8*pi*n*T)+cos(16*pi*n*T)+cos(20*pi*n*T);
>> X6k64=fft(x6nT);
>> X6k64=fftshift(X6k64);
>> Tp=N*T;F=1/Tp;
>> k=-N/2:N/2-1;fk=k*F;
>> subplot(1,1,1);stem(fk,abs(X6k64),'.');box on
>> title('(c) 64点|DFT[x_6(nT)]|');xlabel('f(Hz)');ylabel('幅度'); >> axis([-N*F/2-1,N*F/2-1,0,1.2*max(abs(X6k64))])
二程序运行结果:
实验三 IIR数字滤波器设计与软件实现
一实验程序:
>> Fs=10000;T=1/Fs;
>> st=mstg;
N =
1600
1.低通滤波器设计与实现:
>> fp=280;fs=450;
>> 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);
>> y1t=filter(B,A,st);
>> subplot(3,1,1);
>> myplot(B,A);
>> yt='y_1(t)';
>> subplot(3,1,2);tplot(y1t,T,yt);
2.带通滤波器设计与实现:
>> fp1=440;fpu=560;fs1=275;fsu=900;
>> wp=[2*fp1/Fs,2*fpu/Fs];ws=[2*fs1/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);
>> subplot(3,1,1);
>> myplot(B,A);
>> yt='y_2(t)';
>> subplot(3,1,2);tplot(y2t,T,yt)
3.高通滤波器设计与实现:
>> 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);
>> subplot(3,1,1);myplot(B,A);
>> yt='y_3(t)';
>> subplot(3,1,2);tplot(y3t,T,yt)
二实验程序运行结果:
图(1) 三路调幅信号s(t)的时域波形和幅频特性曲线
图(2) 低通滤波器损耗函数及其分离出的调幅信号y1(t) 图(3) 带通滤波器损耗函数及其分离出的调幅信号y2(t)
图(4) 高通滤波器损耗函数及其分离出的调幅信号y3(t) N=1000时不能得到6根理想谱线:
N=2000时可以得到6根理想谱线:
实验四 FIR数字滤波器设计与软件实现一实验程序:
1.用窗函数法设计滤波器:
>> N=1000;xt=xtg(N);
>> fp=120;fs=150;Rp=0.2;As=60;Fs=1000;
>> wc=(fp+fs)/Fs;
>> B=2*pi*(fs-fp)/Fs;
>> Nb=ceil(11*pi/B);
>> hn=fir1(Nb-1,wc,blackman(Nb));
>> Hw=abs(fft(hn,1024));
>> ywt=fftfilt(hn,xt,N);
>> rs=60;a=1;mpplot(hn,a,rs)
2.用等波纹最佳逼近法设计滤波器:
>> fb=[fp,fs];m=[1,0];
>> dev=[(10^(Rp/20)-1)/(10^(Rp/20)+1),10^(-As/20)]; >> [Ne,fo,mo,W]=remezord(fb,m,dev,Fs);
>> hn=remez(Ne,fo,mo,W);
>> Hw=abs(fft(hn,1024));
>> yet=fftfilt(hn,xt,N);
>> subplot(2,1,1)
>> mfftplot(hn,1000)
>> yn='hn';tstem(hn,yn)
>> yn='hn';A=1;myplot(hn,A)
二实验程序运行结果:
附录实验中用到的特殊绘图函数
1.时域序列离散波形绘制函数tstem:
function tstem(xn,yn)
%时域序列绘图函数
% xn:信号数据序列,yn:绘图信号的纵坐标名称(字符串)
n=0:length(xn)-1;
stem(n,xn,'.');box on
xlabel('n');ylabel(yn);
axis([0,n(end),min(xn),1.2*max(xn)])
2.Xk的离散幅频特性绘制函数mstem:
function mstem(Xk)
M=length(Xk);
k=0:M-1;wk=2*k/M; %产生M点DFT的采样点频率
stem(wk,abs(Xk),'.');box on%绘制M点DFT的幅频特性图
xlabel('w/pi');ylabel('幅度');axis([0,2,0,1.2*max(abs(Xk))]) 3.交换函数fftshift:
function [f, sf]=FFT_SHIFT(t, st)
%This function is FFT to calculate a signal’s Fourier transform %Input: t: sampling time , st : signal data. Time length must greater thean 2
%output: f : sampling frequency , sf: frequen
%output is the frequency and the signal spectrum
dt=t(2)-t(1);
T=t(end);
df=1/T;
N=length(t);
f=[-N/2:N/2-1]*df;
sf=fft(st);
sf=T/N*fftshift(sf);
4.信号产生函数mstg:
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(3,1,1)
plot(t,st);grid;xlabel('t/s');ylabel('s(t)');
axis([0,Tp/8,min(st),max(st)]);title('(a) s(t)的波形');
subplot(3,1,2)
stem(f,abs(fxt)/max(abs(fxt)),'.');grid;title('(b) s(t)的频谱') axis([0,Fs/5,0,1.2]);
xlabel('f/HZ');ylabel('幅度')
5.时域离散系统损耗函数的绘制函数:myplot
function myplot(B,A)
[H,W]=freqz(B,A,1000);
m=abs(H);
plot(W/pi,20*log10(m/max(m)));grid on;
xlabel('\omega/\pi');ylabel('幅度(dB)')
axis([0,1,-80,5]);title('损耗函数曲线');
6.时域序列连续曲线的绘制函数:tplot
function tplot(xn,T,yn)
n=0:length(xn)-1;t=n*T;
plot(t,xn);
xlabel('t/s');ylabel(yn);
axis([0,t(end),min(xn),1.2*max(xn)]);
7.序列向量xn的N点fft并绘制其幅频特性曲线的绘图函数mfftplot:
function mfftplot(xn,N)
Xk=fft(xn,N);
k=0:N-1;wk=2*k/N;
m=abs(Xk);mm=max(m);
plot(wk,m/mm);grid on;
xlabel('\omega/\pi');ylabel('幅度(dB)');
axis([0,2,0,1.2]);title('低通滤波器幅频特性曲线')
8.时域离散系统损耗函数和相频特性函数的绘图函数:mpplot:
function mpplot(B,A,Rs)
if nargin<3 ymin=-80;else ymin=-Rs-20;end;
[H,W]=freqz(B,A,1000);
m=abs(H);p=angle(H);
subplot(2,1,1);
plot(W/pi,20*log10(m/max(m)));grid on;
xlabel('\omega/\pi');ylabel('幅度(dB)')
axis([0,1,ymin,5]);title('低通滤波器幅频特性曲线')
subplot(2,1,2);
plot(W/pi,p/pi);
xlabel('\omega/\pi');ylabel('y_w(t)/\pi');grid on;
title('滤除噪声后的信号波形')
9.信号产生函数xtg:
function xt=xtg(N)
N=2000;Fs=1000;T=1/Fs;Tp=N*T;
t=0:T:(N-1)*T;
fc=Fs/10;f0=fc/10;
mt=cos(2*pi*f0*t);
ct=cos(2*pi*fc*t);
xt=mt.*ct;
nt=2*rand(1,N)-1;
fp=150;fs=200;Rp=0.1;As=70;
fb=[fp,fs];m=[0,1];
dev=[10^(-As/20),(10^(Rp/20)-1)/(10^(Rp/20)+1)];
[n,fo,mo,W]=remezord(fb,m,dev,Fs);
hn=remez(n,fo,mo,W);
yt=filter(hn,1,10*nt);
xt=xt+yt; %噪声加信号
fst=fft(xt,N);k=0:N-1;f=k/Tp;
subplot(3,1,1);plot(t,xt);grid;xlabel('t/s');ylabel('x(t)');
axis([0,Tp/5,min(xt),max(xt)]);title('(a) 信号加噪声波形')
subplot(3,1,2);plot(f,abs(fst)/max(abs(fst)));grid;title('(b) 信号加噪声的频谱')
axis([0,Fs/2,0,1.2]);xlabel('f/Hz');ylabel('幅度')
现代信号处理技术上机实验报告
姓名:常鸿斌
学号:09250418
班级:通信工程四班。