[637] | 1 | #include "diabolo.h"
|
---|
| 2 | #include "bolo.h"
|
---|
| 3 | #include "synchro.h"
|
---|
| 4 | #include "fichier.h"
|
---|
| 5 | #include "trace.h"
|
---|
| 6 | #include "menu.h"
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | static int choix_DS=0;
|
---|
| 11 | static int npt_DS=0; // nombre de points (periode) pour le calcul de la DS
|
---|
| 12 | static double table_DS[2*max_points_DS]; // table de detection synchrone, dupliquer en double longueur
|
---|
| 13 | static double norme_DS;
|
---|
| 14 | static int raz_parasite=2;
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | void exec_trace_DS_suite(int u);
|
---|
| 18 | void trace_DS(double *y,int enregistre);
|
---|
| 19 | void calcul_table_DS(double periode);
|
---|
| 20 |
|
---|
| 21 | #define degre(x) ((int)(x*180./3.14159))
|
---|
| 22 |
|
---|
| 23 | // calcul ya pendant la periode , yb a cheval sur 2 periodes , yc= somme des deux
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | void exec_trace_DS(int fen,int item,double valeur,...)
|
---|
| 27 | {
|
---|
| 28 | static int u=-1;
|
---|
| 29 | static flag_err=0;
|
---|
| 30 | switch(item)
|
---|
| 31 | {
|
---|
| 32 | case ouverture : gg->trace_ouvert=gg->trace_ouvert | 4 ;
|
---|
| 33 | graph->ymin=-20;
|
---|
| 34 | graph->ymax=20;
|
---|
| 35 | graph->ypas=5;
|
---|
| 36 | graph->xmax=500;
|
---|
| 37 | graph->xpas=50;
|
---|
| 38 | graph->taille_graduations=7;
|
---|
| 39 | // graph->flag_tracen=0;
|
---|
| 40 | // for(j=0;j<nb_max_bolo;j++) if( (j<10) && gg->bolo_type[j]) graph->flag_tracen+=(1<<j);
|
---|
| 41 | // graph->flag_tracen+=(1<<nb_max_bolo); // voie pour affichage du scan
|
---|
| 42 |
|
---|
| 43 | case ds_choix_DS :
|
---|
| 44 | case ds_phase :
|
---|
| 45 | case ds_phase+1000 :
|
---|
| 46 | case ds_temps_mort :
|
---|
| 47 | case ds_temps_mort+1000 :
|
---|
| 48 | calcul_table_DS(synchro_periode);
|
---|
| 49 | break;
|
---|
| 50 |
|
---|
| 51 | case ds_raz_parasite : if (valeur) raz_parasite=1; // soustraction
|
---|
| 52 | else raz_parasite=2; // plus de soustraction
|
---|
| 53 | printf("remise a zero signal parasite \n");
|
---|
| 54 | break;
|
---|
| 55 |
|
---|
| 56 | case ds_raz : gg->temps_origine=gg->periode_echantillonage*(double)gg->temps_cntl;
|
---|
| 57 | efface(fen);
|
---|
| 58 | break;
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | case ds_debut : if( (u<8*npt_DS/10) ou (u>15*npt_DS/10) )
|
---|
| 62 | {
|
---|
| 63 | if(!flag_err) {printf("erreur periode \n");flag_err=20;}
|
---|
| 64 | flag_err--;
|
---|
| 65 | }
|
---|
| 66 | else flag_err=0;
|
---|
| 67 | while(u<npt_DS) {exec_trace_DS_suite(u);u++;} // pour finir la periode
|
---|
| 68 | u=0;
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | case ds_suite : if( (u>=0) && (u<npt_DS) ) exec_trace_DS_suite(u);
|
---|
| 72 | u++;
|
---|
| 73 | break;
|
---|
| 74 |
|
---|
| 75 | case ds_enregistre : if(!fenetre(fenetre_enregistre_DS)) nouveauT(fenetre_enregistre_DS,0,"valeurs_DS");
|
---|
| 76 | trace_DS(0,1);
|
---|
| 77 | break;
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | case fermeture : gg->trace_ouvert=gg->trace_ouvert & (255-4); // enleve le 4
|
---|
| 81 | break;
|
---|
| 82 |
|
---|
| 83 | default : break;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | // le trace de la detection synchrone passe par un appel a chaque point avec u=0,1,2,.... , npt_DS-1
|
---|
| 90 | //
|
---|
| 91 | // la commande de trace sera faite par exec_trace_DS_suite pour certaines valeures de u
|
---|
| 92 | // pour une detection avec trois positions qui se suivent, le parametre supplementaire pernum
|
---|
| 93 | // compte de 0 a 2. Il est remis a zero pour un appel de la fonction avec u=-1 (qui ne fait rien d'autre)
|
---|
| 94 |
|
---|
| 95 | // la detection est accumulée simultanement dans deux registres y1 et y2 qui sont plotte simultanement.
|
---|
| 96 | // on a ainsi deux points par periode
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | void exec_trace_DS_suite(int u) // appellé quoiqu'il arrive avec u=0,1,2,.... , npt_DS-1
|
---|
| 100 | {
|
---|
| 101 | static double y[nb_max_bolo+1],y1[nb_max_bolo+1],y2[nb_max_bolo+1],bb[nb_max_bolo+1];
|
---|
| 102 | int j;
|
---|
| 103 | static double phase_mesure[nb_max_bolo],confiance[nb_max_bolo],phase_memoire;
|
---|
| 104 |
|
---|
| 105 | switch(choix_DS)
|
---|
| 106 | {
|
---|
| 107 | case choix_DS_sinus_1f :
|
---|
| 108 |
|
---|
| 109 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 110 | {
|
---|
| 111 | y1[j]+= xbol(j)*table_DS[u]; // le sinus
|
---|
| 112 | y2[j]+= xbol(j)*table_DS[u+npt_DS/4]; // dephase de pi/2 -> le cosinus
|
---|
| 113 | bb[j]+= xbol(j)* (((double)(u%2))-0.5); // estimation du bruit
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | if(u==npt_DS-1)
|
---|
| 117 | {
|
---|
| 118 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 119 | {
|
---|
| 120 | phase_mesure[j]=atan2(y1[j],y2[j]);
|
---|
| 121 | confiance[j]=log((y1[j]*y1[j]+y2[j]*y2[j])/(bb[j]*bb[j]));
|
---|
| 122 | printf(" %d°(%2.1f) ",degre(phase_mesure[j]),confiance[j]);
|
---|
| 123 | }
|
---|
| 124 | j=1; // bolo pur mesurer la phase
|
---|
| 125 | phase_memoire=phase_mesure[j];
|
---|
| 126 | ecritD(fenetre_trace_DS,ds_phase,"%d°",degre(phase_memoire));
|
---|
| 127 | printf(": phase memoire=%g \n",phase_memoire);
|
---|
| 128 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 129 | {
|
---|
| 130 | y1[j]=sin(phase_memoire)*y1[j]+cos(phase_memoire)*y2[j];
|
---|
| 131 | }
|
---|
| 132 | // printf(" trace y1= %g , %g , %g , %g , %g \n",y1[0],y1[1],y1[2],y1[3],y1[4]);
|
---|
| 133 | trace_DS(y1,0);
|
---|
| 134 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 135 | {
|
---|
| 136 | y1[j]=0;y2[j]=0;bb[j]=0;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | break;
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | case choix_DS_hacheur :
|
---|
| 145 |
|
---|
| 146 | if( (u==npt_DS/8) ou (u==5*npt_DS/8) ) trace_DS(y1,0);
|
---|
| 147 | if( (u==3*npt_DS/8) ou (u==7*npt_DS/8) ) trace_DS(y2,0);
|
---|
| 148 |
|
---|
| 149 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 150 | {
|
---|
| 151 | y1[j]+= xbol(j)*table_DS[u];
|
---|
| 152 | y2[j]+= xbol(j)*table_DS[u];
|
---|
| 153 | }
|
---|
| 154 | break;
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 | case choix_DS_secondaire : if(u==npt_DS/4) trace_DS(y1,0);
|
---|
| 158 | if(u==3*npt_DS/4) trace_DS(y2,0);
|
---|
| 159 |
|
---|
| 160 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 161 | {
|
---|
| 162 | y1[j]+= xbol(j)*table_DS[u];
|
---|
| 163 | y2[j]+= xbol(j)*table_DS[u];
|
---|
| 164 | }
|
---|
| 165 | break;
|
---|
| 166 |
|
---|
| 167 | case choix_DS_prisme : if(u==npt_DS/6) {y[2]=y1[2];y1[2]=0;trace_DS(y,0);} // phase 1 (bolo 3)
|
---|
| 168 |
|
---|
| 169 | if(u==4*npt_DS/6) {y[2]=y2[2];y2[2]=0;trace_DS(y,0);} // phase 1 (bolo 3)
|
---|
| 170 |
|
---|
| 171 | if(u==0) {y[1]=y1[1];y1[1]=0;} // phase 2 (bolo 2)
|
---|
| 172 |
|
---|
| 173 | if(u==3*npt_DS/6) {y[1]=y2[1];y2[1]=0;} // phase 2 (bolo 2)
|
---|
| 174 |
|
---|
| 175 | if(u==2*npt_DS/6) {y[3]=y1[3];y1[3]=0; // phase 3 (bolo 4)
|
---|
| 176 | y[0]=y1[0];y1[0]=0; // bolo1
|
---|
| 177 | y[4]=y1[4];y1[4]=0; // temperature
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | if(u==5*npt_DS/6) {y[3]=y2[3];y2[3]=0; // phase 3 (bolo 4)
|
---|
| 181 | y[0]=y2[0];y2[0]=0; // bolo1
|
---|
| 182 | y[4]=y2[4];y2[4]=0; // temperature
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | y1[0]+= xbol(0)*table_DS[u];
|
---|
| 186 | y2[0]+= xbol(0)*table_DS[u];
|
---|
| 187 |
|
---|
| 188 | y1[1]+= xbol(1)*table_DS[u+4*npt_DS/6];
|
---|
| 189 | y2[1]+= xbol(1)*table_DS[u+4*npt_DS/6];
|
---|
| 190 |
|
---|
| 191 | y1[2]+= xbol(2)*table_DS[u+2*npt_DS/6];
|
---|
| 192 | y2[2]+= xbol(2)*table_DS[u+2*npt_DS/6];
|
---|
| 193 |
|
---|
| 194 | y1[3]+= xbol(3)*table_DS[u];
|
---|
| 195 | y2[3]+= xbol(3)*table_DS[u];
|
---|
| 196 |
|
---|
| 197 | y1[4]+= xbol(4)*table_DS[u];
|
---|
| 198 | y2[4]+= xbol(4)*table_DS[u];
|
---|
| 199 |
|
---|
| 200 | break;
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 | default : break;
|
---|
| 205 | }
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 |
|
---|
| 209 | // divise par la norme, trace y puis fait un RAZ
|
---|
| 210 | void trace_DS(double *y,int enregistre) // y [nb_max_bolo +1 ]
|
---|
| 211 | {
|
---|
| 212 | double x;
|
---|
| 213 | static double yraz[nb_max_bolo];
|
---|
| 214 | static double yt[nb_max_bolo+1];
|
---|
| 215 | int j,k,moy;
|
---|
| 216 | static double yfiltre[nb_max_bolo][10];
|
---|
| 217 | static int uf=0;
|
---|
| 218 | x=gg->periode_echantillonage*(double)gg->temps_cntl-gg->temps_origine;
|
---|
| 219 |
|
---|
| 220 | if(enregistre)
|
---|
| 221 | {
|
---|
| 222 | printf("traceDS avec enregistre=1\n");
|
---|
| 223 | ecritT(fenetre_enregistre_DS,fin_f," %9.3f ",x );
|
---|
| 224 | for(j=0;j<nb_max_bolo;j++) if(parametr.bolo[j].bolo_code_util)
|
---|
| 225 | {
|
---|
| 226 | ecritT(fenetre_enregistre_DS,fin_f," %9.3f",yt[j]);
|
---|
| 227 | }
|
---|
| 228 | ecritT(fenetre_enregistre_DS,fin_f,"\n");
|
---|
| 229 | return;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 |
|
---|
| 233 | for(j=0;j<nb_max_bolo;j++) yt[j]=y[j];
|
---|
| 234 | for(j=0;j<nb_max_bolo;j++) y[j]=0;
|
---|
| 235 |
|
---|
| 236 | //printf(" au debut = %g , %g , %g , %g , %g \n",yt[0],yt[1],yt[2],yt[3],yt[4]);
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 |
|
---|
| 241 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 242 | {
|
---|
| 243 | yt[j]/=norme_DS;
|
---|
| 244 | if(raz_parasite==1) yraz[j]=yt[j];
|
---|
| 245 | if(raz_parasite==2) yraz[j]=0;
|
---|
| 246 | yt[j]-=yraz[j];
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | if (gg->trace_ouvert&16) trace_annexe(yt); // données razparasite mais non filtrées
|
---|
| 250 |
|
---|
| 251 | raz_parasite=0;
|
---|
| 252 | selectgra(fenetre_trace_DS);
|
---|
| 253 | yt[nb_max_bolo]=(0.95*graph->ymin+0.05*graph->ymax) +
|
---|
| 254 | + ( (gg->don.sync[sync_subscan]!=0) et (gg->don.sync[sync_scan]!=0) ) * 0.9 * (graph->ymax-graph->ymin);
|
---|
| 255 | //printf(" signal subscan=%g ",yt[nb_max_bolo]);
|
---|
| 256 | //printf(" avant moyenne= %g , %g , %g , %g , %g \n",yt[0],yt[1],yt[2],yt[3],yt[4]);
|
---|
| 257 |
|
---|
| 258 | moy=litD(fenetre_trace_DS,ds_moyenne,0L);
|
---|
| 259 | if(moy>10) {moy=10;ecritD(fenetre_trace_DS,ds_moyenne,"10");}
|
---|
| 260 | if(moy)
|
---|
| 261 | {
|
---|
| 262 | uf++;
|
---|
| 263 | if(uf>=moy) uf=0;
|
---|
| 264 | for(j=0;j<nb_max_bolo;j++) // ne moyenne pas le signal de scan
|
---|
| 265 | {
|
---|
| 266 | for(k=0;k<moy;k++) yfiltre[j][k]+=yt[j];
|
---|
| 267 | yt[j]=yfiltre[j][uf]/moy;
|
---|
| 268 | yfiltre[j][uf]=0;
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
| 271 | //printf(" montracen yt= %g , %g , %g , %g , %g \n",yt[0],yt[1],yt[2],yt[3],yt[4]);
|
---|
| 272 | //printf(" avant trace : =%g \n",yt[nb_max_bolo]);
|
---|
| 273 | montracen(fenetre_trace_DS,nb_max_bolo+1,x,yt);
|
---|
| 274 |
|
---|
| 275 | if(!(graph->scroll_courbe) && litD(fenetre_trace_DS,ds_retour,0L) &&
|
---|
| 276 | ( (x<graph->xmin) ou (x>graph->xmax) ))
|
---|
| 277 | {
|
---|
| 278 | graph->xmax-=graph->xmin;graph->xmin=0;
|
---|
| 279 | gg->temps_origine=gg->periode_echantillonage*(double)gg->temps_cntl;
|
---|
| 280 | x=0;
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | //ecritD(fenetre_trace_DS,ds_bol1,"%gµV",yt[0]);
|
---|
| 284 | //ecritD(fenetre_trace_DS,ds_bol2,"%gµV",yt[1]);
|
---|
| 285 |
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 |
|
---|
| 289 |
|
---|
| 290 |
|
---|
| 291 | // fabrique une table double longueur pour ne pas poser de problèmes
|
---|
| 292 | // la table de detection synchrone est deja dephase comme il faut
|
---|
| 293 |
|
---|
| 294 | void calcul_table_DS(double periode)
|
---|
| 295 | {
|
---|
| 296 | int i,v,tm,phase;
|
---|
| 297 | npt_DS=(int)(periode+0.2); // synchro_periode est un double et npt_DS est un entier
|
---|
| 298 | if (npt_DS>max_points_DS) npt_DS=max_points_DS;
|
---|
| 299 | choix_DS=litD(fenetre_trace_DS,ds_choix_DS,0L);
|
---|
| 300 | tm=litD(fenetre_trace_DS,ds_temps_mort,0L);
|
---|
| 301 | phase=litD(fenetre_trace_DS,ds_phase,0L);
|
---|
| 302 | norme_DS=0;
|
---|
| 303 |
|
---|
| 304 |
|
---|
| 305 | switch(choix_DS)
|
---|
| 306 | {
|
---|
| 307 | case choix_DS_sinus_1f : npt_DS=2* (int) (npt_DS/2); // plus moins plus moins (hacheur)
|
---|
| 308 | for(i=0 ;i<npt_DS;i++)
|
---|
| 309 | {
|
---|
| 310 | table_DS[i]=sin(2 * 3.14159 * (double)i / (double)npt_DS ) ;
|
---|
| 311 | norme_DS+=0.5;
|
---|
| 312 | }
|
---|
| 313 | break;
|
---|
| 314 |
|
---|
| 315 |
|
---|
| 316 | case choix_DS_hacheur : npt_DS=8* (int) (npt_DS/8); // plus moins plus moins (hacheur)
|
---|
| 317 | printf(" DS1 hacheur pour %d points : ",npt_DS);
|
---|
| 318 | i=phase;
|
---|
| 319 | while(i<0) i+=npt_DS;
|
---|
| 320 | for(v=0 ;v<npt_DS/4 ;v++)
|
---|
| 321 | {
|
---|
| 322 | if(i>=npt_DS) i=0;
|
---|
| 323 | if(v<tm) table_DS[i]=0;
|
---|
| 324 | else {table_DS[i]=-1; norme_DS++;}
|
---|
| 325 | i++;
|
---|
| 326 | }
|
---|
| 327 | for(v=0 ;v<npt_DS/4 ;v++)
|
---|
| 328 | {
|
---|
| 329 | if(i>=npt_DS) i=0;
|
---|
| 330 | if(v<tm) table_DS[i]=0;
|
---|
| 331 | else table_DS[i]=1;
|
---|
| 332 | i++;
|
---|
| 333 | }
|
---|
| 334 | for(v=0 ;v<npt_DS/4 ;v++)
|
---|
| 335 | {
|
---|
| 336 | if(i>=npt_DS) i=0;
|
---|
| 337 | if(v<tm) table_DS[i]=0;
|
---|
| 338 | else table_DS[i]=-1; // norme_DS++; la norme ne contient qu'une demi période
|
---|
| 339 | i++;
|
---|
| 340 | }
|
---|
| 341 | for(v=0 ;v<npt_DS/4 ;v++)
|
---|
| 342 | {
|
---|
| 343 | if(i>=npt_DS) i=0;
|
---|
| 344 | if(v<tm) table_DS[i]=0;
|
---|
| 345 | else table_DS[i]=1;
|
---|
| 346 | i++;
|
---|
| 347 | }
|
---|
| 348 | break;
|
---|
| 349 |
|
---|
| 350 |
|
---|
| 351 | case choix_DS_secondaire : npt_DS=4* (int) (npt_DS/4); // plus moins (diodes/secondaire)
|
---|
| 352 | printf(" DS2 (diodes) pour %d points : ",npt_DS);
|
---|
| 353 | i=phase;
|
---|
| 354 | while(i<0) i+=npt_DS;
|
---|
| 355 | for(v=0 ;v<npt_DS/2 ;v++)
|
---|
| 356 | {
|
---|
| 357 | if(i>=npt_DS) i=0;
|
---|
| 358 | if(v<tm) table_DS[i]=0;
|
---|
| 359 | else {table_DS[i]=-1; norme_DS++;}
|
---|
| 360 | i++;
|
---|
| 361 | }
|
---|
| 362 | for(v=0 ;v<npt_DS/2 ;v++)
|
---|
| 363 | {
|
---|
| 364 | if(i>=npt_DS) i=0;
|
---|
| 365 | if(v<tm) table_DS[i]=0;
|
---|
| 366 | else table_DS[i]=1;
|
---|
| 367 | i++;
|
---|
| 368 | }
|
---|
| 369 | break;
|
---|
| 370 |
|
---|
| 371 |
|
---|
| 372 |
|
---|
| 373 | case choix_DS_prisme : npt_DS=6* (int) (npt_DS/6); // moins plus moins (prisme)
|
---|
| 374 | printf(" DS3 (prisme) pour %d points : ",npt_DS);
|
---|
| 375 | i=phase;
|
---|
| 376 | while(i<0) i+=npt_DS;
|
---|
| 377 | for(v=0 ;v<npt_DS/3 ;v++)
|
---|
| 378 | {
|
---|
| 379 | if(i>=npt_DS) i=0;
|
---|
| 380 | if(v<tm) table_DS[i]=0;
|
---|
| 381 | else {table_DS[i]=-1;}
|
---|
| 382 | i++;
|
---|
| 383 | }
|
---|
| 384 | for(v=0 ;v<npt_DS/3 ;v++)
|
---|
| 385 | {
|
---|
| 386 | if(i>=npt_DS) i=0;
|
---|
| 387 | if(v<tm) table_DS[i]=0;
|
---|
| 388 | else {table_DS[i]=-1;}
|
---|
| 389 | i++;
|
---|
| 390 | }
|
---|
| 391 | for(v=0 ;v<npt_DS/3 ;v++) // plus pour la phase de référence
|
---|
| 392 | {
|
---|
| 393 | if(i>=npt_DS) i=0;
|
---|
| 394 | if(v<tm) table_DS[i]=0;
|
---|
| 395 | else {table_DS[i]=2; norme_DS+=2;}
|
---|
| 396 | i++;
|
---|
| 397 | }
|
---|
| 398 | break;
|
---|
| 399 |
|
---|
| 400 | default : break;
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 | for(i=0;i<npt_DS;i++) table_DS[i+npt_DS]=table_DS[i]; // complete la table (double longueur)
|
---|
| 404 | ecritD(fenetre_trace_DS,ds_periode,"periode: %d pts",npt_DS);
|
---|
| 405 |
|
---|
| 406 | /*
|
---|
| 407 | printf("\n normeDS=%d : ", norme_DS);
|
---|
| 408 | for(i=0;i<npt_DS;i++)
|
---|
| 409 | {
|
---|
| 410 | printf(" %d ",table_DS[i]);
|
---|
| 411 | }
|
---|
| 412 | printf("\n");
|
---|
| 413 | alerte(2,"bonjour");
|
---|
| 414 | */
|
---|
| 415 | }
|
---|
| 416 |
|
---|