An LTI discrete system can also be described by a linear constant coefficient difference equation of the form:

This equation describes a recursive approach for computing the current output, given the input values and previously computed output values. In practice, this equation is computed forward in time, from n=-∞ to n=∞. Therefore, another form of this equation is:

A solution to equation (2) can be obtained in the form:

The homogeneous part yh[n] is given by:

Where zk, k=1,…,N are N roots (also called natural frequencies) of the characteristic equation:

This characteristic equation is important in determining the stability of the system. If roots zk satisfy the condition:

Then a casual system described by equation (2) is stable. The particular part of the solution, yp[n], is determined from the right-hand side of equation (1), where we will use z-transform for solving the difference equation.
Matlab solving
A function called filter in available in Matlab to solve Discrete-Time difference equations, given the input and the difference equation coefficients. In its simplest form it is invoked by:
y=filter(b,a,x)
Where b and a are the coefficient arrays from the equation (1), and x is the input sequence array. One must ensure that the coefficient a0 not be zero.
To compute and plot impulse response, Matlab also provides the function impz:
h=impz(b,a,n);
It computes samples of the impulse response of the filter at the sample indices given in n with numerator coefficients in b and denominator coefficients in a.
Example 1.
Given the following difference equation:

- Calculate and plot the impulse response h[n] at n=-20,…,100
- Calculate and plot the unit step response s[n] at n=-20,…,100
- Is the system specified by h[n] stable?
Solution:
- To determine h[n] we use the following script:
n=[-20:120];
a=[1,-1,0.9];
b=[1];
h=impz(b,a,n);
stem(n,h)
grid
xlabel(‘n’); ylabel(‘h[n]’)
The script yields:

- 2. To determine s[n] we use the following script:
n=[-20:120];
a=[1,-1,0.9];
b=[1];
x=stepseq(0,-20,120);
s=filter(b,a,x);
stem(n,s)
xlabel(‘n’); ylabel(‘s[n]’);
The script yields:

- Is the system specified by h[n] stable?
From Figure 1 we see that h[n] is practically zero n>120. Hence the sum:

Can be determined with the following script:
sum(abs(h))
This yields:
ans = 14.8785
That is to say:

This result implies that the system is stable. An alternate approach is to use the stability condition of the roots:
z=roots(a);
magz=abs(z)
magz =
0.9487 0.9487
Since the magnitude of both roots are less than one, the system is stable.
Actually, there are two forms of solving a linear constant coefficient difference equation: finding the particular and the homogeneous solutions; finding the zero-input and the zero-state responses. It is by using the z-transform that we can derive a method to obtain both.
Finding the particular and the homogeneous solutions
In construction…
Working with initial conditions – The zero-input and the zero-state responses.
In Matlab another form of the function filter can be used to solve for the differential equation, given its initial conditions.
In construction…
Related: Digital Filters – Moving Average Filters
You could be also interested in:
- What is DSP ?- Digital Signal Processing
- Matlab code for DSP – Introduction
- Elementary sequences in Digital Signal Processing (Versión en Español)
- The Geometric Series in DSP (Versión en Español)
- The sinusoidal function in discrete-time (Versión en Español)
- Convolution in Discrete-Time in Matlab (Versión en Español)
- Digital Filters – Moving Average Filters (Versión en Español)
- The Discrete-Time Fourier Transform (Versión en Español)
Source:
- Digital Signal Processing Using Matlab, 3erd ed
- Fundamentos_de_Señales_y_Sistemas_usando la Web y Matlab
- Oppenheim – Señales y Sistemas
- Análisis de Sistemas Lineales Asistido con Scilab – Un Enfoque desde la Ingeniería Eléctrica.
Literature review by:
Prof. Larry Francis Obando – Technical Specialist – Educational Content Writer
Exercises are solved!!
WhatsApp: +34633129287 Inmediate Attention!!
Copywriting, Content Marketing, Tesis, Monografías, Paper Académicos, White Papers (Español – Inglés)
Escuela de Ingeniería Electrónica de la Universidad Simón Bolívar, USB Valle de Sartenejas.
Escuela de Ingeniería Eléctrica de la Universidad Central de Venezuela, UCV Caracas.
Escuela de Turismo de la Universidad Simón Bolívar, Núcleo Litoral.
Contacto: España. +34633129287
Caracas, Quito, Guayaquil, Jaén.
WhatsApp: +34633129287
FACEBOOK: DademuchConnection
email: dademuchconnection@gmail.com
11 comentarios sobre “Solving discrete-time differential equations with Matlab”