Fourier Transforms Fourier s idea that periodic functions can be represented by an infinite series of sines and cosines with discrete frequencies which are integer multiples of a fundamental frequency can be generalized to continuous frequencies. This leads to the Fourier Transform, which replaces the summation of discrete frequency components with an integral over a continuous range of frequencies. The Fourier Transform is similar in many ways to the Laplace Transform you may have learned about in the study of differential equations. The Fourier Transform of a function g(t) is given by the integral G(f ) = g(t) dt e 2πft The function G(f) gives the frequency spectrum of the function g(t), showing us which frequencies, how much of each frequency and what phase shift each requires to construct the function g(t). The function G(f) is said to be in the frequency domain. Note that this integral depends on Euler s formula, which states that an exponential function with an imaginary exponent is equivalent to the complex sum of a cosine and a sine. Specifically, e i2πft = cos(2πf t) + i sin(2πf t) Fourier Transforms are particularly useful for analyzing the frequency content of signals and for modifying signals by filtering out particular frequencies, such as the high-frequency hiss of audio recordings, as well as synthesizing signals (such as electronic pianos) by combining appropriate sine and cosine functions. An implementation of the Fourier Transform which is suitable for use on a computer, the Discrete Fourier Transform (DFT), has been developed, and a particularly efficient algorithm for calculating the DFT when the number of data points is a power of 2, called the Fast Fourier Transform (FFT), is widely used in science and engineering. The fft( ) command in Scilab calculates either the DFT or FFT, depending on whether or not the number of data points is a power of 2, and produces the frequency spectrum of the signal, showing which frequencies are contained in the signal and how much of each frequency. Generating a Function Suppose we were given data for the graph shown for two cycles here with the Scilab commands shown below. -->x=linspace(0,1,128);
-->y=3*sin(2*%pi*4*x)+4*cos(2*%pi*6*x); -->plot(x,y) Finding the FFT We want to find what frequencies the data contains and how much of each frequency is in the signal. Here s how we do it. We first need to generate a frequency scale. It turns out that the frequency resolution (distance between two points in the frequency spectrum) is the inverse of the product of the space or time resolution x and the number of data points N: f = 1/(N x). The frequency window must then be set N f = 1/ x. -->dx=x(2)-x(1); -->f=linspace(0,1/dx,128); The fft( ) command returns complex numbers, representing coefficients to e {i2πx}. To see the frequency spectrum, we look at the magnitude, m, of the complex coefficients. The magnitude is obtained by taking the square-root of the sum of the squares of the real and 1 imaginary parts with the abs( ) command and scaling the amplitude by. (N f) -->df=f(2)-f(1) -->m=abs(fft(y))/(128*df);
-->plot(f,m) The figure above shows the frequency spectrum. The two spikes to the left are the frequency components of our signal. The two spikes to the right are reflections of the two spikes on the left and actually represent negative frequency components. (If you think of a rotation about the origin in the counterclockwise direction as representing a positive angular frequency, then a rotation in the clockwise direction represents a negative angular frequency.) We can zoom in on the positive portion of the frequency spectrum with the following Scilab command to display just the first 16 data points of the frequency and the magnitude functions: -->plot(f(1:16),m(1:16))
The close-up of the frequency spectrum shown above shows clearly that the frequency components of our signal are at 4 Hz and 6 Hz and the components have amplitudes of y = 3 sin(2π 4x) + 4 cos(2π 6x) 1.5 and 2. In the original function,, the coefficients of the sine and cosine were 3 and 4, respectively, but in the frequency spectrum, the amplitude is split evenly between the positive and negative frequency components. Filtering Out Unwanted Frequency Components Transforming a signal into the frequency domain allows us to apply filters which remove undesirable frequency components from a signal. An audio application of this idea would be to remove the high-frequency hiss or pops generated by scratches which degrade the quality of recorded music. A graphical application of this idea would be to remove scratches from an old photograph. To simulate this situation, we ll add some high-frequency noise to our previous signal. Here is the Scilab command to do that: -->yn=y+sin(2*%pi*20*x); -->plot(x,yn)
A quick comparison of this degraded signal to the one at the beginning shows the striking effect of the high-frequency noise. Transforming this signal into the frequency domain with the following commands yields the frequency spectrum shown below. -->mn=abs(fft(yn))/(128*df); -->plot(f,mn)
The high-frequency noise we added is clearly distinguishable in the frequency spectrum shown above. We can create a notch filter to remove the noise at 20 Hz by creating a function which has the value 0 near 10 Hz and has the value 1 everywhere else. The following Scilab commands do this: -->n=f-f+1; -->n(15:25)=0; -->n(103:113)=0; -->plot(f,n) Multiplying our transformed signal by the notch filter removes the noise spikes from the frequency spectrum. Note the.* operator multiplies corresponding elements of each function. -->m2=mn.*n; -->plot(f,m2)
Inverting the Filtered FFT to Exit the Frequency Domain By using the Inverse Fast Fourier Transform command signal back to the space/time domain: -->y2=ifft(fft(yn).*n); -->plot(x,y2) if f t(), we can transform our filtered A comparison of the filtered signal above with the noisy signal and the original signal,
shows that we have totally eliminated the noise and restored the full quality of the original signal. Practice 1) Find the frequencies contained in the following signal on and the amplitude of each frequency component. Show graphs resulting from each step. The data is in the file loaded into Scilab by opening the pasting it into a Scilab array: > x = [ 1 > 0.9844 > 0.9688 > 0.9688 > 0.9844] data. zip data and noisy (available at: http://civerson.com/math4c/data.zip) and it can be x. txt C[0, 1] file, copying the contents to the clipboard, and x y y The noisy data is in the file and can be similarly loaded into Scilab: > y2 = [ 4 > 6.873 > 8.9388 > 1.8834 > 0.8872] $ y2.txt 2) Remove the high-frequency noise from the noisy signal by filtering in the frequency domain. Show graphs resulting from each step, including a graph of your frequency filter. 3) Can you determine the amplitude and frequency of the original signal? 4) Can you determine the equation for the original signal?