% 1,已知系统:y[n]+0.1y[n-1]-0.3y[n-2]=x[n]-2x[n-1]+0.3x[n-2],
% 计算信号sin(2*pi*0.2*n)通过该系统的响应
n = 0:50; x = sin(2*pi*0.2*n) ;
num = [1 -2 0.3]; den = [1 0.1 -0.3]; ic = [0
0];
y = filter(num,den,x,ic);
subplot(3,3,1); stem(n,x); xlabel('Time index n'); ylabel('Amplitude'); title('Input
x[n]');
axis([0 20 -1 1]);
subplot(3,3,2); stem(n,y);
xlabel('Time index n'); ylabel('Amplitude'); title('Output
y[n]');
axis([0 20 -2 2]);
也就是求x通过这个系统,得到的y。filter是滤波的意思,那也就是说,通过这个差分方程的分子分母,也就是系数,可以得到一个相应的滤波器,然后结合x,就能得到y了。
% 2,已知系统y[n]=nx[n],
%用信号x1[n]=cos(2*pi*0.2*n)和x2=cos(2*pi*0.6*n)判断系统的线性
a = 2; b =
-3;
x1 = cos(2*pi*0.2*n); x2 =
cos(2*pi*0.6*n);
x12 = a*x1 + b*x2;
y1=n.*x1; y2=n.*x2;
y12=n.*x12; yt = a*y1 +
b*y2; d1 = y12 - yt;
subplot(3,3,4); stem(n,y12);
xlabel('Time index n'); ylabel('Amplitude');
title('n\cdot(a \cdot x_{1}[n] + b \cdot x_{2}[n])');
axis([0 20 -100 100]);
subplot(3,3,5); stem(n,yt);
xlabel('Time index n'); ylabel('Amplitude');
title('a \cdot y_{1}[n] + b \cdot y_{2}[n]');
axis([0 20 -100 100]);
subplot(3,3,6); stem(n,d1); xlabel('Time index n'); ylabel('Amplitude'); title('Difference
Signal');
axis([0 20 -100 100]);
根据图形的显示,得到结论:该系统是线性系统。
并且由这题,又知道了一些注释的表示方法:\cdot,这个表示一个点,相乘的意思;_{1}[是下标的意思;
这题没用到什么特别的函数,主要的式子的验证。
%3,用信号x3=cos(2*pi*0.1*n)判断上题系统的是不变性,D = 5。
D = 5; n1=-5:50;
x3 = cos(2*pi*0.1*n); xd = [zeros(1,D) x3];
y3 =
n.*x3; yd = n1.*xd;
d2 = y3 - yd(1:51);
subplot(3,3,7); stem(n,y3);
xlabel('Time index n'); ylabel('Amplitude'); title('Output y[n]');
subplot(3,3,8);stem(n,yd(1:51));
xlabel('Time index n'); ylabel('Amplitude'); title('Output due to Delayed');
subplot(3,3,9); stem(n,d2); xlabel('Time index n'); ylabel('Amplitude'); title('Difference
Signal');
根据图形,结论:该系统是时变系统,因为相减之后不为零。其实,我们一开始就可以根据y[n]=nx[n]知道这是时变系统了,因为还要乘以一个n的关系。
时不变,就是时间改变,但响应依然不变。这题就用zeros补零,使激励有时移。
做这题时,一定要注意取值,要坚持长度对应的原则。
% 由于图比例较小,为了使波形清晰,1、2题只取前20个样本画出