[637] | 1 | #include "diabolo.h"
|
---|
| 2 | #include "acqui.h"
|
---|
| 3 | #include "fourier.h"
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | void spectreRMS(double *y,int n);
|
---|
| 7 | void fou(int n_fou,double*t_fou,int bolo);
|
---|
| 8 |
|
---|
| 9 | double* t_fou=0L;
|
---|
| 10 | int i=0;
|
---|
| 11 | int k,n=0;
|
---|
| 12 | double ff,qq;
|
---|
| 13 |
|
---|
| 14 | int indfen=0;
|
---|
| 15 | int fenet[100];
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | // foufou crée un tableau de doubles qui contiendra k traces et k transformees de fourier
|
---|
| 19 | // ou k est le niombre de bolos : k=nb_max_bolo
|
---|
| 20 | // trace bolo j : y[i]=t_fou[(n+10)*j+i];
|
---|
| 21 | // fourier bolo j : y[i]=t_fou[(n+10)*k+(n+10)*j+i];
|
---|
| 22 |
|
---|
| 23 | // gg->flag_fou est le flag qui contient 0 si rien ne se passe ou une transformee en memoire
|
---|
| 24 | // 1 s'il faut initialiser la transformee
|
---|
| 25 | // 2 si une transformee est en cours
|
---|
| 26 | // foufou est apelle si flag>0
|
---|
| 27 |
|
---|
| 28 | // ces deux definitions ne marchent que si n (nb de pts pour fourier) et k (nombre de bolo) sont connus
|
---|
| 29 | //#define tr(j,i) t_fou[((n)+10)*(j)+(i)]
|
---|
| 30 | //#define fo(j,i) t_fou[((n)+10)*k+((n)+10)*(j)+(i)]
|
---|
| 31 |
|
---|
| 32 | #define tr(k,n,j,i) t_fou[((n)+10)*(2*(j))+(i)]
|
---|
| 33 | #define fo(k,n,j,i) t_fou[((n)+10)*(2*(j)+1)+(i)]
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | void foufou()
|
---|
| 37 | {
|
---|
| 38 | int j;
|
---|
| 39 |
|
---|
| 40 | if(gg->flag_fou==1) // initialisation
|
---|
| 41 | {
|
---|
| 42 | if(!fenetre(fenetre_fourier))
|
---|
| 43 | ouvreD(fenetre_fourier,fourier_id,"transformée de fourier",exec_fourier);
|
---|
| 44 | else {select(fenetre_fourier);exec_fourier(fenetre_fourier,ouverture,0L);}
|
---|
| 45 | return;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | if((i % 10)==0) ecritD(fenetre_fourier,f_message,"prise de donnee: %d",i);
|
---|
| 49 | for(j=0;j<k;j++) {tr(k,n,j,i)=xbol(j);fo(k,n,j,i)=xbol(j);}
|
---|
| 50 | i++;
|
---|
| 51 |
|
---|
| 52 | if(i>n) { // fin de prise de donnees
|
---|
| 53 | char ss[256];
|
---|
| 54 | double m1,mm;
|
---|
| 55 |
|
---|
| 56 | gg->flag_fou=0;
|
---|
| 57 | for(j=0;j<k;j++)
|
---|
| 58 | {
|
---|
| 59 | ecritD(fenetre_fourier,f_message,"transformee bolo %d",j);
|
---|
| 60 | spectreRMS(&(fo(k,n,j,0)),n);
|
---|
| 61 | }
|
---|
| 62 | ecritD(fenetre_fourier,f_message,"fin de calcul",j);
|
---|
| 63 |
|
---|
| 64 | qq=gg->periode_echantillonage; printf("echantillonage=%g msec , ",qq*1000.);
|
---|
| 65 | qq=n*qq; printf("temps total=%6.2f sec \n",qq);
|
---|
| 66 | if(qq>1) ff=1./qq;else ff=1.; printf("unité de frequence : %6.2f mHz \n",ff*1000.);
|
---|
| 67 | qq=sqrt(qq);
|
---|
| 68 | ecritD(fenetre_fourier,f_message,"f=%5.2f,%4.1f Hz",ff*10.,ff*(double)n/8 );
|
---|
| 69 | printf("\n bruit des bolos entre f=%5.2f et f=%5.1f \n\n",ff*10.,ff*(double)n/8);
|
---|
| 70 |
|
---|
| 71 | ss[0]=0;
|
---|
| 72 | for(j=0;j<k;j++) if( (j!=0) && (j!=3))
|
---|
| 73 | {
|
---|
| 74 | mm=0;m1=0; for(i=10;i<n/8;i++) {mm=mm+fo(k,n,j,i);m1++;}
|
---|
| 75 | if(m1>1) mm=1000.*qq*mm/m1;
|
---|
| 76 | printf("%s: %5.1f nV\n",parametr.bolo[j].bolo_nom,mm);
|
---|
| 77 | if(strlen(ss)<200) sprintf(ss+strlen(ss),"%s: %5.1f nV\r",parametr.bolo[j].bolo_nom,mm);
|
---|
| 78 | if(strlen(ss) > 240) erreur("dans fourier, string trop long ");
|
---|
| 79 | }
|
---|
| 80 | ecritD(fenetre_fourier,f_resu,ss);
|
---|
| 81 | printf("\n");
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | //-------------------- fonction exec de la fenetre : fourier -------------------------------
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | void exec_fourier(int fen,int item,double valeur,...)
|
---|
| 93 | {
|
---|
| 94 | int f;
|
---|
| 95 | int j;
|
---|
| 96 | char ss[256];
|
---|
| 97 | double m;
|
---|
| 98 | if(item>1000) item-=1000; // pour appeler le case pour tous les cara d'un edit texte
|
---|
| 99 |
|
---|
| 100 | switch(item)
|
---|
| 101 | {
|
---|
| 102 | case ouverture : //j=litD(fenetre_acquisition,e_nb_pts,0L);
|
---|
| 103 | j=litD(fenetre_fourier,f_nb_pts,0L);
|
---|
| 104 | for(n=64;n<=j;n*=2) {}; n=n/2; // n est le nombre de points de la transformée
|
---|
| 105 | k=nb_max_bolo; // k est le nombre de bolos
|
---|
| 106 | if(t_fou) free(t_fou);
|
---|
| 107 | t_fou=malloc((n+10)*2*k*sizeof(double));
|
---|
| 108 | printf(" malloc pour le tableau t_fou avec %d octets \n",2*k*(n+10)*sizeof(double));
|
---|
| 109 | changecontrole(fenetre_fourier,f_bolo,1,k,idem,idem,idem,"");
|
---|
| 110 | i=0; // compteur de prise de données
|
---|
| 111 | ecritD(fenetre_fourier,f_resu,"");
|
---|
| 112 | gg->flag_fou=2;
|
---|
| 113 | break;
|
---|
| 114 |
|
---|
| 115 | case fermeture : gg->flag_fou=0;
|
---|
| 116 | while(indfen) {indfen--;if(fenetre(fenet[indfen])) ferme(fenet[indfen]);}
|
---|
| 117 | if(t_fou) {free(t_fou);t_fou=0;}
|
---|
| 118 | break;
|
---|
| 119 |
|
---|
| 120 | case f_calcule : gg->flag_fou=1; break;
|
---|
| 121 |
|
---|
| 122 | case f_fourier :
|
---|
| 123 |
|
---|
| 124 | j=litD(fen,f_bolo,0)-1;
|
---|
| 125 | if( (j<0) ou (j>=k) ) j=0;
|
---|
| 126 | sprintf(ss,"fourier bolo %d ",j+1);
|
---|
| 127 | f=ouvreD(0,0,ss,0L);
|
---|
| 128 | if(indfen<90) {fenet[indfen]=f;indfen++;}
|
---|
| 129 | selectgra(f);
|
---|
| 130 | strcpy(graph->xtitre,"Hz");
|
---|
| 131 | strcpy(graph->ytitre,"nV/sqrt(Hz)");
|
---|
| 132 | graph->xlog=1;
|
---|
| 133 | graph->ylog=1;
|
---|
| 134 | graph->xmin=litD(fen,f_xmin,0);
|
---|
| 135 | graph->xmax=litD(fen,f_xmax,0);
|
---|
| 136 | graph->ymin=litD(fen,f_ymin,0);
|
---|
| 137 | graph->ymax=litD(fen,f_ymax,0);
|
---|
| 138 | graph->grille=1;
|
---|
| 139 | efface(f);
|
---|
| 140 | for(i=1;i<=(n/2);i++) trace(f,ff*(double)i,1000.*qq*fo(k,n,j,i)); /* en µV / Hz */
|
---|
| 141 | break;
|
---|
| 142 |
|
---|
| 143 | case f_trace : j=litD(fen,f_bolo,0)-1;
|
---|
| 144 | if( (j<0) ou (j>=k) ) j=0;
|
---|
| 145 | sprintf(ss,"trace bolo %d ",j+1);
|
---|
| 146 | f=ouvreD(0,0,ss,0L);
|
---|
| 147 | if(indfen<90) {fenet[indfen]=f;indfen++;}
|
---|
| 148 | selectgra(f);
|
---|
| 149 | graph->ymax=litD(fen,f_traceymax,0);
|
---|
| 150 | graph->ymin=-litD(fen,f_traceymax,0);
|
---|
| 151 | graph->ypas=litD(fen,f_traceymax,0)/4.;
|
---|
| 152 | graph->grille=1;
|
---|
| 153 | strcpy(graph->xtitre,"sec");
|
---|
| 154 | strcpy(graph->ytitre,"µV");
|
---|
| 155 | efface(f);
|
---|
| 156 | m=0; for(i=1;i<=n;i++) m+=tr(k,n,j,i);
|
---|
| 157 | for(i=1;i<=n;i++) trace(f,gg->periode_echantillonage*(double)i,tr(k,n,j,i)-m/(double)n);
|
---|
| 158 | autox(f);
|
---|
| 159 | break;
|
---|
| 160 |
|
---|
| 161 | default : break;
|
---|
| 162 | }
|
---|
| 163 | }
|
---|