Sin categoría

Digital Filters – FIR and IIR Filters – MA Filters – Examples

Filter is a generic name that means a linear time-invariant system designed for a specific job of frequency selection or frequency discrimination. Hence discrete-time LTI systems are also called digital filters. There are two types of digital filters: FIR Filters and IIR Filters.


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

La imagen tiene un atributo ALT vacío; su nombre de archivo es image-75.png

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 equation (1) is:

La imagen tiene un atributo ALT vacío; su nombre de archivo es image-49.png
FIR Filter

If the unit impulse response of an LTI system is of finite duration, the system is called a finite-duration impulse response (or FIR) filter.  Hence for a FIR filter h[n]=0 for n<n1 and for n>n2. The following part of the difference equation (2) describes a causal FIR filter:

Furthermore, h[0]=bo , h[1]=b1 ,… h[M]=bM . while all the other h[n]’s are 0. FIR filters are also called non-recursive or moving average (MA) filters. In Matlab FIR filters are represented either as impulse response values {h[n]} or as difference equation coefficients {bm} and {a0 =1}. Therefore, to implement FIR filters in Matlab, we can use either the conv(x,h) function, or the filter(b,1,x) function. See the following example:

Example 1. 

Let the following rectangular pulse x[n] be an input to an LTI system with impulse response h[n]:

Determine the output y[n] of the system.


In Elementary sequences we have implemented the function stepseq for plotting the unit step function in discrete time, or any combination as example 1. Next Script allows plotting x[n].

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

Figure 1. Input sequence x[n], example 1.

Next Script allows plotting h[n].

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

Figure 2. Impulse response h[n] for system in example 1.

Now, we use conv Matlab function to determine y[n]:

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

Figure 3. Output sequence y[n]=x[n]*h[n] for example 1.

Another approach is by using the filter function:

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

What yields:

Figure 4. Output sequence y[n]=x[n]*h[n] for example 1.

There is a difference in the outputs of these two implementations that should be noted. As you can see in Figure 3, the output sequence from conv(x,h) function has a longer length than both x[n] and h[n] sequences. On the other hand, the output sequence from the filter(h,1,x) function in Figure 4 has exactly the same length as the input x[n] sequence. In practice, the use of the filter function is encouraged.

Watch out: The filter function can be used to compute the convolution indirectly. That was possible because of the impulse response in example 1 was a one-side exponential sequence for wich we could determine a difference equation representation. Not all infinite-lenght impulse responses can be converted into difference equations.

IIR Filter

If the impulse response of an LTI system is of infinite duration, then the system is called an infinite-duration impulse response (or IIR) filter. The following part of the difference equation (2):

Describes a recursive filter in which the output y[n] is recursively computed from its previously computed values and is called an autoregressive (AR) filter. The impulse response of such filter is of infinite duration and hence it represents and IIR filter. The general equation (2) also describes an IIR filter. It has two parts: an AR part and a MA part. Such an IIR filter is called an autoregressive moving average, or an ARMA filter. In Matlab, IIR filters are described by the difference equation coefficients {bm} and {ak} and are implemented by the filter(b,a,x) function. See the following example:

Example 2

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.

Related: Solving discrete-time differential equations with Matlab


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

You can also be interested in:

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



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