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.

`Preliminaries`

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

`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=bo , h=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.

Solution:

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

n=[0:40];
x=stepseq(0,0,40)-stepseq(10,0,40);
stem(n,x)
xlabel(‘n’); ylabel(‘x[n]’)

Next Script allows plotting h[n].

n=[0:40];
h=(0.9).^n;
stem(n,h)
xlabel(‘n’); ylabel(‘h[n]’)

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

y=conv(x,h);
n=[0:80];
stem(n,y);
xlabel(‘n’); ylabel(‘y[n]’)

Another approach is by using the filter function:

n=[0:40];
x=stepseq(0,0,40)-stepseq(10,0,40);
h=(0.9).^n;
y=filter(h,1,x);
stem(n,y)
xlabel(‘n’); ylabel(‘y[n]’)
grid

What yields:

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?

Solution:

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

n=[-20:120];
a=[1,-1,0.9];
b=;
h=impz(b,a,n);
stem(n,h)
grid
xlabel(‘n’); ylabel(‘h[n]’)

The script yields:

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

n=[-20:120];
a=[1,-1,0.9];
b=;
x=stepseq(0,-20,120);
s=filter(b,a,x);
stem(n,s)
xlabel(‘n’); ylabel(‘s[n]’);

The script yields:

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:

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.

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.

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

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