Fourier Analysis

advertisement
Techniques in Signal
and Data Processing
CSC 508
Fourier Analysis
Fourier Analysis for Signal Processing
By now you should be somewhat familiar with the frequency domain, at least at an
intuitive level. In summary, let's review a few concepts.
A sine or a cosine wave in the time domain is represented by a single sample (spike) in
the positive frequency domain (see Fourier Series). There is another spike in the negative
frequency domain which we will ignore for now. Further the location of this spike
indicates the frequency of the sine/cosine wave in units of cycles-per-interval. The
interval we are referring to here is the sampling interval in the time domain. The
amplitude of this spike is 1/2 the peak amplitude of the sine/cosine wave.
A
Amplitude
amplitude A/2
0 1 2 3 4 5
2 cycles/interval
time domain
frequency domain
Using RUN__FFT to Analyze Signals in the Frequency Domain
The executable program run_fft.exe computes the complex Fourier transform of a real or
complex signal sampled at up to 2048 samples per interval. The data must be provided in a
textfile of the following format. These textfiles MUST have the extension .dat since run_fft
adds this extension to any filename used. It also creates an output textfile with the same
name and the extension .out.
The number of samples MUST be an integer power of 2
number of samples
in data set
128
0.242980
0.471397
0.671559
0.831470
0.941544
0.995185
0.989177
0.923880
:
:
-0.671560
-0.471398
-0.242981
-0.000002
real
sample
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
imaginary
sample
(e.g. 32, 64, 128 up to 2048). If you have a signal that
has a different number of samples, just pad the data file
with zeros up to the next power of two in size.
The left-hand value is the real component of a complex number and
the right-hand value is the imaginary component. If you are loading
purely real data samples, then include a zero for the imaginary
components.
You may have more samples (rows) than is indicated by the number of
samples but you cannot provide fewer samples. If you attempt to read a
file with an incorrect format you will receive the error message,
raised Ada.IO_EXCEPTIONS.END_ERROR
If you misspell the file name or try to read a filename with an extension
other than .dat you will receive the error message,
raised Ada.IO_EXCEPTIONS.NAME_ERROR
The real input signal below was generated with sine_gen.exe and as is a single sine wave
with amplitude 1.0, frequency 5.0 (cycles/interval) sampled at 128 (samps/interval). The
imaginary component is zero. RUN_FFT.exe computes the complex Fourier transform,
real and imaginary components.
FFT
Am p(i)  x
2
real
x
2
imag
RUN_FFT also computes
and displays the Amplitude
and Phase of the frequency
domain signal.
 ximag
Phase(i)  tan 
 xreal
1



Phase and Amplitude in the Frequency Domain
The same information is contained in the real-imaginary data set as the amplitude-phase
data set. Amplitude-phase form has the advantage of being more understandable at an
intuitive level.
The amplitude graph shows the relative amplitude of the input signal as a function of
frequency (in cycles per sampling interval). In our example we see a spike at 5.0
cycles/interval.
The phase graph shows the phase of the input signal relative to the first sample. That is,
how much do we need to shift (lead or lag) a sine wave to match the corresponding
frequency component of the input signal. (In RUN_FFT the display is in relative
amplitude, so very small phase shifts may show up as large peaks in the graph.)
Computing an Inverse FFT by Doing a Direct FFT
You may wonder how we get back to the time domain from the frequency domain. Using
the complex form of the FFT we simply compute the FFT again using the frequency
domain data as input.
The inverse FFT of an N-point sequence X(k), k=0,1,2, . . . , N-1, is defined as,
1 N 1
x(n)   X (k ) W nk
N k 0
(1)
If we take the complex conjugate (i.e. negate the imaginary part of each data sequence,
term by term) and multiply by N, we find,
N 1
Nx (n)   X * (k )W nk
*
(2)
k 0
The right-hand side of (2) is recognized to be the FFT of the sequence X*(k) and may
be computed using any complex FFT algorithm. The desired output sequence x(n) can
then be obtained by taking the complex conjugate of the the FFT of (2) and dividing
by N do give,
*
1  N 1 *

