12.07.2015 Views

Lode's Computer Graphics Tutorial Fourier Transform

Lode's Computer Graphics Tutorial Fourier Transform

Lode's Computer Graphics Tutorial Fourier Transform

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Now the keys all change the spectrum in a certain way: they'll aplly a filter. Low Pass filters (LP) setthe spectrum to 0, except around the origin. High Pass filters (HP) do the oposite.Not all keys are shown here, because it's very messy and big code. Only a few are shown as anexample, the rest is in the downloadable source file in a more closely packed form.if(keyPressed(SDLK_a)){for(int x = 0; x < n; x++){FRe2[x] = FRe[x];FIm2[x] = FIm[x];}changed = 1;} //no filterif(keyPressed(SDLK_b)){for(int x = 0; x < n; x++){if(x < 44 || x > N - 44){FRe2[x] = FRe[x];FIm2[x] = FIm[x];}else FRe2[x] = FIm2[x] = 0;}changed = 1;} //LP//ETCETERA... *snip*Again, if a key was pressed, the new spectrum is drawn, and the inverse FFT is performed to draw thefiltered version of the original function. If you press escape the program will end.if(changed){cls(RGB_White);FFT(N, 1, FRe2, FIm2, fRe, fIm);calculateAmp(N, fAmp, fRe, fIm);plot(100, fAmp, 1.0, 0, ColorRGB(160, 160, 160));plot(100, fIm, 1.0, 0, ColorRGB(128, 255, 128));plot(100, fRe, 1.0, 0, ColorRGB(255, 0, 0));}calculateAmp(N, FAmp2, FRe2, FIm2);plot(350, FRe2, 12.0, 1, ColorRGB(255, 128, 128));plot(350, FIm2, 12.0, 1, ColorRGB(128, 255, 128));plot(350, FAmp2, 12.0, 1, ColorRGB(0, 0, 0));drawLine(w/2, 0,w/2,h-1, ColorRGB(128, 128, 255));print("Press a-z to choose a filter. Press esc to quit.", 0, 0, RGB_Black);redraw();

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!