Page 139 - MATLAB Recipes for Earth Sciences
P. 139

6.7 Impulse Response                                            133

             y6= y6(1+(m6-1)/2:end-(m6-1)/2,1);
             y6(end+1:end+m6-1,1)=zeros(m6-1,1);
           We obtain an output vector y6 of the same length and phase as the input
           vector x6. We plot the results for comparison.
             stem(t,x6)
             hold on
             stem(t,y6,'filledv,'r')
             axis([0 20 -2 2])
           In contrast to  plot, the function stem only accepts one data series.
           Therefore, the second series y6 is overlaid on the same plot using the func-
           tion hold. The effect of the fi lter is clearly seen on the plot. It averages the
           unit impulse over a length of five elements. Furthermore, the values of the

           output equal the filter weights of a6, in our example 0.2 for all elements of

           a6 and y6.

             For a recursive filter, the output y6 does not agree with the fi lter weights.
           Again, impulse is generated fi rst.
             clear
             t = (0:20)';
             x7 = [zeros(10,1);1;zeros(10,1)];

           Subsequently, an arbitrary recursive fi lter with weights of a7 and b7 is de-
           signed.

             b7 = [0.0048    0.0193    0.0289    0.0193    0.0048];
             a7 = [1.0000   -2.3695    2.3140   -1.0547    0.1874];
             m7 = length(b7);
             y7 = filter(b7,a7,x7);

             y7= y7(1+(m7-1)/2:end-(m7-1)/2,1);
             y7(end+1:end+m7-1,1)=zeros(m7-1,1);
           The stem plot of the input x2 and the output y2 shows an interesting impulse
           response:

             stem(t,x7)
             hold on
             stem(t,y7,'filled','r')
             axis([0 20 -2 2])

           The signal is again smeared over a wider area. It is also shifted towards the

           right. Therefore this filter not only affects the amplitude of the signal, but
           also shifts the signal towards lower or higher values. In most cases, phase

           shifts are unwanted characteristics of filters, although in some applications
           shifts along the time axis might of particular interest.
   134   135   136   137   138   139   140   141   142   143   144