x(n)   X (k )W nk 
N  k 0

So, we can use RUN_FFT to obtain both Fourier transforms and inverse transforms.
Building a Frequency Domain Filter
We can use the FFT and FFT-1 (inverse FFT) to build a selective bandpass filter. Let's
start with an input signal composed of a number of sine waves of different frequencies,
Reviewing the amplitude of the FFT of this signal we see that it is made of three sine
waves of approximately equal amplitude and some low level of noise that is equally
distributed in frequency (i.e. white noise). The frequencies of the three sine waves
are 1, 12 and 24 cycles/interval.
If we multiply each sample (real and imaginary) of the FFT by 1.0 or 0.0 we can
select which frequency components we wish to keep and which we wish to eliminate.
In this example, we will remove each sine wave, and compute the inverse FFT to see
the effect. We will need to also remove the aliased samples. To remove the Kth
component we must zero-out both sample K and sample (N-K).
The program RUN_FFT places the FFT in a textfile of the same name as the input file but
with the extension .out. We will modify this file and then give it some other filename with
the extension .dat so that we can compute the inverse FFT with RUN_FFT.
The real component of the FFT of our modified data set contains the filtered time-domain
signal.
We now return to the original FFT and remove the second sine wave, compute the
inverse FFT and display the filtered time-domain signal with the the 12 cycle/interval
sine wave removed.
Finally, we zero-out the third sine wave (24 cycles/interval) and compute the inverse FFT
to obtain,
A close review of the FFT reveals that the first term represents the 0 cycle/interval
(constant amplitude or DC) component. For an N sample FFT, the last term is the
N-1 cycles/interval term, but it also corresponds to the 1 cycle/interval aliased
component.
0 1 2 3 4 . . .
True Frequency Components
. . . N-1
. . . 4 3 2 1
Aliased Frequency Components
Due to aliasing, we need not consider any information in the FFT past sample N/2. In
fact it is often helpful to zero-out the samples of the FFT past N/2 before we compute
the inverse FFT (reduces white noise by a factor of 2).
Building a Low Pass Filter in the Frequency Domain
If we know the highest frequency that could be part of a signal we can zero-out all the
frequency components in the FFT above this maximum frequency.
1. Generate input data set. This sample is comprised of
two sine waves (freq=3.0, amp=1.0) and (freq=4.0,
amp=1.0) and white noise (amp=0.5).
2. Compute the FFT of the input data set.
3. Multiply both the real and imaginary components of
the FFT by the low-pass frequecy window.
4. Take the complex conjugate of the FFT (i.e. multiply
each term in the imaginary component by -1.0
5. Compute the FFT of this complex conjugate to
obtain the low-pass filtered data set.
Homework
1. Use the signal_gen.exe program to create your own noisy signal and duplicate the steps
defined for creating a lowpass fileter using the FFT. Verify the need to compute the
complex conjugate by first taking the FFT of the filtered signal without performing the
complex conjugate step (i.e. do no reverse the sign on the imaginary components).
After noting the effect on the time domain signal, recompute the inverse FFT on the
complex conjugate to complete your lowpas filter. Make sure that your cutoff frequency
is higher than the highest component you wish to keep in the time domain.
2. Create a 128 sample input signal composed of a single 15 sample square pulse of
amplitude 1.0 with the rest of the samples set to zero (all imaginary terms = 0.0).
a. Compute the FFT of this input data set, and then compute inverse FFT to verify that
the original time domain signal is obtained. (Don't forget to take the complex conjugate of
the FFT).
b. Zero out all terms (real and imaginary) past the 30th term in the FFT and compute the
inverse FFT of this modified signal.
c. Comment on the time domain signal obtained in this case. Specifically explain the
variation in amplitude on the square pulse.
Download