- Text
- Spectrum,
- Fourier,
- Imaginary,
- Filter,
- Component,
- Frequency,
- Amplitude,
- Functions,
- Inverse,
- Transform,
- Graphics,
- Tutorial

Lode's Computer Graphics Tutorial Fourier Transform

Frequency Shifting(exp(-i*w0*x))*f(x)F(w-w0)This is the dual of the time shifting.Duality or Symmetryif f(x) F(w)then F(x) f(-w)Apart from some scaling factors at least. Because of this property, for example, the spectrum of arectangular pulse is a sinc function and at the same time the spectrum of a sinc function is a rectangularpulse.Symmetry RulesThese are only a few of the symmetry rules:• The **Fourier** **Transform** of a real even signal is real and even (i.e. it's symmetrical, mirroredaround the y-axis)• The **Fourier** **Transform** of a real odd signal is imaginary and odd (odd means it's assymetrical,mirrored around the origin point)• Since arbitrary real signals are always a sum of an even and an odd function, the **Fourier****Transform** of a real signal has an even real part and an odd imaginary part, and the Amplitude isthus always symmetrical.• In the same way, the amplitude of FT's of pure imaginary signals are symmetrical, but the FT ofcomplex signals isn't always symmetrical.Convolution TheoremConvolution is an operation between two functions that is defined as an integral, but can also beexplained as follows:Take 2 functions, for example two rectangle functions f1(x) and f2(x). Keep one of the rectangles at afixed position. Mirror the second one around the y axis (this doesn't have a lot of effect on a rectangle).Then shift this second function over a value u, where u goes from -infinity to +infinity.The resulting function g(u), the convolution of f1(x) and f2(x), takes u as a parameter. For a certain u,multiply f1 and the shifted and mirrored f2 with each other, and take area under the result (byintegrating it). This area is the value of g(u) for that u! This has to be done for every u to know thecomplete result. For example, for the two rectangle functions, as we start at u=-infinity, g(u) is 0because the two rectangles don't overlap, and multiplication of the two functions will thus result in thezero function, which has zero area. As u moves to the right, g(u) will remain 0 all the time, until finallythe two rectangles start overlapping. Now the more we go to the right, the larger the area will become,until it reaches it's maximum, so g(u) is rising. Then, the rectangles are overlapping less and less againas the second one moves more to the right, and the value of g(u) decreases again. Finally g(u) reacheszero again and remains so until +infinity. The resulting g(u) is thus a triangle function.This is what filters of painting programs that don't use the FT do in 2D. The image is then the function

that remains at fixed position, while the filter matrix moves around the whole image, and you calculatethe value of every pixel by multiplying every element of the matrix with every corresponding pixel ofthe image the matrix overlaps. For large filter matrices this is a lot of work. You can create your ownfilter matrices in painting programs like Paint Shop Pro and Photoshop by using the "User Defined"filter.Correlation is almost the same as convolution, except you don't have to mirror the second function.The convolution theorem sais that, convolving two functions in the time domain corresponds tomultiplying their spectra in the fourier domain, and vica versa. This multiplication is a much easieroperation than convolution.Since filters, too, can be described in the time and the fourier domain (called the impulse response andtransfer function of the filter respectively), and linear filters do a convolutoin in the time domain, in thefrequency domain this corresponds to multiplying the transfer function of the filter with the spectrumof the signal. The impulse response of the filter in the time domain is the response of the filter to a diracimpuls (see earlier), and the transfer function of the filter is the **Fourier** **Transform** of the impulseresponse.For us, the Convolution Theorem will come in handy when we experiment with the **Fourier****Transform**ations of signals and images.Programming The 1D **Fourier** **Transform**Here's the code of a simple program that'll calculate the FT of a given signal, and will plot both thesignal and the FT. Put it in the main.cpp file.First the variables and functions are declared. N will be the number of discrete points in the signal. Forthe signal and it's spectrum, respectively a small f or g and capital F or G are used, as it's also done inmathematics.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 DFT(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 creates a sine signal, and will then use the other functions to calculate the FT andplot it.

- Page 1 and 2: Lode's Computer Graphics TutorialFo
- Page 3 and 4: would have a single peak. A spectru
- Page 5 and 6: The spectrum is positive everywhere
- Page 7: This looks already much more progra
- Page 11 and 12: It takes 4 arrays as parameters: *g
- Page 13 and 14: FFT, which uses only O(n*logn) oper
- Page 15 and 16: FiltersIn the Fourier Domain, it's
- Page 17 and 18: Now the keys all change the spectru
- Page 19 and 20: A HP FilterHere, the same is done w
- Page 21 and 22: The main function first loads an im
- Page 23 and 24: And here's the Fast Fourier Transfo
- Page 25 and 26: left corner at xpos,yPos. The shift
- Page 27 and 28: would have only 2 color channels, o
- Page 29 and 30: The sloped lines in the spectrum he
- Page 31 and 32: shown here, the code for all keys i
- Page 33 and 34: }calculateAmp(N, M, fAmp[0][0], fRe
- Page 35 and 36: component back.This is the original
- Page 37 and 38: In the above images, a circular sec
- Page 39 and 40: It looks pretty ugly, because there
- Page 41 and 42: And here's the result of a much thi