source: Sophya/trunk/Poubelle/archediab.old/archediab.sources/c/trace-DS.c@ 651

Last change on this file since 651 was 649, checked in by ansari, 26 years ago

archediab 28 vol

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