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