Sin categoría

Solving discrete-time differential equations with Matlab

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:


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:


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:

  1. Calculate and plot the impulse response h[n] at n=-20,…,100
  2. Calculate and plot the unit step response s[n] at n=-20,…,100
  3. Is the system specified by h[n] stable?


  1. To determine h[n] we use the following script:

xlabel(‘n’); ylabel(‘h[n]’)

The script yields:

Figure 1. Impulse response h[n] for example 1.
  1. 2. To determine s[n] we use the following script:

xlabel(‘n’); ylabel(‘s[n]’);

The script yields:

Figure 2. Step response s[n] for example 1.
  1. 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:


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:


magz =


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:


  • 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!!

Twitter: @dademuch

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   

Twitter: @dademuch

FACEBOOK: DademuchConnection


11 comentarios en “Solving discrete-time differential equations with Matlab”


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s