[394] | 1 | #include <iostream.h>
|
---|
| 2 | #include <fstream.h>
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 | #include <math.h>
|
---|
| 6 | #include "mayer_fft.h"
|
---|
| 7 | #include "dyffttools.h"
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | #include "transfelec.h"
|
---|
| 11 | #include "formepulse.h"
|
---|
| 12 |
|
---|
| 13 | #include "ssthardware.h"
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 | #define LTab (2048)
|
---|
| 17 | #define LSave (128)
|
---|
| 18 | #define Tpas (5.e-4)
|
---|
| 19 | //float PulseOptOrigin=LTab/16.*Tpas;
|
---|
| 20 | float PulseOptOrigin=0.;
|
---|
| 21 |
|
---|
| 22 | //#define DYTestRun
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | FormePulse::FormePulse(TransFuncElec TF) {
|
---|
| 27 |
|
---|
| 28 | Dcomplex j(0.,1.);
|
---|
| 29 | double Fpas=1./(Tpas*LTab);
|
---|
| 30 |
|
---|
| 31 | double *PulseInReel=new double[LTab];
|
---|
| 32 | double *PulseInImg=new double[LTab];
|
---|
| 33 | double *PulseOut=new double[LTab];
|
---|
| 34 |
|
---|
| 35 | Dcomplex* PulseFFT=new Dcomplex[LTab];
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | for(long i=0; i<LTab; i++) PulseInReel[i]=pulseOptique(i*Tpas);
|
---|
| 39 | for(long i=0; i<LTab; i++) PulseInImg[i]=0.;
|
---|
| 40 |
|
---|
| 41 | /*
|
---|
| 42 | // On fenetre le signal.
|
---|
| 43 | for(long i=0; i<LTab; i++) PulseInReel[i]=PulseInReel[i]*DYWindow(i,LTab);
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | ofstream dlout; // sert a sortir les print test
|
---|
| 47 |
|
---|
| 48 | #ifdef DYTestRun
|
---|
| 49 | //On ecrit le signal entrant
|
---|
| 50 | char s[32]="WaveIn.txt";
|
---|
| 51 | dlout.open(s,ios::out | ios::trunc);
|
---|
| 52 | if (!dlout.is_open())
|
---|
| 53 | { cerr<<"erreur a l'ouverture du fichier de resultats: "<<s<<endl;
|
---|
| 54 | exit(-1);
|
---|
| 55 | }
|
---|
| 56 | dlout<<"temps"<<"\tPartieReelle"<<"\tPartieImag"<<endl;
|
---|
| 57 |
|
---|
| 58 | for (long k=0; k<LTab; k++) {
|
---|
| 59 | dlout<<k*Tpas<<"\t"<<PulseInReel[k]<<"\t"<<PulseInImg[k]<<endl;
|
---|
| 60 | }
|
---|
| 61 | dlout.close();
|
---|
| 62 |
|
---|
| 63 | #endif
|
---|
| 64 |
|
---|
| 65 | // C'est la fft!
|
---|
| 66 | fft(LTab, PulseInReel, PulseInImg);
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | // On Filtre dans l'espace des frequences
|
---|
| 70 | for (int i=0; i<LTab; i++) {
|
---|
| 71 | PulseFFT[i]=PulseInReel[i]+PulseInImg[i]*j;
|
---|
| 72 | //On applique le filtre Iici
|
---|
| 73 | PulseFFT[i]=TF.TsFunc(2*3.1416*i*Fpas)*PulseFFT[i];
|
---|
| 74 | PulseInReel[i]=real(PulseFFT[i]);
|
---|
| 75 | PulseInImg[i]=imag(PulseFFT[i]);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | #ifdef DYTestRun
|
---|
| 79 | // On écrit la FFT
|
---|
| 80 | char s1[32]="PulseFFT.txt";
|
---|
| 81 | dlout.open(s1,ios::out | ios::trunc);
|
---|
| 82 | if (!dlout.is_open())
|
---|
| 83 | { cerr<<"erreur a l'ouverture du fichier de resultats: "<<s1<<endl;
|
---|
| 84 | exit(-1);
|
---|
| 85 | }
|
---|
| 86 | dlout<<"Frequence"<<"\tPartieReelle"<<"\tPartieImag"<<endl;
|
---|
| 87 |
|
---|
| 88 | for (long k=0; k<LTab; k++) {
|
---|
| 89 | dlout<<k*Fpas<<"\t"<<PulseInReel[k]<<"\t"<<PulseInImg[k]<<endl;
|
---|
| 90 | }
|
---|
| 91 | dlout.close();
|
---|
| 92 | #endif
|
---|
| 93 |
|
---|
| 94 | // FFT inverse
|
---|
| 95 | ifft(LTab,PulseInReel,PulseInImg);
|
---|
| 96 | for (int i=0; i<LTab; i++) {
|
---|
| 97 | PulseInReel[i]/=LTab;
|
---|
| 98 | PulseInImg[i]/=LTab;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 |
|
---|
| 102 | // On recherche le maximum d'amplitude
|
---|
| 103 | double Max=0.; //En volt
|
---|
| 104 | int MaxIndex=0;
|
---|
| 105 |
|
---|
| 106 | for(int i=0; i<LSave; i++)
|
---|
| 107 | if(PulseInReel[i]>Max) {
|
---|
| 108 | Max=PulseInReel[i];
|
---|
| 109 | MaxIndex=i;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | gainElec=Max/SSTFPulseCourant;
|
---|
| 113 | //En Volt/ampere
|
---|
| 114 |
|
---|
| 115 | // On calcule la LMH
|
---|
| 116 |
|
---|
| 117 | int HalfMaxInf;
|
---|
| 118 | for(HalfMaxInf=MaxIndex;HalfMaxInf>0;HalfMaxInf--)
|
---|
| 119 | if(fabs(PulseInReel[HalfMaxInf])<(Max/2.)) break;
|
---|
| 120 | int HalfMaxSup;
|
---|
| 121 | for(HalfMaxSup=MaxIndex;HalfMaxSup<LTab;HalfMaxSup++)
|
---|
| 122 | if(fabs(PulseInReel[HalfMaxSup])<(Max/2.)) break;
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | FullwidthHalfMax=(HalfMaxSup-HalfMaxInf)*Tpas;
|
---|
| 126 |
|
---|
| 127 | // On normalise à un Volt. Et on ecrit en memoire le resultat
|
---|
| 128 | ShapeArr=new double[LSave];
|
---|
| 129 | for(int i=0; i<LSave; i++) ShapeArr[i]=PulseInReel[i]/Max;
|
---|
| 130 |
|
---|
| 131 | #ifdef DYTestRun
|
---|
| 132 | //On ecrit le resultat dans un fichier
|
---|
| 133 | char s2[32]="Resultatfiltrage.txt";
|
---|
| 134 | dlout.open(s2,ios::out | ios::trunc);
|
---|
| 135 | if (!dlout.is_open()){
|
---|
| 136 | cerr<<"erreur a l'ouverture du fichier de resultats: "<<s2<<endl;
|
---|
| 137 | exit(-1);
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | dlout<<"Impulsion courant de: "<<SSTFPulseCourant<<" Ampères"<<endl;
|
---|
| 141 | dlout<<"Maximum d'amplitude: "<<max<< " Volts"<<endl;
|
---|
| 142 | dlout<<" gain chaine preampli: "<<gainElec<<endl<<endl;
|
---|
| 143 | dlout<<"Temps"<<"\tPartie Reelle"<<endl;
|
---|
| 144 |
|
---|
| 145 | for (int k=0; k<LSave; k++) {
|
---|
| 146 | dlout<<k*Tpas<<"\t"<<ShapeArr[k]<<endl;
|
---|
| 147 | }
|
---|
| 148 | #endif
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | //On tue les tableaux de passage....
|
---|
| 153 | delete[] PulseInReel;
|
---|
| 154 | delete[] PulseInImg;
|
---|
| 155 | delete[] PulseOut;
|
---|
| 156 | delete[] PulseFFT;
|
---|
| 157 |
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | FormePulse& FormePulse::operator =(const FormePulse& FPlse) {
|
---|
| 161 | ShapeArr=new double[LSave];
|
---|
| 162 | for(int i=0; i<LSave; i++) ShapeArr[i]=FPlse.ShapeArr[i];
|
---|
| 163 | return *this;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | FormePulse::~FormePulse() {
|
---|
| 167 | delete[] ShapeArr;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | double FormePulse::TMax() {
|
---|
| 171 | double returnVal=LSave*Tpas;
|
---|
| 172 | return returnVal;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | double FormePulse::PulseShape(double temps) {
|
---|
| 176 | int ientier=(int)(temps/Tpas);
|
---|
| 177 | double returnValue;
|
---|
| 178 | if (ientier<0) returnValue=0.;
|
---|
| 179 | else if (ientier>=LSave) returnValue= ShapeArr[127];
|
---|
| 180 | else {
|
---|
| 181 | double Min=ShapeArr[ientier];
|
---|
| 182 | double Max=ShapeArr[ientier+1];
|
---|
| 183 | // double test=temps/Tpas-ientier;
|
---|
| 184 | returnValue=Min+(Max-Min)*(temps/Tpas-ientier);
|
---|
| 185 | }
|
---|
| 186 | return returnValue;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 | double FormePulse::LongPulseOptique() {
|
---|
| 191 | double returnVal;
|
---|
| 192 | returnVal=SSTLongPhotDiode/SSTLongFocale*PeriodRotTeles/2/3.1415/sin(SSTTelesElevation);
|
---|
| 193 | //en secondes
|
---|
| 194 | return returnVal;
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | double FormePulse::pulseOptique(double temps) {
|
---|
| 198 | double value;
|
---|
| 199 | if((temps>PulseOptOrigin)&&(temps<=PulseOptOrigin+LongPulseOptique()))
|
---|
| 200 | value=SSTFPulseCourant; // Amplitude: 1 nanoampère
|
---|
| 201 |
|
---|
| 202 | else value=0.;
|
---|
| 203 | // for(long i=0; i<LTab; i++) value=sin(2*3.1416*temps/5.e-3); //pour test FFT
|
---|
| 204 | return value;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 |
|
---|