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

Last change on this file since 3222 was 2600, checked in by ansari, 21 years ago

ajout de script (.pic) exemple pour (s)piapp - Reza 12 Aout 2004

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