4 利用计算系统的输出

来源:互联网 发布:牛股王 知乎 编辑:程序博客网 时间:2024/05/16 03:37

这里主要介绍滤波函数filter。

比如如果系统函数是

y(n)+0.62y(n-1)+0.13y(n-2)=x(n-2)

输入是x(n)=u(n)-u(n-15)

那么求输出对应的程序是:

n = -5:25;N = 15;step = [n>=0];stepN = [(n-N)>=0];x = step-stepN;b = [0,0,1];a = [1,0.62,0.13];y = filter(b,a,x);[H,W] = freqz(b,a);subplot(3,1,1);stem(n,x);axis([-5 25 0 1]);subplot(3,1,2);plot(W,abs(H));axis([0 pi 0 2]);subplot(3,1,3);stem(n,y);axis([-5 25 -0.5 1]);

输出结果如图:


有些时候,不仅给出了传输函数和输入,也给出了系统的初值条件,这就需要使用filtic函数确定初值条件,再将条件写到filter函数的参数中:

比如LTI系统满足差分方程:

3y(n)-2.85y(n-1)+2.7075y(n-2)=x(n)+x(n-1)+x(n-2)

输入是x(n)=cos(pin/3)u(n)

初值是x(-1)=1,x(-2)=1;y(-1)=-2,y(-2)=-3

那么程序如下:

% 确定系统的幅度响应b = [1,1,1];a = [3,-2.85,2.7075];[H,W] = freqz(b,a);% 计算初值条件Y = [-2,3];X = [1,1];xic = filtic(b,a,Y,X);% 带入filtern = [0:35];x = cos(pi*n/3);y = filter(b,a,x,xic);subplot(3,1,1);stem(n,x);subplot(3,1,2);plot(W,abs(H));subplot(3,1,3);stem(n,y);axis([0 35 -8 8]);

结果如图:



然后计算系统的单位冲击响应h(t),这是通过函数impz来实现的。下面是一个例子:

对于系统函数为y(n)-0.4y(n-1)-0.45y(n-2)=-0.45x(n)-0.4x(n-1)

a = [1,-0.4,-0.45];b = [-0.45,-0.4];N = 60;n = 0:N-1;x = 2*0.9.^n;y = filter(b,a,x);subplot(2,1,1);stem(n,x);subplot(2,1,2);stem(n,y);figure;[h,t] = impz(b,a,N);stem(t,h);axis([0 30  -0.45 0]);

它的冲击响应如图所示:



0 0
原创粉丝点击