Views
3 years ago

# Lode's Computer Graphics Tutorial Fourier Transform

Lode's Computer Graphics Tutorial Fourier Transform

## function every time. ca

function every time. ca and sa still represent the cosine and sine, but are calculated with the half-angleformulas and initual values -1.0 and 0.0 (cos and sin of pi): each loop, ca and sa represent the cosineand sine of half the angle as the previous loop.//Calculate the FFTdouble ca = -1.0;double sa = 0.0;int l1 = 1, l2 = 1;for(int l = 0; l < m; l++){l1 = l2;l2 *= 2;double u1 = 1.0;double u2 = 0.0;for(int j = 0; j < l1; j++){for(int i = j; i < n; i += l2){int i1 = i + l1;double t1 = u1 * GRe[i1] - u2 * GIm[i1];double t2 = u1 * GIm[i1] + u2 * GRe[i1];GRe[i1] = GRe[i] - t1;GIm[i1] = GIm[i] - t2;GRe[i] += t1;GIm[i] += t2;}double z = u1 * ca - u2 * sa;u2 = u1 * sa + u2 * ca;u1 = z;}sa = sqrt((1.0 - ca) / 2.0);if(!inverse) sa =- sa;ca = sqrt((1.0 + ca) / 2.0);}Finally, the values are divided through n if it isn't the inverse DFT.}//Divide through n if it isn't the IDFTif(!inverse)for(int i = 0; i < n; i++){GRe[i] /= n;GIm[i] /= n;}The function reads from *gRe and *gIm again and stores the result in *GRe and *GIm.There are 3 nested loops now in the FFT part, but only the first one goes from 0 to n-1, the other twotogether only loop log_2(n) times. For this small signal of only 128 values you probably won't noticeany increase in speed because both DFT and FFT are calculated instantly (unless you're working onsome computer from the '40s), but on bigger signals, on 2D signals, and in applications where the FThas be be calculated over and over in real time, it'll make an important difference.

FiltersIn the Fourier Domain, it's easy to apply some filters. All you have to do is multiply the spectrum withthe transfer function of the filter.Low pass filters only let through components with low frequencies (for example the bass from music),while High Pass filters let only components with high frequencies through. You can also make BandPass and Band Stop filters, which let through or block components with a certain frequency. Amplifiersmultiply the whole spectrum with a constant value, and you can of course make filters that amplifycertain frequencies, or triangular filters that weaken higher frequencies more and more, etc...So to make for example a Low Pass filter, multiply the spectrum with a rectangular function with therectangle around the origin. All the low frequency components will then be kept, while the high onesare multiplied by zero and are thus filtered away.Here's a part of code for a program that'll first allow you to select different signals and watch their FT,and after pressing the space key, will allow you to choose different filters on the spectrum, and it'llcalculate the inverse FT to see how the original signal is affected by the filter.The full code can be downloaded here: fourier1d.cpp.First all variables and functions are declared.const int N = 128; //yeah ok, we use old fashioned fixed size arrays heredouble fRe[N]; //the function's real part, imaginary part, and amplitudedouble fIm[N];double fAmp[N];double FRe[N]; //the FT's real part, imaginary part and amplitudedouble FIm[N];double FAmp[N];const double pi = 3.1415926535897932384626433832795;void FFT(int n, bool inverse, double *gRe, double *gIm, double *GRe, double *GIm); //Calculates the DFTvoid plot(int yPos, double *g, double scale, bool trans, ColorRGB color); //plots a functionvoid calculateAmp(int n, double *ga, double *gRe, double *gIm); //calculates the amplitude of a complex functionThe main function starts here. It enters the first loop, this loop will allow you to choose a function. Theparameters p1 and p2 can be changed to modify the amplitude and/or width of some of the functions.int main(int /*argc*/, char */*argv*/[]){screen(640, 480, 0, "Fourier Transform and Filters");for(int x = 0; x < N; x++) fRe[x] = fIm[x] = 0;bool endloop = 0, changed = 1;int n = N;double p1 = 25.0, p2 = 2.0;while(!endloop){if(done()) end();readKeys();

the Fourier transform and applications
Introduction to Fourier Transform Infrared ... - Nicolet CZ sro
CSC418: Computer Graphics Tutorial 1 - CDF
Chapter 36 Fast Fourier Transform and N - Phase ... - E-Courses
SLEVES and SLEFES - Computer Graphics Laboratory
Real-Time Interaction Behavior - Computer Graphics and Visualization
THE WAVELET TUTORIAL PART II by ROBI POLIKAR
Fourier transform
Fourier Transform
Fourier Transform
Fourier Transform Graphical Analysis: an Approach for Digital Image ...
Fourier Transformation
Fast Clifford Fourier Transformation for - Computer Science and ...
Fourier Theorem & Transforms
Fundamentals of the Discrete Fourier Transform
Tutorial : , & coherence with M 1 Fourier transform by Fast Fourier ...
Analysis/resynthesis with the short time Fourier transform
Fourier transforms, filtering and convolution
Fourier transforms, filtering and convolution
Fourier Transform - Part I
Fourier Transforms.
Fourier transforms & the convolution theorem - UGAstro
some notes on the Fourier transform - IGPP
The Discrete Fourier Transform
Exercises in MATLAB for convolution and Fourier transform These ...
Fast Fourier Transform and MATLAB Implementation
Chapter 8 Fourier Transforms
The Fast Fourier Transform - LOMONT.org
Lecture: Fourier Transform - biomachina.org
Fast Fourier Transforms - NOISE