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