Linear Methods of Applied Mathematics

Filtering and signal processing

(c) Copyright 1994-1997 by Evans M. Harrell II and James V. Herod. 
     All rights reserved.

Notes for the instructor.

This contains calculations and examples which correlate with an appendix of the WWW text by Harrell and Herod.

Students can be encouraged to cut and paste from this notebook to do homework.

Instructions

This notebook uses Mathematica  to perform calculations for Harrell and Herod's hypertext book, Linear Methods of Applied Mathematics.   The student needs only a basic knowledge of Mathematica  to use the notebook, which is designed both to show how to work problems in the text and to provide a template for using Mathematica  to work other problems of the student's own design.  

Calculations will be performed when the reader presses enter in a given calculation cell (bold print).  It is best to activate the cells in order, so that Mathematica  will be able to call on operators and functions defined in earlier cells.  Red color coding is used to warn the reader when a given calculation relies on an earlier one.

An intuitive way to understand projections of functions, which has many applications in signal
processing, is in terms of filtering. The word "filtering" refers to an attempt to extract the
important part of some data while eliminating random contributions called "noise" or other
unwanted features which obscure the ones that matter. 

To illustrate the procedure, we choose a simple selection of features that are regarded as 
good and bad, to create "low-pass" and "high-pass" filters.

Suppose that we have a signal f(t) which contains some pure frequencies we are interested in,
say corresponding to pure vibratory functions 

    sin(2πt), sin(4πt), ..., sin(20πt), cos(2πt), cos(4πt), ..., cos(20πt),
           (f1) 

with frequencies 1,2,..., 10, plus some noise fnoise(t). (The frequency of a sinusoidal function
sin(t) differs from the angular frequency  by the factor 2 .) We write the full function
as: 

    f(t) = a1 cos(2 t) + a2 cos(4 t) + ... a10 cos(20 t) 
         + b1 sin(2 t) + b2 sin(4 t) + ... b10 sin(20 t) 
         + fnoise(t)

       =: ffiltered(t) + fnoise(t)

Often the constant term (a0 in the sections on Fourier series) is left out of the expansion, since a
signal usually oscillates around average zero.

Example F.1 Let us use Mathematica  to see the effect of filtering as applied to some interesting functions on the interval 0 < x < 1. We begin with the function sin(1/(x-.05)), which oscillates strongly near x=0:

f[x_] := Sin[1/(x - .05)]

Plot[Sin[1/(x - .05)], {x, 0, 1}]

The integrals to calculate the Fourier series for this function cannot be done in closed form, so we calculate them numerically, by slightly modifying the code we used in the notebook for Chapter II:

Ave[g_, {a_,b_}] := (1/(b-a)) NIntegrate[(g /. x -> intvar1),                        {intvar1, a, b}]
A[g_,m_, {a_,b_}] := (2/(b-a)) NIntegrate[              (Cos[2 m Pi intvar2/(b-a)] g /. x -> intvar2),               {intvar2, a, b}]
B[g_,n_, {a_,b_}] := (2/(b-a)) NIntegrate[              (Sin[2 n Pi intvar3/(b-a)] g /. x -> intvar3),                  {intvar3, a, b}]

LowPassFilter[f_,N_,{a_,b_}] := Ave[f,{a,b}] +            Sum[Cos[2 n Pi x/(b-a)] A[f,n,{a,b}], {n,1,N}] +     Sum[Sin[2 n Pi x/(b-a)] B[f,n,{a,b}], {n,1,N}]

LowPassFilter[f[x],3, {0,1}]

We notice that there were convergence problems associated with the wildness of this function.  We shall ignore them and assume that the calculations are sufficiently accurate.

pic1 = Plot[%, {x,0,1}, PlotStyle -> RGBColor[1,0,0]]

pic2 = Plot[f[x], {x,0,1}]

Show[{pic1,pic2}]

For comparison, let's look at the high-frequency part of this function. A
high-pass filter would throw away the result of the low-pass filter and keep
the rest:

HighPassFilter[g_,N_, {a_,b_}] := g - LowPassFilter[g,N, {a,b}]

HighPassFilter[f[x], 3, {0,1}]

pic3 = Plot[%, {x,0,1}, PlotStyle -> RGBColor[1,0,0]]

Show[{pic2,pic3}]

Example F.2   This time we perform signal processing on the function sin(1/(x-.05)), in order to enhance the low frequencies, with the integral kernel:

IKernel[x_,t_] := 6 Sum[Cos[2 Pi n x] Cos[2 Pi n t] /n, {n,1,10}]  +  						6 Sum[Sin[2 Pi m x] Sin[2 Pi m t] /m, {m,1,10}]

EnhanceLow[g_] := 6 Sum[Cos[2 Pi n x] NIntegrate[(g /. x -> t) Cos[2 Pi n t], {t,0,1}] /n, {n,1,10}]  +  						6 Sum[Sin[2 Pi m x] NIntegrate[(g /. x -> t) Sin[2 Pi m t], {t,0,1}] /m, {m,1,10}]

EnhanceLow[f[x]]

Tip in case you have trouble with this command

This involved some heavy-duty integration.  If you do not have a powerful computer, you may prefer to have fewer than 20 terms in this calculation.  You can do this by modifying the definition of EnhanceLow.

pic4 = Plot[%, {x,0,1}, PlotStyle -> RGBColor[1,0,0]]

Show[{pic2,pic4}]