1 | #ifndef FSAPPIRRSMPL_SEEN
|
---|
2 | #define FSAPPIRRSMPL_SEEN
|
---|
3 |
|
---|
4 |
|
---|
5 | // approximation par serie de Fourier avec echantillonnage irregulier
|
---|
6 | //------------------------------------------------------------------
|
---|
7 | // ***** Guy Le Meur -- LAL-Orsay mars 2002 ****************
|
---|
8 | //-------------------------------------------------------------------
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 | #include <math.h>
|
---|
13 | #include <iostream>
|
---|
14 |
|
---|
15 |
|
---|
16 | #include "machdefs.h" // Definitions specifiques SOPHYA
|
---|
17 | #include "nbmath.h"
|
---|
18 | #include "timing.h"
|
---|
19 | #include "array.h"
|
---|
20 | #include "fftservintf.h"
|
---|
21 | #include "fftpserver.h"
|
---|
22 |
|
---|
23 | #include "toeplitzMatrix.h"
|
---|
24 |
|
---|
25 |
|
---|
26 | ////////////////////////////////////////////////////////////////////
|
---|
27 | // Un signal donne , suppose a bande de frequences limitee, de longueur
|
---|
28 | // finie est periodise. Ce signal periodise est suppose developpe
|
---|
29 | // en serie de Fourier finie: l'approximation consiste a rechercher
|
---|
30 | // les coefficients de cette serie de Fourier. Cela est fait en utilisant
|
---|
31 | // le fait que la matrice du systeme a ecrire est Toeplitz. On utilise
|
---|
32 | // une classe ToeplitzMatrix, qui utilise les FFT pour la resolution
|
---|
33 | // L'utilisation standard comporte les etapes suivantes :
|
---|
34 | //
|
---|
35 | // constructeur --> definit l'echantillonnage et l'amplitude
|
---|
36 | // des abscisses (pour periodisation)
|
---|
37 | //
|
---|
38 | // methode approximateSignal(nbFreq, signal) : definit la bande
|
---|
39 | // de frequences et les valeurs du signal
|
---|
40 | //
|
---|
41 | // recuperation de valeurs approximees ou interpolees :
|
---|
42 | // methodes: . restaureSignal() (signal "debruite" aux valeurs
|
---|
43 | // d'echantionnage)
|
---|
44 | // . restaureRegularlySampledSignal() (signal recalcule
|
---|
45 | // sur un echantillonnage regulier quelconque)
|
---|
46 | // . computeSignalOnASampling() (signal recalcule
|
---|
47 | // sur un echantillonnage irregulier quelconque)
|
---|
48 | //
|
---|
49 | // on peut aussi recuperer les valeurs des coefficients du developpement
|
---|
50 | // en serie de Fourier (methodes complexFourierCoef() et coeffCosSin()
|
---|
51 | /////////////////////////////////////////////////////////////////////
|
---|
52 |
|
---|
53 |
|
---|
54 | class FSApproximationIrregularSampling
|
---|
55 | {
|
---|
56 |
|
---|
57 | private:
|
---|
58 | // verouiller le clonage
|
---|
59 | FSApproximationIrregularSampling(const FSApproximationIrregularSampling&) {}
|
---|
60 | FSApproximationIrregularSampling &operator = (const FSApproximationIrregularSampling&) {return *this;}
|
---|
61 |
|
---|
62 |
|
---|
63 | public:
|
---|
64 | FSApproximationIrregularSampling();
|
---|
65 |
|
---|
66 | FSApproximationIrregularSampling(TVector<double>& sampling, double offset, double range);
|
---|
67 |
|
---|
68 | ~FSApproximationIrregularSampling();
|
---|
69 |
|
---|
70 | void approximateSignal(int M, const TVector<double>& signal);
|
---|
71 |
|
---|
72 | void restaureRegularlySampledSignal(int n, TVector<double>& solution) const;
|
---|
73 |
|
---|
74 |
|
---|
75 | // le vecteur d'abscissses est suppose ordonne et appartenir a l'intervalle
|
---|
76 | // de definition du signal
|
---|
77 | void computeSignalOnASampling(const TVector<double>& abscisses, TVector<double>& solution ) const;
|
---|
78 |
|
---|
79 | double estimationConditionnement() const;
|
---|
80 |
|
---|
81 | void samplingValues(TVector<double>& sv) const;
|
---|
82 |
|
---|
83 | void restaureSignal(TVector<double>& sol) const;
|
---|
84 |
|
---|
85 |
|
---|
86 | inline void sampledSignal(TVector<double>& signal) const
|
---|
87 | {
|
---|
88 | signal = signal_;
|
---|
89 | reshapeSignalInUsersFrame(samplingValues_, signal);
|
---|
90 | }
|
---|
91 | inline const TVector<double>& weights() const { return poids_;}
|
---|
92 |
|
---|
93 | // coefficients complexes ck, pour k=0,M
|
---|
94 | inline void complexFourierCoef(TVector<complex<double> >& coef) const
|
---|
95 | {
|
---|
96 | int n= coefFourier_.Size();
|
---|
97 | coef.ReSize(n);
|
---|
98 | coef = coefFourier_;
|
---|
99 | coef *= normeSignal_;
|
---|
100 | }
|
---|
101 | // terme constant, puis cos, sin, cos, sin......
|
---|
102 | void coeffCosSin(TVector<double>& coef) const;
|
---|
103 |
|
---|
104 | private:
|
---|
105 |
|
---|
106 | inline void initFFT()
|
---|
107 | {
|
---|
108 | fftIntfPtr_ =new FFTPackServer;
|
---|
109 | fftIntfPtr_->setNormalize(false);
|
---|
110 |
|
---|
111 | }
|
---|
112 | inline double valeursSerie(double u) const
|
---|
113 | {
|
---|
114 | complex<double> somme =complex<double>(0.,0.);
|
---|
115 | for (int j=1; j<=M_; j++)
|
---|
116 | {
|
---|
117 | double angle = 2.*M_PI*j*u;
|
---|
118 | complex<double> expon = complex<double>(cos(angle), sin(angle));
|
---|
119 | somme += coefFourier_(j)*expon;
|
---|
120 | }
|
---|
121 | return coefFourier_(0).real()+ 2*somme.real();
|
---|
122 | }
|
---|
123 |
|
---|
124 | inline void calculeExponentiellesFourier()
|
---|
125 | {
|
---|
126 | int j;
|
---|
127 | int n = samplingValues_.Size();
|
---|
128 | exponFourier_.ReSize(n);
|
---|
129 | for (j=0; j<n; j++)
|
---|
130 | {
|
---|
131 | double angle=-2.*M_PI*samplingValues_(j);
|
---|
132 | exponFourier_(j) = complex<double>(cos(angle),sin(angle));
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | void matchToSamplingReference(TVector<double>& sampling) const;
|
---|
137 | void resizeSamplingIn_0_1(double offset, double range);
|
---|
138 |
|
---|
139 | void reshapeSignalInUsersFrame(const TVector<double>& abscisses, TVector<double>& resultat) const;
|
---|
140 | void reshapeSignalInUsersFrame(TVector<double>& resultat) const;
|
---|
141 |
|
---|
142 | void makeToeplitzMatrix(int M);
|
---|
143 | void makeRHS(TVector<complex<double> >& coefSolution);
|
---|
144 | void makeSamplingVector(const TVector<double>& sampling, double offset, double range);
|
---|
145 | void makeSignalVector(const TVector<double>& signal);
|
---|
146 | void computeWeights();
|
---|
147 | void NormSignal();
|
---|
148 |
|
---|
149 |
|
---|
150 | FFTServerInterface* fftIntfPtr_;
|
---|
151 | Toeplitz tptz_;
|
---|
152 | TVector<double> samplingValues_;
|
---|
153 | TVector<double> poids_;
|
---|
154 | TVector<double> signal_;
|
---|
155 | TVector<complex<double> > exponFourier_;
|
---|
156 | TVector<complex<double> > coefFourier_;
|
---|
157 | double samplingOffset_;
|
---|
158 | double samplingRange_;
|
---|
159 | double normeSignal_;
|
---|
160 | double delta_;
|
---|
161 | int nokdelta_;
|
---|
162 | int M_;
|
---|
163 | };
|
---|
164 |
|
---|
165 |
|
---|
166 | #endif
|
---|