重庆大学数字信号处理实验2th
%8.2.1 n=0:100;
s1=cos(2*pi*0.05*n); s2=cos(2*pi*0.47*n); x=s1+s2; m=2;
num=ones(1,m);
y=filter(num,m,x); clf;
subplot(2,2,1);plot(n,s1); axis([0,100,-2,2]);
xlabel('Time index n');ylabel('Amplitude' ); title('s1' );
subplot(2,2,2);plot(n,s2); axis([0,100,-2,2]);
xlabel('Time index n');ylabel('Amplitude' ); title('s2' );
subplot(2,2,3);plot(n,x); axis([0,100,-2,2]);
xlabel('Time index n');ylabel('Amplitude' ); title(' 输入信号x=s1+s2'); subplot(2,2,4);plot(n,y); axis([0,100,-2,2]);
xlabel('Time index n');ylabel('Amplitude' ); title(' 输出信号y' );
s1
2
2
1
0-1-20
50100Time index n输入信号x=s1+s2
1
0-1-20
s2
A m p l i t u d e
A m p l i t u d e
50
Time index n输出信号y
100
22
A m p l i t u d e
0-1-20
50
Time index n
100
A m p l i t u d e
1
1
0-1-20
50
Time index n
100
%8.2.2 n=0:40; a=2;b=-3;
x1=cos(2*pi*0.12*n); x2=cos(2*pi*0.45*n); x=a*x1+b*x2; num=[1 1 1]/3; den=1; ic=[1 0];
y1=filter(num,den,x1,ic); y2=filter(num,den,x2,ic); y=filter(num,den,x,ic); yt=a*y1+b*y2; d=y-yt;
subplot(3,1,1);stem(n,y); ylabel('Amplitude' );
title(' 系统在a*x_{1}(n)+b*x_{2}(n)作用下输出y(n)'); subplot(3,1,2);stem(n,yt); ylabel('Amplitude' );
title(' 输出的线性组合:a*y_{1}(n)+b*y_{2}(n)'); subplot(3,1,3);stem(n,d);
xlabel('Time index n');ylabel('Amplitude' ); title('y(n)-[a*y_{1}(n)+b*y_{2}(n)]');
A m p l i t u d e
系统在a*x1(n)+b*x2(n)作用下输出y(n)
5
1015202530输出的线性组合:a*y1(n)+b*y2(n)
35
40
A m p l i t u d e
5
10
152025y(n)-[a*y1(n)+b*y2(n)]
30
35
40
A m p l i t u d e
Time index n
%8.2.3 n=0:40; n0=5;
x1=cos(2*pi*0.12*n); x2=cos(2*pi*0.45*n); x=x1+x2;
num=[1 1 1]/3; den=1; ic=[0 0];
y1=filter(num,den,x,ic);
T[x(n-n0)]
y=[zeros(1,n0) y1]; xt=[zeros(1,n0) x];
yt=filter(num,den,xt,ic) d=y-yt
subplot(3,1,1) stem(yt);
title('T[x(n-n0)]'); subplot(3,1,2) stem(y);
title('y(n-n0)'); subplot(3,1,3) stem(d);
title('y(n-n0)-T[x(n-n0)]')
20
-220
-210
-1
01020
y(n-n0)
304050
010
2030y(n-n0)-T[x(n-n0)]
4050
0102030冲激响应
4050
%8.2.4 n=0:25; m=1;
num=[0.3 -0.2 0.4]; x=[1 0 0 0];
y=filter(num,m,x); y=[y,zeros(1,22)];
subplot(411),stem(n,y);title(' 冲激响应' ); axis([ 0 6 -1 1]); x=[1 2 3 4 ];
y=filter(num,m,x); y=[y,zeros(1,22)];
subplot(412),stem(n,y);axis([ 0 10 -1 2]); title(' 使用filter 求解零状态响应' );
24
使用filter 求解零状态响应
6
n=0:25; m=1;
num=[0.3 -0.2 0.4]; x=[1 0 0 0 ];
y=filter(num,m,x) length(y);
y1=[y,zeros(1,22)] plot(n,y1);
x=[1 2 3 4 zeros(1,22)]; y1=conv(x,y1); a=length(y1); n=0:(a-1);
subplot(413),stem(n,y1);axis([0 10 -1 2]); title(' 使用conv 求解零状态响应(未截取)' ); y2=[y1(1:4) zeros(1,length(n)-4)];
subplot(414),stem(n,y2);axis([0 10 -1 2]); title(' 使用conv 求解零状态响应(截取)' );
0510
使用conv 求解零状态响应(未截取)0510
使用conv 求解零状态响应(截取)0510
冲激响应
21
0-121
0-121
0-10
5
10
15
510
零状态响应(截取)
15
510
零状态响应(未截取)
15
f=[0.3 -0.2 0.4]; g=[1 0.5 0]; y=impz(f,g,50);
subplot(311),stem(y);title('³å¼¤ÏìÓ¦') axis([0 15 -1 2]); x=[1 2 3 4]; y1=conv(x,y);
subplot(312),stem(y1);title('Áã״̬ÏìÓ¦£¨Î´½ØÈ¡£') axis([0 15 -1 2]);
y2=[y1(1:4)' zeros(1,length(y1)-4)];
subplot(313),stem(y2);title('Áã״̬ÏìÓ¦£¨½ØÈ¡)') axis([0 15 -1 2]);
%8.2.5 n=0:100;
s1=cos(2*pi*0.05*n); s2=cos(2*pi*0.47*n);
x=s1+s2;num=ones(1,5); M=2;
y=filter(num,M,x); y=[y zeros(1,5)]; for n=0:100;k=-M:-1;
y1(1,n+1)=sum(y(n+1:n-k)); n=n+1;end ;
y1=[y1 zeros(1,5)]; y2=[y+y1];n=0:100;
subplot(2,2,1); plot(n,s1);
axis([0,100,-2,2]); title('s1' ); subplot(2,2,2); plot(n,s2);
axis([0,100,-2,2]); title('s2' ); subplot(2,2,3); plot(n,x);
axis([0,100,-2,2]); title(' 输入信号x' ); subplot(2,2,4);
plot([0 1 2 3 4 n+5],y2); axis([0,100,-10,10]);title(' 输出信号y2' );
s1
s2
221
1
值
列0值
列0序序-1-1-20
50100
-20
50100
序号n 序号n 输入信号x
输出信号y2
2101
5
值
列0值
列0序序-1-5-20
50100
-100
50100
序号n
序号n