Lecture 6: Discrete Fourier Transform In the previous lecture we introduced the discrete Fourier transform as given either by summations or as a matrix vector product The discrete Fourier transform of f [f f f n- ] is another vector whose k th component is n n i( πk) j/ n i( π / n) kj j j j n kj f j j e f e f j Or, in terms of a matrix product it is kj Ff where F has kj component Three very important properties include trig functions, inverse discrete Fourier transforms and the convolution identity These will allow us to formulate a filter to purge images of unwanted periodic noise, see the Matlab code fftsinem The Matlab code ffttrigm computed the discrete Fourier transform for the sine and cosine functions with different frequencies f and f 4 Note the spikes occur at frequencies f and n-f The amplitudes are proportional the ±n/, will be positive real for the cosine function and opposite sign and imaginary for the sine function 4 3 real(fft(8*cos(*pi**t))) - 4 6 8 frequency imag(fft(4*(sin(*pi*4*t))) - - 4 6 8 frequency
Discrete Fourier Transform of Trig Functions Let t : /(n-): The discrete Fourier transform of e iπf t is for k f and n for k f The discrete Fourier transform of e -iπf t is for k n-f and n for k n-f The discrete Fourier transform of cos(πf t) is for k f or n-f, n/ for k f and n-f The discrete Fourier transform of sin(πf t) is for k f or n-f, (-n/)i for k f and (n/) i for k n-f The proofs of the Fourier transforms for the sine and cosine vectors follow from the Fourier transforms of the exponential functions and Euler s formula The above example also illustrates these properties In order to understand the first formula, consider the special case n 3 and use the matrix representation for the discrete Fourier transform iπ f e iπ f t iπ f/3 f Fe e iπ f /3 f e If f, + + 3 iπ f t Fe + + + + If f, + + iπ f t Fe 3 + + + + If f, F + + + + + + 3 iπ f t e The reader should verify the remaining Fourier transforms
The Inverse Discrete Fourier Transform The inverse discrete Fourier transform of g [g g g n- ] is another vector whose k th component is n n i( πk) j/ n i( π / n) kj e g j e g n n j j n n j Or, in terms of a matrix product it is kj F g where F has kj component n kj In order to confirm this, again consider the special case n 3 g j j FF 3 + + + + + + 3 + + + + + + + + + + + + 3 3 I 3 3 The inverse Fourier transform can be efficiently computed by using the same technique as in the fast Fourier transform The following illustrates the Matlab command ifft() for computing the inverse Fourier transform: >> f [ 7 ] >> g fft(f) g -35-433i -35 + 433i >> ifft(g) ans 7
The Discrete Convolution and Fourier Transform The discrete convolution of two vectors of length n is vector of length n- The components correspond to the n- degree polynomial that is a product of the two n- degree polynomials with coefficients from the two vectors of length n For example, for n 3 and the two vectors a [a a a ] and b [b b b ]: p ( x) p ( x) ( a + a x + a x )( b + b x + b x ) a b conv( a, b) a b ( ) ( ) 3 4 ( ) ( ab) + ab + ba x + ab + ab + ab x + ( ab + ab) x + ab x The convolution of a and b conv( a, b) Then [ ab ab+ ba ab + ab+ ab ab + ab ab] p p ( x) p ( x) The analogue of the convolution property for the discrete Fourier transforms requires the use of padded discrete Fourier transforms This is a technical difficulty caused be the fact that the dimension of vectors increase during the convolution of two vectors Let a be a n vector A padded a vector, is a n- vector with a in the first n components and eros in the last n- components For example, let n 3 and a [a a a ] A a a Its Fourier transform is a a 3 4 a 4 3 4 FA a a + a+ 3 4 3 a 4 3 4 3 The component wise product with a Fourier transform of a padded vectors of a and b is
4 4 FA* F B ( a + a + a)*( b + b + b) 3 3 4 3 4 3 4 ab + ( ab + ab ) + ( ab + ab + ab ) 3 4 3 3 4 3 + ( ab + ab ) + ab 4 Fconv( a, b) Convolution Property Let A and B be the padded vectors of two n vectors a and b The n- dimensional Fourier transform of the convolution of a and b is the point wise or array product of the Fourier transforms of A and B: Fconv( a, b) FA * F B Example Let n 3 and a [ 3 6] and b [8 6 3] >> a [ 3 6] >> b [8 6 3] >> conv(a,b) ans 6 36 7 45 8 >> A [a ] >> B [b ]
>> ffta fft(a) ffta -97-63799i 47 + 3943i 47-3943i -97 + 63799i >> fftb fft(b) fftb 7 747-74697i 479-6735i 479 + 6735i 747 + 74697i >> lhs fft(conv(a,b)) lhs e+ * 87-697 - 399i 847 + 5i 847-5i -697 + 399i >> rhs ffta*fftb rhs e+ * 87-697 - 399i 847 + 5i 847-5i -697 + 399i The convolution property can be restated as conv a b A B (, ) F ( F * F )
If B is an image, then its Fourier transform will reflect the frequencies of the periodic parts of the image By masking or filtering out the unwanted frequencies one can obtained a new image by applying the inverse Fourier transformation A filter is a matrix with the same dimension as the Fourier transform of the padded image whose components vary from to If the component is, then the frequency is allowed to pass; if the component is, then the frequency is tossed out Let Filter represent such a matrix Then the filtered image is NewB F ( Filter * F B) Application to Low Pass Filter Periodic Noise on Sine Curve - - 3 4 5 6 7 8 9 6 4 Shifted Fourier Transform 5 5 5
Matlab Code fftsinem to Filter High Frequencies clear; t ::; % Define sin( pi t) with high frequency variations x *sin(*pi*t) + *sin(*pi**t) + *cos(*pi**t); fftx fft(x,); fftx fftshift(fftx); % Padded fft figure() subplot(,,); plot(t,x); subplot(,,); plot(abs(fftx)); freqfilter eros(,); freqfilter(,7:3) ; newfftx freqfilter*fftx; % Low pass filter newx ifftshift(newfftx); newx ifft(newx,); % Padded inverse fft figure() subplot(,,); plot(abs(newfftx)); subplot(,,); plot(t,real(newx(,:))); 6 4 Filtered Frequency Domain 5 5 5 5 Filtered Time Domain -5-3 4 5 6 7 8 9