/*---------------------------------------------------*/ /* module : FonctionDemo7.c */ /* auteur : Mignotte Max */ /* date : --/--/2010 */ /* langage : C */ /* labo : DIRO */ /*---------------------------------------------------*/ /*------------------------------------------------*/ /* FICHIERS INCLUS -------------------------------*/ /*------------------------------------------------*/ #include #include #include #include #include #include "FonctionDemo7.h" /*------------------------------------------------*/ /* FONCTIONS -------------------------------------*/ /*------------------------------------------------*/ /*---------------------------------------------------------*/ /* Alloue de la memoire pour une matrice 1d de float */ /*---------------------------------------------------------*/ float* fmatrix_allocate_1d(int hsize) { float* matrix; matrix=(float*)malloc(sizeof(float)*hsize); if (matrix==NULL) printf("probleme d'allocation memoire"); return matrix; } /*----------------------------------------------------------*/ /* Alloue de la memoire pour une matrice 2d de float */ /*----------------------------------------------------------*/ float** fmatrix_allocate_2d(int vsize,int hsize) { int i; float** matrix; float *imptr; matrix=(float**)malloc(sizeof(float*)*vsize); if (matrix==NULL) printf("probleme d'allocation memoire"); imptr=(float*)malloc(sizeof(float)*hsize*vsize); if (imptr==NULL) printf("probleme d'allocation memoire"); for(i=0;i=1;idim--) { n=nn[idim]; nrem=ntot/(n*nprev); ip1=nprev << 1; ip2=ip1*n; ip3=ip2*nrem; i2rev=1; for (i2=1;i2<=ip2;i2+=ip1) { if (i2 < i2rev) { for (i1=i2;i1<=i2+ip1-2;i1+=2) { for (i3=i1;i3<=ip3;i3+=ip2) { i3rev=i2rev+i3-i2; SWAP(data[i3],data[i3rev]); SWAP(data[i3+1],data[i3rev+1]); } } } ibit=ip2 >> 1; while (ibit >= ip1 && i2rev > ibit) { i2rev -= ibit; ibit >>= 1; } i2rev += ibit; } ifp1=ip1; while (ifp1 < ip2) { ifp2=ifp1 << 1; theta=isign*6.28318530717959/(ifp2/ip1); wtemp=sin(0.5*theta); wpr = -2.0*wtemp*wtemp; wpi=sin(theta); wr=1.0; wi=0.0; for (i3=1;i3<=ifp1;i3+=ip1) { for (i1=i3;i1<=i3+ip1-2;i1+=2) { for (i2=i1;i2<=ip3;i2+=ifp2) { k1=i2; k2=k1+ifp1; tempr=(float)wr*data[k2]-(float)wi*data[k2+1]; tempi=(float)wr*data[k2+1]+(float)wi*data[k2]; data[k2]=data[k1]-tempr; data[k2+1]=data[k1+1]-tempi; data[k1] += tempr; data[k1+1] += tempi; } } wr=(wtemp=wr)*wpr-wi*wpi+wr; wi=wi*wpr+wtemp*wpi+wi; } ifp1=ifp2; } nprev *= n; } } /*----------------------------------------------------------*/ /* FFT1D */ /*----------------------------------------------------------*/ void FFT1D(float* vctR,float* vctI,int lgth) { int i; float* data; unsigned long* nn; /*allocation memoire*/ data=(float*)malloc(sizeof(float)*((2*lgth)+1)); nn=(unsigned long*)malloc(sizeof(unsigned long)*2); nn[1]=lgth; /*Remplissage de data*/ for(i=0;i.dat */ /*----------------------------------------------------------*/ float* LoadSignalDat(char* name,int* length) { int i; float ech1,ech2; char buff[NBCHAR]; float Tech; FILE *fic; //Allocation float** Vct2D=fmatrix_allocate_2d(2,10000000); //nom du fichier dat strcpy(buff,name); strcat(buff,".dat"); printf("\n >> Ouverture de %s",buff); //ouverture du fichier fic=fopen(buff,"r"); if (fic==NULL) { printf("\n- Grave erreur a l'ouverture de %s -\n",buff); exit(-1); } //Lecture Donnée & Longueur & Periode Ech for(i=0;;i++) { fscanf(fic,"%f %f",&ech1,&ech2); if (feof(fic)) break; //printf("\n[%f::%f]",ech1,ech2); Vct2D[0][i]=ech1; Vct2D[1][i]=ech2; } (*length)=i; Tech=Vct2D[0][1]; Tech=1.0/Tech; Tech=(int)Tech; printf(" (%d echantillons)",(*length)); printf("\n >> Techantillonnage:: %.0f echantillons/seconde",Tech); //Chargement float* VctFinal=fmatrix_allocate_1d((*length)); for(i=0;i<(*length);i++) VctFinal[i]=Vct2D[1][i]; //End fclose(fic); (*length)=i; free_fmatrix_2d(Vct2D); return VctFinal; } /*----------------------------------------------------------*/ /* Sauvegarde du signal de nom .dat */ /*----------------------------------------------------------*/ void SaveSignalDat(char* name,float* vct,int length) { int i; char buff[NBCHAR]; FILE* fic; /*--extension--*/ strcpy(buff,name); strcat(buff,".dat"); /*--ouverture fichier--*/ fic=fopen(buff,"w"); if (fic==NULL) { printf(" Probleme dans la sauvegarde de %s",buff); exit(-1); } printf("\n Sauvegarde de %s au format dat\n",name); /*--enregistrement--*/ for(i=0;i.dat */ /*----------------------------------------------------------*/ void SaveSignalDat2(char* name,float* vct,int length,float Tech) { int i; char buff[NBCHAR]; FILE* fic; /*--extension--*/ strcpy(buff,name); strcat(buff,".dat"); /*--ouverture fichier--*/ fic=fopen(buff,"w"); if (fic==NULL) { printf(" Probleme dans la sauvegarde de %s",buff); exit(-1); } printf("\n Sauvegarde de %s au format dat\n",name); /*--enregistrement--*/ for(i=0;i (en ppm) //---------------------------------------------------------- void load_image_ppm(char* path,float*** img,int lgth,int wdth) { int i,j; int temp; char* tempc; unsigned char varb,varv,varr; char stringTmp1[200],stringTmp2[200]; int ta1,ta2,ta3; FILE *fic; //enregistrement du chemin; if (strstr(path,".ppm")==NULL) strcat(path,".ppm"); //ouverture du fichier fic=fopen(path,"r"); if (fic==NULL) { printf("\n ->> Grave erreur a l'ouverture de %s -\n",path); exit(-1); } //recuperation de l'entete tempc=fgets(stringTmp1,100,fic); //P6 tempc=fgets(stringTmp2,100,fic); //Comment for(;;) { if (((int)stringTmp2[0]==10)||((int)stringTmp2[0]==35)) tempc=fgets(stringTmp2,100,fic); else break; } temp=sscanf(tempc," %d %d",&ta1,&ta2); temp=fscanf(fic," %d",&ta3); //affichage de l'entete printf("\n\n -- Entete --"); printf("\n ------------"); printf("\n %s %d %d \n %d",stringTmp1,ta1,ta2,ta3); printf("\n ----------------------------------------------------------\n\n"); //chargement dans la matrice for(i=0;i au format couleur ppm //---------------------------------------------------------- void SaveImagePpm(char* Name,float*** matrvb,int lgth,int wdth) { int i,j; char buff[200]; FILE* fuser; time_t tm; //extension strcpy(buff,Name); strcat(buff,".ppm"); //ouverture fichier fuser=fopen(buff,"w"); if (fuser==NULL) { printf(" probleme dans la sauvegarde de %s",buff); exit(-1); } //affichage printf("\n sauvegarde dans -> %s au format %s [%d][%d]",buff,".ppm",lgth,wdth); fflush(stdout); //sauvegarde de l'entete fprintf(fuser,"P6"); fprintf(fuser,"\n# IMG Module, %s",ctime(&tm)); fprintf(fuser,"%d %d",wdth,lgth); fprintf(fuser,"\n255\n"); //enregistrement for(i=0;i au format pgm //---------------------------------------------------------- void SaveImagePgm(char* name,float** mat,int length,int width) { int i,j; char buff[NBCHAR]; FILE* fic; time_t tm; //extension strcpy(buff,name); strcat(buff,".pgm"); //ouverture fichier fic=fopen(buff,"w"); if (fic==NULL) { printf(" Probleme dans la sauvegarde de %s",buff); exit(-1); } printf("\n Sauvegarde de %s au format pgm\n",name); //sauvegarde de l'entete fprintf(fic,"P5"); if ((ctime(&tm))==NULL) fprintf(fic,"\n#\n"); else fprintf(fic,"\n# IMG Module, %s",ctime(&tm)); fprintf(fic,"%d %d",width,length); fprintf(fic,"\n255\n"); //enregistrement for(i=0;i FausseCouleur for(i=0;imax) max=mat[i][j]; //Recalibre la matrice for(i=0;i