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