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

Last change on this file since 3558 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
Line 
1#define TF r_8
2
3int nlig = 128; int ncol = 128;
4TMatrix<TF> in(nlig,ncol);
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);
9 in(l,c) = (TF)30.*exp(-r2/9.);
10}
11// Le dernier argument de RandomSequence est le sigma du bruit
12// Si on veut rajouter du bruit, decommenter les 3 lignes suivantes
13 TMatrix<TF> noise(nlig,ncol);
14 noise = RandomSequence(RandomSequence::Gaussian, 0., 0.5);
15 in += noise;
16TMatrix< complex<TF> > fftin;
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;
29TMatrix< complex<TF> > fftfb(fftin.NRows(), fftin.NCols());
30TMatrix< complex<TF> > fftfd(fftin.NRows(), fftin.NCols());
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);
38 complex<TF> att;
39 // Filtrage brutal fonction en escalier
40 if (kr < 10) att = complex<TF>((TF)0.5, (TF)0.);
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)
44 att = complex<TF>((TF)(1.-exp(-kr*0.1)), (TF)0.);
45 fftfd(ky, kx) = fftin(ky, kx) * att ;
46 }
47TMatrix<TF> infb(nlig,ncol);
48TMatrix<TF> infd(nlig,ncol);
49// FFTBackward -- Attention, le tableau des coefficient de Fourier
50// est modifie - On en fait une copie
51TMatrix< complex<TF> > fftf(fftin.NRows(), fftin.NCols());
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.