We are going to build now another kind of filter. Its name is `Finite Impulse Response' and it is usually known as `FIR'. By the way, `IIR' means `Infinite Impulse Response'. In Scilab the command to design a FIR filter is `wfir'. We are going to follow a process similar to the process followed in the previous chapters. In this case we have three steps:
The first step is very similar to the design of IIR filters
-->valcoeff = wfir ('lp', 4, [.2 0], 'hm', [0 0])
valcoeff =
! 0.0161456 0.2881307 0.2881307 0.0161456 !
The first parameter (`lp') indicates that we are designing a low pass filter, the second one (`4') is the length of the filter (in our example we get four coefficients) and the third one is the cut-off frequency (for `lp' and `hp' we only use the first value). Frequency values, as in the previous chapter, are scaled to the sampling frequency.
Once we get the coefficients, we have to build the transfer function (this step was not necessary in `IIR filters' since `iir()' returns the transfer function)
-->hpoly = poly (valcoeff, 'z','coeff')
hpoly =
2 3
0.0161456 + 0.2881307z + 0.2881307z + 0.0161456z
-->hz = horner (hpoly, (1/%z))
hz =
2 3
0.0161456 + 0.2881307z + 0.2881307z + 0.0161456z
------------------------------------------------
3
z
-->lisys = syslin ('d', hz)
lisys =
2 3
0.0161456 + 0.2881307z + 0.2881307z + 0.0161456z
------------------------------------------------
3
z
This step is the most difficult of the process. We create the transfer function with the coefficients of the previous step. The function `horner' converts a polynomial in `z' in a polynomial in `1/z'. Afterwards, we define a discrete system with `syslin' (we call it `lisys'). Notice that in `horner' we need a percent sign to use a predefined polynomial in `z'.
The third step is the application of the filter with the command `flts' as in the previous chapters.
-->in = rand(1:256); -->out = flts (in,lisys);
Once we define the linear system, we can make a lot of things such as adding or subtracting with other linear systems. We can find out the characteristics of the filter we made :
-->bode(lisys)
And Scilab plots the characteristic of the filter.
It would be probably interesting to stress several aspects of `wfir'. The function can be called without arguments
-->valcoeff = wfir ()
Scilab plots different windows asking for the kind of filter, the cut-off frequency, the filter length and the window type. We get the same coefficients than with the direct command but we do not have to remember the details.
Although we have stressed the similarity with the application of IIR filters, FIR filters can be applied by convolution and we do not need to convert them to linear systems (the process described in this chapter).
If we want to know the characteristics of the filter that we have designed, we have some options.
-->[valcoeff, filtamp, filtfreq] = wfir ('lp', 20, [.2 0], 'hm', [0 0]);
We can get the response of the filter:
-->plot2d(filtfreq,filtamp)
And the result is
FIR filters have a linear phase, which implies that the filter does not change the original shape of the signal. This characteristic is important when signal shape is considered in data interpretation. In Clinical Neurophysiology, we are usually very interested in maintaining the shape of the signal. In the previous chapter, with IIR filters, we filtered the signal twice (the second one in inverse order) to compensate the modifications of phase. We do not need to do it with FIR filtering.