PHYCS 6730 Lab Exercise: Fourier Transform Filtering

In this exercise we will continue playing with Fourier transforms of real valued data. In the homework you are asked to complete and run code that uses an FFT to do signal filtering. These exercises are warmup for the homework.

You will need the additional executable ~p6730/exercises/fft/ftfilter2 and some additional sample signal files in ~p6730/exercises/fft.

Exercise 1 Low pass filter -- approximate and exact

The low pass filter simulates the charging of an RC shunt with time constant tau = RC. The corresponding continuum filter function is g(t) = exp(-t/tau)/tau (normalized so that the integral is 1). The continuum Fourier transform of this function is

     G(f) = 1/(1 - I*omega*tau)
where omega = 2*Pi*f and f is the frequency.

Check this through direct integration of g(t) exp(I*omega*t)

The discrete filter function is g(t) = exp(-t/tau)(1-z), where z = exp(-dt/tau), normalized so the sum is 1. (We assume that exp(-Ndt/tau) is negligible.) Its Fourier transform is

     G(f) = (1-z)/[1 - cos(omega*dt)*z - I*sin(omega*dt)*z].
Check this by direct summation of g(k*dt) exp(I*omega*k*dt) for k = 0,...,31.

Nothing to hand in.


Exercise 2. Wraparound pollution

The basis for Fourier transform filtering is the convolution theorem. It states that the Fourier transform of the convolution of two functions f and g is simply the product of the Fourier transforms of f and g. So to construct the convolution, we take the Fourier transforms of f and g, multiply them, and take the inverse transform of the product. Computing the convolution directly is an O(N^2) process, but with FFT's the Fourier transform approach is only an O(N log N) process.

When the signal is sampled over a finite time interval, there are pitfalls in the convolution theorem: the theorem is valid only if the signal is regarded as repeating itself indefinitely. A causal filter produced an output signal depending only on the present and past input signal -- and not the future. But if we think of the signal as repeating itself, the future and past become confused. The beginning of the signal is preceded by the ending of the signal from the previous iteration. The causal convolution at the beginning of the signal reaches back in time. What comes before the beginning of the signal? Logically, we would say, nothing. But periodicity says, reaching back in time before the beginning of the signal takes us to the end of the signal. The signal wraps around. This is usually undesirable, so we say the convolution is polluted by the wraparound effect. To prevent wraparound, it is necessary to pad the end of the signal with enough zeros that when the convolution reaches back in time from the beginning and wraps around, it sees harmless zeros.

To explore this effect, we look at signals that consist only of a spike. One signal test2 has a spike at the beginning and the other test3 at the end. We will take the convolution in both cases with the low-pass RC filter - an exponential decay. We do this first with a filtering code ftfilter2 that does no padding. Then we repeat with code (your homework exercise) ftfilter that pads with zeros over four times the characteristic RC filter time.

Run ~p6730/exercises/fft/ftfilter2 with both data sets test2 and test3. Choose tau = 0.2. You are welcome to experiment with other time constants as well. Plot the output signals with gnuplot. What do you see? Do the same with the code ~p6730/examples/a05/ftfilter.

Answer these questions:

  1. How many sample points are in the signals in test2 and test3.
  2. About how many sample intervals correspond to the filter time constant 0.2?
  3. How do the unfiltered signals test2 and test3 differ from each other?
  4. How do the filtered signals differ?
  5. Explain the difference in terms of wraparound.