Example
Finding difference equation
Below is a basic example showing the opposite of the steps
above: given a transfer function one can easily calculate thesystems difference equation.
$H(z)=\frac{(z+1)^{2}}{(z-\frac{1}{2})(z+\frac{3}{4})}$
Given this transfer function of a time-domain filter, we want
to find the difference equation. To begin with, expand bothpolynomials and divide them by the highest order
$z$ .
$H(z)=\frac{(z+1)(z+1)}{(z-\frac{1}{2})(z+\frac{3}{4})}=\frac{z^{2}+2z+1}{z^{2}+2z+1-\frac{3}{8}}=\frac{1+2z^{-1}+z^{-2}}{1+\frac{1}{4}z^{-1}-\frac{3}{8}z^{-2}}$
From this transfer function, the coefficients of the two
polynomials will be our
${a}_{k}()$ and
${b}_{k}()$ values found in the general difference equation
formula,
[link] .
Using these coefficients and the above form of the transferfunction, we can easily write the difference equation:
$x(n)+2x(n-1)+x(n-2)=y(n)+\frac{1}{4}y(n-1)-\frac{3}{8}y(n-2)$
In our final step, we can rewrite the difference equation in
its more common form showing the recursive nature of the system.
$y(n)=x(n)+2x(n-1)+x(n-2)+\frac{-1}{4}y(n-1)+\frac{3}{8}y(n-2)$
Got questions? Get instant answers now!
Solving a lccde
In order for a linear constant-coefficient difference equation
to be useful in analyzing a LTI system, we must be able tofind the systems output based upon a known input,
$x(n)$ , and a set of initial conditions. Two common
methods exist for solving a LCCDE: the
direct
method and the
indirect method , the later
being based on the z-transform. Below we will briefly discussthe formulas for solving a LCCDE using each of these methods.
Direct method
The final solution to the output based on the direct method
is the sum of two parts, expressed in the followingequation:
$y(n)={y}_{h}(n)+{y}_{p}(n)$
The first part,
${y}_{h}(n)$ , is referred to as the
homogeneous
solution and the second part,
${y}_{h}(n)$ , is referred to as
particular
solution . The following method is very similar to
that used to solve many differential equations, so if youhave taken a differential calculus course or used
differential equations before then this should seem veryfamiliar.
Homogeneous solution
We begin by assuming that the input is zero,
$x(n)=0$ .Now we simply need to solve the homogeneous difference
equation:
$\sum_{k=0}^{N} {a}_{k}()y(n-k)=0$
In order to solve this, we will make the assumption that
the solution is in the form of an exponential. We willuse lambda,
$\lambda $ , to
represent our exponential terms. We now have to solve thefollowing equation:
$\sum_{k=0}^{N} {a}_{k}()\lambda ^{(n-k)}=0$
We can expand this equation out and factor out all of thelambda terms. This will give us a large polynomial in
parenthesis, which is referred to as the
characteristic polynomial . The roots of this
polynomial will be the key to solving the homogeneousequation. If there are all distinct roots, then the
general solution to the equation will be as follows:
${y}_{h}(n)={C}_{1}(){\lambda}_{1}()^{n}+{C}_{2}(){\lambda}_{2}()^{n}+\dots +{C}_{N}(){\lambda}_{N}()^{n}$
However, if the characteristic equation contains multiple
roots then the above general solution will be slightlydifferent. Below we have the modified version for an
equation where
${\lambda}_{1}$ has
$K$ multiple
roots:
${y}_{h}(n)={C}_{1}(){\lambda}_{1}()^{n}+{C}_{1}()n{\lambda}_{1}()^{n}+{C}_{1}()n^{2}{\lambda}_{1}()^{n}+\dots +{C}_{1}()n^{(K-1)}{\lambda}_{1}()^{n}+{C}_{2}(){\lambda}_{2}()^{n}+\dots +{C}_{N}(){\lambda}_{N}()^{n}$
Particular solution
The particular solution,
${y}_{p}(n)$ , will be any solution that will solve the
general difference equation:
$\sum_{k=0}^{N} {a}_{k}(){y}_{p}(n-k)=\sum_{k=0}^{M} {b}_{k}()x(n-k)$
In order to solve, our guess for the solution to
${y}_{p}(n)$ will take on the form of the input,
$x(n)$ . After guessing at a solution to the above
equation involving the particular solution, one onlyneeds to plug the solution into the difference equation
and solve it out.
Indirect method
The indirect method utilizes the relationship between the
difference equation and z-transform, discussed
earlier , to find a
solution. The basic idea is to convert the differenceequation into a z-transform, as described
above , to get the
resulting output,
$Y(z)$ .
Then by inverse transforming this and using partial-fractionexpansion, we can arrive at the solution.
$$Z\left\{y,\left(n+1\right),-,y,\left(n\right)\right\}=zY\left(z\right)-y\left(0\right)$$
This can be interatively extended to an arbitrary order derivative as in Equation
[link] .
$$Z\left\{-,\sum _{m=0}^{N-1},y,\left(n-m\right)\right\}={z}^{n}Y\left(z\right)-\sum _{m=0}^{N-1}{z}^{n-m-1}{y}^{\left(m\right)}\left(0\right)$$
Now, the Laplace transform of each side of the differential equation can be taken
$$Z\left\{\sum _{k=0}^{N},{a}_{k},\left[y,\left(n-m+1\right),-,\sum _{m=0}^{N-1},y,\left(n-m\right),y,\left(n\right)\right],=,Z,\left\{x,\left(,n,\right)\right\}\right\}$$
which by linearity results in
$$\sum _{k=0}^{N}{a}_{k}Z\left\{y,\left(n-m+1\right),-,\sum _{m=0}^{N-1},y,\left(n-m\right),y,\left(n\right)\right\}=Z\left\{x,\left(,n,\right)\right\}$$
and by differentiation properties in
$$\sum _{k=0}^{N}{a}_{k}\left({z}^{k},Z,\left\{y,\left(,n,\right)\right\},-,\sum _{m=0}^{N-1},{z}^{k-m-1},{y}^{\left(m\right)},\left(0\right)\right)=Z\left\{x,\left(,n,\right)\right\}.$$
Rearranging terms to isolate the Laplace transform of the output,
$$Z\left\{y,\left(,n,\right)\right\}=\frac{Z\left\{x,\left(,n,\right)\right\}+{\sum}_{k=0}^{N}{\sum}_{m=0}^{k-1}{a}_{k}{z}^{k-m-1}{y}^{\left(m\right)}\left(0\right)}{{\sum}_{k=0}^{N}{a}_{k}{z}^{k}}.$$
Thus, it is found that
$$Y\left(z\right)=\frac{X\left(z\right)+{\sum}_{k=0}^{N}{\sum}_{m=0}^{k-1}{a}_{k}{z}^{k-m-1}{y}^{\left(m\right)}\left(0\right)}{{\sum}_{k=0}^{N}{a}_{k}{z}^{k}}.$$
In order to find the output, it only remains to find the Laplace transform
$X\left(z\right)$ of the input, substitute the initial conditions, and compute the inverse Z-transform of the result. Partial fraction expansions are often required for this last step. This may sound daunting while looking at
[link] , but it is often easy in practice, especially for low order difference equations.
[link] can also be used to determine the transfer function and frequency response.
As an example, consider the difference equation
$$y\left[n-2\right]+4y\left[n-1\right]+3y\left[n\right]=cos\left(n\right)$$
with the initial conditions
${y}^{\text{'}}\left(0\right)=1$ and
$y\left(0\right)=0$ Using the method described above, the Z transform of the solution
$y\left[n\right]$ is given by
$$Y\left[z\right]=\frac{z}{[{z}^{2}+1][z+1][z+3]}+\frac{1}{[z+1][z+3]}.$$
Performing a partial fraction decomposition, this also equals
$$Y\left[z\right]=.25\frac{1}{z+1}-.35\frac{1}{z+3}+.1\frac{z}{{z}^{2}+1}+.2\frac{1}{{z}^{2}+1}.$$
Computing the inverse Laplace transform,
$$y\left(n\right)=(.25{z}^{-n}-.35{z}^{-3n}+.1cos\left(n\right)+.2sin\left(n\right))u\left(n\right).$$
One can check that this satisfies that this satisfies both the differential equation and the initial conditions.