Page 143 - MATLAB Recipes for Earth Sciences
P. 143

6.8 Frequency Response                                          137

           of an input signal. An exact value of the magnitude can also be obtained by
           simple interpolation of the magnitude,

             1-interp1(f,magnitude,1/20)

             ans =
                 0.4260
           which is the expected ca. 43% reduction of the amplitude of a sine wave
           with period 20. The sine wave with period 15 experiences an amplitude
           reduction of

             1-interp1(f,magnitude,1/15)
             ans =
                 0.6768

           i.e., around 68% similar to the value observed at the beginning. The fre-
           quency response can be calculated for all kinds of filters. It is a valuable

           tool to predict the effects of a filter on signals in general. The phase re-

           sponse can also be calculated from the complex frequency response of the

           filter (Fig. 6.4):
             phase = 180*angle(h)/pi;

             plot(f,phase)
             xlabel('Frequency'), ylabel('Phase in degrees')
             title('Phase')
           The phase angle is plotted in degrees. We observe frequent 180° jumps in
           this plot that are an artifact of the arctangent function inside the function
           angle. We can unwrap the phase response to eliminate the 180° jumps us-
           ing the function unwrap.

             plot(f,unwrap(phase))
             xlabel('Frequency'),ylabel('Phase in degrees')
             title('Phase')


           Since the filter has a linear phase response, no shifts of the frequency com-
           ponents of the signal occur relative to each other. Therefore we would not
           expect any distortions of the signal in the frequency domain. The phase shift

           of the filter can be computed using
             interp1(f,unwrap(phase),1/20) * 20/360
             ans =
                -5.0000
   138   139   140   141   142   143   144   145   146   147   148