离散线性时不变系统实验分析
x[n]
h[n]
n
n
y[n]
n 实验2-2a
Input Sequence
]
n
[x Input Response
]
n [h Output Sequence
]
n [1
y n
实验2-2b
Input Sequence
]
n [x
]
5+n [h Output Sequence
]
n [2y n
注释:以下函数为第二次实验公用函数 % conv_m子函数
function[y,ny]=conv_m(x,nx,h,nh) if nargin~=4 disp('Ussage:Y=conv_m(x,nx,h,nh)'); return;end;
nyb=nx(1)+nh(1);nye=nx(length(x))+nh(length(h)); ny=[nyb:nye];y=conv(x,h);
% stepseq 子函数
function [x,n]=stepseq(n0,n1,n2) if nargin~=3 disp('Usage:Y=stepseq(n0,n1,n2)');return; elseif((n0n2|n1>n2)
error('arguments must satisfy n1
n=[n1:n2];x=[(n-n0)>=0];
===============================================
% 实验2-1
clear;clf;clc;n=[-5:20];
h=delta(n-5);x=stepseq(0,-5,20)-stepseq(5,-5,20);
[y,ny]=conv_m(x,n,h,n)
subplot(2,2,1);stem(n,x);title('x[n]');xlabel('n');axis([-5,20,0,1.2]);grid on;
subplot(2,2,2);stem(n,h);title('h[n]');xlabel('n');axis([-5,20,0,1.2]);grid on;
subplot(2,2,3);stem(ny,y);title('y[n]');xlabel('n');axis([-5,20,0,1.2]);grid on; % delta 子函数
function y=delta(x) y=(x==0);
=============================================== % 实验2-2a
n=-5:20;u1=stepseq(0,-5,20);u2=stepseq(6,-5,20); x=u1-u2;h=n.*x;subplot(3,1,1);stem(n,x);
axis([-5,20,0,2]);title('Imput Sequence');
ylabel('x[n]');subplot(3,1,2);stem(n,h);axis([-5,20,0,6]);
title('Impuse Response');ylabel('h[n]');
[y1,ny]=conv_m(x,n,h,n);ubplot(3,1,3);stem(ny,y1); title('Output Sequence');xlabel('n');ylabel('y_1[n]'); % 实验2-2b
n=-10:20;u1=stepseq(0,-10,20);u2=stepseq(6,-10,20); x=u1-u2;u3=stepseq(-5,-10,20);u4=stepseq(1,-10,20); x1=u3-u4;h=(n+5).*x1;subplot(3,1,1);stem(n,x); axis([-10,20,0,2]);title('Input Sequence');ylabel('x[n]');
subplot(3,1,2);stem(n,h);axis([-10,20,0,6]); title('Impulse Response');ylabel('h[n+5]');
[y2,ny]=conv_m(x,n,h,n);subplot(3,1,3);stem(ny,y2);
title('Output Sequence');xlabel('n');ylabel('y_2[n]');
Input Sequence
]
n [x Impulse Sequence
]
n [h Output Sequence
]
n [2
y n
实验2-4
n ]
h [n Step Response
n ]
[s n
% 实验2-3 n=-5:50;
u1=stepseq(0,-5,50);u2=stepseq(10,-5,50); x=u1-u2;h=((0.9).^n).*u1;
subplot(3,1,1);stem(n,x);axis([-5,50,0,2]);title('Imput Sequence');ylabel('x[n]');
subplot(3,1,2);stem(n,h);axis([-5,50,0,2]);
title('Impulse Responce');ylabel('h[n]'); [y,ny]=conv_m(x,n,h,n);
subplot(3,1,3);stem(ny,y);
title('Output Sequence');xlabel('n');ylabel('y[n]');
=============================================== % 实验2-4
a=[1,-0.8];b=1; n=[-10:50];n1=[-10:0.5:50];
x=impseq(0,-10,50);h=filter(b,a,x);
subplot(2,1,1);stem(n,h);title('Impulse Response'); xlabel('n');ylabel('h[n]'); x=stepseq(0,-20,100); s=filter(b,a,x);
subplot(2,1,2);stem(n1,s);title('Step Response'); xlabel('n');ylabel('s[n]'); % impseq 子函数
function[x,n]=impseq(n0,n1,n2) if nargin~=3
disp('Usage:Y=impseq(n0,n1,n2)'); return;
elseif((n0n2)|(n1>n2))
error('arguments must satisfy n1
end n=[n1:n2];
x=[(n-n0)==0];