Page 131 - MATLAB Recipes for Earth Sciences
P. 131

6.4 Convolution and Filtering                                   125

           smooth the signal. Therefore running means of a given length are often used
           to smooth signals, mainly for cosmetic reasons. Modern spreadsheet soft-
           ware usually contains running means for smoothing data series. The impact

           of the smoothing filter increases with increasing fi lter length.
             The weights that a fi lter of arbitrary length may take can vary. As an ex-

           ample, let us assume an asymmetric filter of fi ve weights.
             b = [0.05 0.08 0.14 0.26 0.47]

           The sum of all of the filter weights is one. It therefore does not introduce en-
           ergy to the signal. However, since it is highly asymmetric it shifts the signal
           along the time axis, i.e., it introduces a phase shift.

             The general mathematical representation of the filtering process is the
           convolution









           where b  is the vector of fi lter weights, N +N  is the order of the filter, which
                  k                            1  2
           is the length of the filter reduced by one. In our examples of filters of fi ve


           weights, the order of the filters is four. In contrast to this format, MATLAB

           uses the engineering standard of indexing filters, i.e., filters are always de-


           fined as  causal. Therefore the convolution used by MATLAB is defi ned as





           where N is the order of the filter. A number of frequency-domain tools pro-
           vided by MATLAB cannot simply be applied to  non-causal filters that have

           been designed for applications in earth sciences. Hence, it is common to
           carry out phase corrections in order to simulate causality. For example, fre-
           quency-selective filters as introduced in Chapter 6.9 can be applied using

           the function filtfilt, which provides zero-phase forward and reverse
           fi ltering.
             The functions conv and  filter that provide digital fi ltering  with
           MATLAB are best  illustrated in terms of a simple running mean. The n
           elements of the vector x(t ), x(t ), x(t ), …, x(t ) are replaced by the arithme-
                                 1    2    3       n
           tic means of subsets of the input vector. For instance, a running mean over
           three elements computes the mean of inputs x(t ), x(t ), x(t )to obtain the
                                                     n-1   n    n+1
   126   127   128   129   130   131   132   133   134   135   136