source: Sophya/trunk/SophyaPI/DemoPIApp/fft2d.cc@ 3456

Last change on this file since 3456 was 3356, checked in by ansari, 18 years ago

adaptation fft2d.cc pour faire du r_4 ET r_8 (au choix defini par define TF) - Reza 23/10/2007

File size: 2.8 KB
RevLine 
[3356]1#define TF r_8
2
[2600]3int nlig = 128; int ncol = 128;
[3356]4TMatrix<TF> in(nlig,ncol);
[2600]5int l,c;
6for(l=40; l<80; l++)
7 for(c=40; c<80; c++) {
8 double r2 = (l-60.5)*(l-60.5)+(c-60.5)*(c-60.5);
[3356]9 in(l,c) = (TF)30.*exp(-r2/9.);
[2600]10}
11// Le dernier argument de RandomSequence est le sigma du bruit
12// Si on veut rajouter du bruit, decommenter les 3 lignes suivantes
[3356]13 TMatrix<TF> noise(nlig,ncol);
[2600]14 noise = RandomSequence(RandomSequence::Gaussian, 0., 0.5);
15 in += noise;
[3356]16TMatrix< complex<TF> > fftin;
[2600]17FFTWServer ffts;
18ffts.setNormalize(true);
19cout << " FFTServer info string= " << ffts.getInfo() << endl;
20cout << " Calling ffts.FFTForward(in, fftin) : " << endl;
21ffts.FFTForward(in, fftin);
22// On garde les tableau in et fftin avec KeepObj()
23KeepObj(in);
24KeepObj(fftin);
25// On fait un filtre passe-haut
26// Il faut savoir que les frequences negatives sont rangees
27// dans la seconde moitie du tableau en numero de ligne
28int kx, ky;
[3356]29TMatrix< complex<TF> > fftfb(fftin.NRows(), fftin.NCols());
30TMatrix< complex<TF> > fftfd(fftin.NRows(), fftin.NCols());
[2600]31// fb : Filtrage brutal , fd : Filtrage doux
32for(ky=0; ky<fftin.NRows(); ky++)
33 for(kx=0; kx<fftin.NCols(); kx++) {
34 int kyy = ky;
35 // deuxieme partie du tableau - Frequences negatives en y
36 if (ky > fftin.NRows()/2) kyy = fftin.NRows()-ky;
37 double kr = sqrt((double)kx*kx+kyy*kyy);
[3356]38 complex<TF> att;
[2600]39 // Filtrage brutal fonction en escalier
[3356]40 if (kr < 10) att = complex<TF>((TF)0.5, (TF)0.);
[2600]41 else att = complex<double>(1., 0.);
42 fftfb(ky, kx) = fftin(ky, kx) * att ;
43 // Filtrage doux sous forme de 1-exp(-alpha k_r)
[3356]44 att = complex<TF>((TF)(1.-exp(-kr*0.1)), (TF)0.);
[2600]45 fftfd(ky, kx) = fftin(ky, kx) * att ;
46 }
[3356]47TMatrix<TF> infb(nlig,ncol);
48TMatrix<TF> infd(nlig,ncol);
[2600]49// FFTBackward -- Attention, le tableau des coefficient de Fourier
50// est modifie - On en fait une copie
[3356]51TMatrix< complex<TF> > fftf(fftin.NRows(), fftin.NCols());
[2600]52// Pour le filtre brutal
53fftf = fftfb;
54ffts.FFTBackward(fftf, infb);
55// Pour le filtre doux
56fftf = fftfd;
57ffts.FFTBackward(fftf, infd);
58// On garde les tableaux fft filtre et signal filtre
59KeepObj(infb);
60KeepObj(infd);
61KeepObj(fftfb);
62KeepObj(fftfd);
Note: See TracBrowser for help on using the repository browser.