线性常系数差分方程的求解?
已知系统的输入序列,通过求解差分方程可以求出输出序列。求解差分方程的基本方法有以下三种:
? (1) 经典解法。
y(n) = yH(n) + yP(n)
----Homogeneous part: yH(n)
----Particular part: yP(n)
(2) 递推解法。迭代法,卷积和计算法
(3) 变换域方法。Z变换法
递推解法:
已知输入序列和N个初始条件,则可以求出n时刻的输出;如果将该公式中的n用n+1代替,可以求出n+1时刻的输出,因此(1.3.1)式表示的差分方程本身就是一个适合递推法求解的方程。
例1.3.1 设系统用差分方程y(n)=ay(n-1)+x(n)描述,输入序列x(n)=δ(n),求输出序列y(n)。?
解 该系统差分方程是一阶差分方程,需要一个初始条件。?
y = filter (b, a, x)
where
b=[b0,b1,……bM] a=[a0,a1,……aN]
are the coefficient arrays from the equation.
x is the input sequence array.
The output y has the same length as input x.
Note: ensure that the coeffient a0 not be zero.
e.g, y(n)-y(n-1)+0.9y(n-2)=x(n);
Solution
From the given difference equation the coefficient array are:
b=[1];
a=[1,-1,0.9];
%matlab code
a=[1,-1,0.9];
b=1;
% Part a.
x=impseq(0,-20,120);
n=[-20:120];
h=filter(b,a,x);
subplot(2,1,1);
stem(n,h)
axis([-20,120,-1.1,1.1])
title('脉冲响应');
text(125,-1.1,'n');
ylabel('h(n)')
从上边可以看出,使用filter来解差分方程式是非常方便的,
可以在matlab的帮助文件中看出一些信息:
FILTER One-dimensional digital filter.
Y = FILTER(B,A,X) filters the data in vector X with the
filter described by vectors A and B to create the filtered
data Y. The filter is a "Direct Form II Transposed"
implementation of the standard difference equation:
a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
- a(2)*y(n-1) - ... - a(na+1)*y(n-na)
If a(1) is not equal to 1, FILTER normalizes the filter
coefficients by a(1).
FILTER always operates along the first non-singleton dimension,
namely dimension 1 for column vectors and non-trivial matrices,
and dimension 2 for row vectors.
[Y,Zf] = FILTER(B,A,X,Zi) gives access to initial and final
conditions, Zi and Zf, of the delays. Zi is a vector of length
MAX(LENGTH(A),LENGTH(B))-1, or an array with the leading dimension
of size MAX(LENGTH(A),LENGTH(B))-1 and with remaining dimensions
matching those of X.
FILTER(B,A,X,[],DIM) or FILTER(B,A,X,Zi,DIM) operates along the
dimension DIM.
MATLAB Function Reference filter Filter data with an infinite impulse response (IIR) or finite impulse response (FIR) filter Syntaxy = filter(b,a,X)
[y,zf] = filter(b,a,X)
[y,zf] = filter(b,a,X,zi)
y = filter(b,a,X,zi,dim)
DescriptionThe filter function filters a data sequence using a digital filter which works for both real and complex inputs. The filter is a direct form II transposed implementation of the standard difference equation (see "Algorithm"). y = filter(b,a,X) filters the data in vector X with the filter described by numerator coefficient vector b and denominator coefficient vector a. If a(1) is not equal to 1, filter normalizes the filter coefficients by a(1). If a(1) equals 0, filter returns an error. If X is a matrix, filter operates on the columns of X. If X is a multidimensional array, filter operates on the first nonsingleton dimension. [y,zf] = filter(b,a,X) returns the final conditions, zf, of the filter delays. If X is a row or column vector, output zf is a column vector of max(length(a),length(b))-1. If X is a matrix, zf is an array of such vectors, one for each column of X, and similarly for multidimensional arrays. [y,zf] = filter(b,a,X,zi) accepts initial conditions, zi, and returns the final conditions, zf, of the filter delays. Input zi is a vector of length max(length(a),length(b))-1, or an array with the leading dimension of size max(length(a),length(b))-1 and with remaining dimensions matching those of X. y = filter(b,a,X,zi,dim) and [...] = filter(b,a,X,[],dim) operate across the dimension dim
ExampleYou can use filter to find a running average without using a for loop. This example finds the running average of a 16-element vector, using a window size of 5. data = [1:0.2:4]';
windowSize = 5;
filter(ones(1,windowSize)/windowSize,1,data)
ans =
0.2000
0.4400
0.7200
1.0400
1.4000
1.6000
1.8000
2.0000
2.2000
2.4000
2.6000
2.8000
3.0000
3.2000
3.4000
3.6000
[...] = filter(b,a,X,[],dim)