| 1 | int nlig = 128; int ncol = 128; | 
|---|
| 2 | TMatrix<r_8> in(nlig,ncol); | 
|---|
| 3 | int l,c; | 
|---|
| 4 | for(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; | 
|---|
| 14 | TMatrix< complex<r_8> > fftin; | 
|---|
| 15 | FFTWServer ffts; | 
|---|
| 16 | ffts.setNormalize(true); | 
|---|
| 17 | cout << " FFTServer info string= " << ffts.getInfo() << endl; | 
|---|
| 18 | cout << " Calling ffts.FFTForward(in, fftin) : " << endl; | 
|---|
| 19 | ffts.FFTForward(in, fftin); | 
|---|
| 20 | //  On garde les tableau in et fftin avec KeepObj() | 
|---|
| 21 | KeepObj(in); | 
|---|
| 22 | KeepObj(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 | 
|---|
| 26 | int kx, ky; | 
|---|
| 27 | TMatrix< complex<r_8> > fftfb(fftin.NRows(), fftin.NCols()); | 
|---|
| 28 | TMatrix< complex<r_8> > fftfd(fftin.NRows(), fftin.NCols()); | 
|---|
| 29 | // fb : Filtrage brutal , fd :  Filtrage doux | 
|---|
| 30 | for(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 | } | 
|---|
| 45 | TMatrix<r_8> infb(nlig,ncol); | 
|---|
| 46 | TMatrix<r_8> infd(nlig,ncol); | 
|---|
| 47 | // FFTBackward -- Attention, le tableau des coefficient de Fourier | 
|---|
| 48 | // est modifie - On en fait une copie | 
|---|
| 49 | TMatrix< complex<r_8> > fftf(fftin.NRows(), fftin.NCols()); | 
|---|
| 50 | // Pour le filtre brutal | 
|---|
| 51 | fftf = fftfb; | 
|---|
| 52 | ffts.FFTBackward(fftf, infb); | 
|---|
| 53 | // Pour le filtre doux | 
|---|
| 54 | fftf = fftfd; | 
|---|
| 55 | ffts.FFTBackward(fftf, infd); | 
|---|
| 56 | //  On garde les tableaux fft filtre et signal filtre | 
|---|
| 57 | KeepObj(infb); | 
|---|
| 58 | KeepObj(infd); | 
|---|
| 59 | KeepObj(fftfb); | 
|---|
| 60 | KeepObj(fftfd); | 
|---|