Accueil > > > FAST FOURIER TRANSFORM
FAST FOURIER TRANSFORM
Information sur la source
Description
Un petit exemple de la FAST FOURIER TRANSFORM sur la fonction f(x) = x*(1-x). N'hésitez pas à mettre des commentaires. Si vous avez des idées pour améliorer mon code n'hésitez pas non plus.
Source
- // FAST FOURIER TRANSFORM
- // Exemple de la FFT sur la fonction f(x) = x*(1-x)
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
-
- #define swap(a,b) norm=(a); (a)=(b); (b)=norm
-
- //reel[] et imag[i] sont la liste des réelles et des imaginaires
- // sign = 1 donne la transformée de Fourier
- // sign = -1 donne la transformée de Fourier inverse
-
- void fft(double *reel, double *imag, int log2n, int sign) {
-
- int n, m, m2, i, j, k, l;
- double c1, c2, norm, norm2, cphi, sphi;
-
- n = 1<<log2n;
-
- /* Inversement des bits */
- for(i=0; i<n; i++) {
-
- for(j=log2n-1, m=0, k=i; j>=0; j--, k>>=1) m += (k&1)<<j;
-
- if(m>i) {
- swap(reel[i],reel[m]);
- swap(imag[i],imag[m]);
- }
- }
-
- /* normalisation de la transformée de Fourier */
- norm = 1.0/sqrt((double)n);
- for(i=0; i<n ;i++) {
- reel[i] *= norm;
- imag[i] *= norm;
- }
-
- /* calcul de la FFT */
- for(j=0; j < log2n; j++) {
- m = 1<<j; m2 = 2*m;
- c1 = 1.0;
- c2 = 0.0;
- cphi = cos(sign*2.0*M_PI/((double)m2));
- sphi = sin(sign*2.0*M_PI/((double)m2));
- for(k=0; k<m; k++) {
- for(i=k; i<n; i+=m2) {
- l = i + m;
- norm = c1*reel[l] - c2*imag[l];
- norm2 = c1*imag[l] + c2*reel[l];
- reel[l] = reel[i] - norm;
- imag[l] = imag[i] - norm2;
- reel[i] += norm;
- imag[i] += norm2;
- }
- norm = c1*cphi - c2*sphi; // Calcul de exp(2 pi k/m) avec
- norm2 = c1*sphi + c2*cphi; // le théorème d'addition
- c1 = norm; c2 = norm2;
- }
- }
-
- }
- int main(int argc, char *argv[])
- {
- int n=16, k=4, i;
- double re[16], im[16];
- double h,x;
- FILE *fichier;
- fichier = fopen("FFT.dat","w");
-
- h = 1.0/(n-1);
-
- printf("Calcul des Points:\n");
- for(i=0; i<n; i++) {
- x = h*i;
- re[i] = x*(1-x);
- im[i] = 0;
-
- printf(" % lf %+lf i\n",re[i],im[i]);
-
- }
-
- fft(re,im,k,+1);
- printf("Transformation:\n");
- for(i=0; i<n; i++) {
- printf(" % lf %+lf i\n",re[i],im[i]);
- fprintf(fichier,"%d %lf %lf\n",i,re[i],im[i]);//on enregistre dans FFT.dat
- }
- fclose(fichier);
-
- fft(re,im,k,-1);
- printf("FFT inverse:\n");
- for(i=0; i<n; i++) {
- printf(" % lf %+lf i\n",re[i],im[i]);
- }
- system("PAUSE");
- return 0;
- }
// FAST FOURIER TRANSFORM
// Exemple de la FFT sur la fonction f(x) = x*(1-x)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define swap(a,b) norm=(a); (a)=(b); (b)=norm
//reel[] et imag[i] sont la liste des réelles et des imaginaires
// sign = 1 donne la transformée de Fourier
// sign = -1 donne la transformée de Fourier inverse
void fft(double *reel, double *imag, int log2n, int sign) {
int n, m, m2, i, j, k, l;
double c1, c2, norm, norm2, cphi, sphi;
n = 1<<log2n;
/* Inversement des bits */
for(i=0; i<n; i++) {
for(j=log2n-1, m=0, k=i; j>=0; j--, k>>=1) m += (k&1)<<j;
if(m>i) {
swap(reel[i],reel[m]);
swap(imag[i],imag[m]);
}
}
/* normalisation de la transformée de Fourier */
norm = 1.0/sqrt((double)n);
for(i=0; i<n ;i++) {
reel[i] *= norm;
imag[i] *= norm;
}
/* calcul de la FFT */
for(j=0; j < log2n; j++) {
m = 1<<j; m2 = 2*m;
c1 = 1.0;
c2 = 0.0;
cphi = cos(sign*2.0*M_PI/((double)m2));
sphi = sin(sign*2.0*M_PI/((double)m2));
for(k=0; k<m; k++) {
for(i=k; i<n; i+=m2) {
l = i + m;
norm = c1*reel[l] - c2*imag[l];
norm2 = c1*imag[l] + c2*reel[l];
reel[l] = reel[i] - norm;
imag[l] = imag[i] - norm2;
reel[i] += norm;
imag[i] += norm2;
}
norm = c1*cphi - c2*sphi; // Calcul de exp(2 pi k/m) avec
norm2 = c1*sphi + c2*cphi; // le théorème d'addition
c1 = norm; c2 = norm2;
}
}
}
int main(int argc, char *argv[])
{
int n=16, k=4, i;
double re[16], im[16];
double h,x;
FILE *fichier;
fichier = fopen("FFT.dat","w");
h = 1.0/(n-1);
printf("Calcul des Points:\n");
for(i=0; i<n; i++) {
x = h*i;
re[i] = x*(1-x);
im[i] = 0;
printf(" % lf %+lf i\n",re[i],im[i]);
}
fft(re,im,k,+1);
printf("Transformation:\n");
for(i=0; i<n; i++) {
printf(" % lf %+lf i\n",re[i],im[i]);
fprintf(fichier,"%d %lf %lf\n",i,re[i],im[i]);//on enregistre dans FFT.dat
}
fclose(fichier);
fft(re,im,k,-1);
printf("FFT inverse:\n");
for(i=0; i<n; i++) {
printf(" % lf %+lf i\n",re[i],im[i]);
}
system("PAUSE");
return 0;
}
Historique
- 08 avril 2005 10:13:46 :
- Ajout d'un fichier PDF explicatif de la FFT avec rappels sur la Transformée de Fourier, etc...
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
TECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYSTECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYS par ROMELARD Fabrice
Speakers : Lionel Limozin et Alain Marty La session commence par une découverte de SharePoint à travers la mise en place d'un environnement SharePoint pour la gestion des Sessions animées par BeWise. Le besoin est très ba...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice PERSPECTIVE 3.0 POUR SILVERLIGHT 5.0PERSPECTIVE 3.0 POUR SILVERLIGHT 5.0 par odewit
Je viens de publier la version 3.0 de Perspective pour Silverlight, qui regroupe un portage sous Silverlight 5.0 des fonctionnalités de Perspective 2.0, le framework 3D de haut-niveau introduit récemment et de nouveaux exemples de code. En voici la li...
Cliquez pour lire la suite de l'article par odewit TECHDAYS PARIS 2012 : TOP 10 DES BEST PRACTICES POUR SQL SERVERTECHDAYS PARIS 2012 : TOP 10 DES BEST PRACTICES POUR SQL SERVER par ROMELARD Fabrice
Speaker : Nadia Ben El Kadi Configuration machine La session commence par la toute première question à se poser lors de la mise en place d'environnement SQL Server, la configuration des machines : Type de mac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : KINECT + OFFICE 365 UN BON GESTE POUR VOTRE SITECHDAYS PARIS 2012 : KINECT + OFFICE 365 UN BON GESTE POUR VOTRE SI par ROMELARD Fabrice
Speakers : Fabrice Barbin, Samuel Blanchard, Julien Lo Presti Titre Prometteur et attractif invitant à voir comment lier le composant ludique Kinect dans le cadre d'une structure IT classique, notamment au travers de la plat...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE DU PREMIER JOURTECHDAYS PARIS 2012 : PLEINIèRE DU PREMIER JOUR par ROMELARD Fabrice
KeyNotes du premier jour pour les développeurs. La session est principalement axée sur une des principales directions prise par Microsoft à travers tous ses nouveaux produits : Cloud privé ou public (Solution Azure) ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
C++ C++ par yesoun1
Cliquez pour lire la suite par yesoun1 OPNETOPNET par hth21
Cliquez pour lire la suite par hth21 RE : ARBRE BINAIRERE : ARBRE BINAIRE par pacotheking
Cliquez pour lire la suite par pacotheking
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|