-->[famp, f] = frmag(numer(lisys), denom(lisys), 256); -->xsetech([0,0,1,1]) -->xbasc() -->plot2d(f*200,famp)Notice that `frmag' needs as inputs the numerator and the denominator of the filter as well as an integer that indicates the length of the array that we are going to get. We obtain two vectors containing the frequencies (`f' in our example) and the amplitudes of the output (`famp' in our example). We have to notice that `frmag' returns frequencies in the range of 0 to 0.5. To evaluate the output at the sampling frequency used we can multiply `f' by the sampling frequency used, in this case 200. And here is the result:
This figure plots the quotient between the amplitudes of output and input. Frequencies above 7.5 Hz remain unchanged whereas frequencies under 2.5 are completely eliminated.
A different representation of the response is as a `Bode diagram'. Bode diagram expresses information on amplitude and phase of the response in logarithmic units
-->bode(lisys)and we get the following result:
Let's notice several facts in the representation. The first thing to notice is the logarithmic scale of the axis. Frequencies are expressed as power of 10 and span from 0.001 to 1 (the x axis is equivalent to 0.001, 0.01, 0.1 and 1). Frequencies above 0.5 do not exist. As we sampled at 200 Hz, the values in the x-axis correspond to frequencies of 0.2 (0.001 * 200), 2 (0.01 * 200) and 20 (0.1 * 200) Hz. The magnitude is indicated in decibels. We have seen that `frmag' expresses the amplitudes as a quotient between output and input. Bode diagrams are expressed in db.
The conversion between decimal values and decibels is made by:
-->decvalues = [1 0.1 0.001 0.001] //decimal values decvalues = ! 1. 0.1 0.001 0.001 ! -->dbvalues = 20 * log10 (decvalues) //db values dbvalues = ! 0. - 20. - 60. - 60. !And the conversion between decibels and decimal values is made by:
-->dbvalues = [0 -3 -6 -20] //db values dbvalues = ! 0. - 3. - 6. - 20. ! -->decvalues = 10 ^ (dbvalues/20) //decimal values decvalues = ! 1. 0.7079458 0.5011872 0.1 !The lower frame of bode diagram is the modification in phase that the system introduces. When a signal enters a filter, amplitude and phase can change. The modification in phase is expressed in degree. Since the modification in phase can change the form of the signal, filtering can have a deep effect on some measurement made on the signal.
In the previous section we designed a filter (with `iir') that we have applied to a sampled signal (with `flts') to eliminate some frequencies. Afterwards, we did the same process with the same signal sampled at a different rate. Since we designed a filter, we were interested in evaluating its response in amplitude. In this section, we got a very complete representation of the filter with `frmag' and `bode'.
In next chapters we are going to filter some real signals and use different types of filtering.