# 数字信号处理matlab——系统响应和系统稳定

### 例一

y(n)=0.05x(n)+0.05x(n-1)+0.9y(n-1)

``````clc
close all;
clear all;
A=[1,-0.9];
B=[0.05,0.05];
xn=[ones(1,8),zeros(1,42)];
n=0:length(xn)-1;
[hn,n]=impz(B,A,length(xn));
yn=filter(B,A,xn);
figure
subplot(2,1,1);
xlabel('n');
ylabel('y(n)');
stem(n,yn,'.');
axis([0,length(n),min(yn),1.2*max(yn)]);
title('System response to R8(n)');

subplot(2,1,2);
xlabel('n');
ylabel('h(n)');
stem(n,hn,'.');
axis([0,length(n),min(hn),1.2*max(hn)]);
title('System unit impulse response');
``````

### 例二

y(n)=0.05x(n)+0.05x(n-1)+0.9y(n-1)

``````clc
close all;
clear all;
A=[1,-0.9];
B=[0.05,0.05];
xn=ones(1,100);
n=0:length(xn)-1;
[hn,n]=impz(B,A,length(xn));
yn=filter(B,A,xn);
figure
subplot(2,1,1);
xlabel('n');
ylabel('y(n)');
stem(n,yn,'.');
axis([0,length(n),min(yn),1.2*max(yn)]);
title('System response to u(n)');

subplot(2,1,2);
xlabel('n');
ylabel('h(n)');
stem(n,hn,'.');
axis([0,length(n),min(hn),1.2*max(hn)]);
title('System unit impulse response');
``````

### 例三

``````clc
close all;
clear all;
xn=ones(1,8);
n=0:length(xn)-1;
figure
subplot(3,1,1);
stem(n,xn,'.');
xlabel('n');
ylabel('xn');
axis([0,30,0,1.2*max(xn)]);

hn=[ones(1,10),zeros(1,10)];
m=0:length(hn)-1;
subplot(3,1,2);
stem(m,hn,'.');
xlabel('m');
ylabel('hn');
axis([0,30,0,1.2*max(hn)]);

yn=conv(hn,xn)
l=0:length(xn)+length(hn)-2;
subplot(3,1,3);
stem(l,yn,'.');
xlabel('l');
ylabel('yn');
axis([0,30,0,1.2*max(yn)]);

``````

### 例四

``````clc
close all;
clear all;
xn=ones(1,8);
n=0:length(xn)-1;
figure
subplot(3,1,1);
stem(n,xn,'.');
xlabel('n');
ylabel('xn');
axis([0,20,0,1.2*max(xn)]);

hn=[1,2.5,2.5,1,zeros(1,6)];
m=0:length(hn)-1;
subplot(3,1,2);
stem(m,hn,'.');
xlabel('m');
ylabel('hn');
axis([0,20,0,1.2*max(hn)]);

yn=conv(hn,xn)
l=0:length(xn)+length(hn)-2;
subplot(3,1,3);
stem(l,yn,'.');
xlabel('l');
ylabel('yn');
axis([0,20,0,1.2*max(yn)]);

``````

### 例五

``````y(n)=1.8237y(n-1)-0.9801y(n-2)+1/100.49x(n)-1/100.49x(n-2)
``````

``````clc
close all;
clear all;
un=ones(1,256);
n=0:length(un)-1;
A=[1,-1.8237,0.9801];
B=[1/100.49,0,-1/100.49];
yn=filter(B,A,un);
figure
stem(n,yn,'.');
xlabel('n');
ylabel('yn');
axis([0,length(un),1.2*min(yn),1.2*max(yn)]);

``````

### 例六

``````y(n)=1.8237y(n-1)-0.9801y(n-2)+1/100.49x(n)-1/100.49x(n-2)
``````

``````clc
close all;
clear all;
n=0:256;
xn=sin(0.014*n)+sin(0.4*n);
A=[1,-1.8237,0.9801];
B=[1/100.49,0,-1/100.49];
yn=filter(B,A,xn);
figure
stem(n,yn,'.');
xlabel('n');
ylabel('yn');
axis([0,length(n),1.2*min(yn),1.2*max(yn)]);

``````

1.通过差分方程求得系统输出，需要初始条件，是否是零输入响应
2.已知系统单位脉冲响应，通过求输入信号和系统单位脉冲响应的线性卷积求得系统输出

原文作者：dqw~
原文地址: https://blog.csdn.net/weixin_41129832/article/details/118405258
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。