begin process at 2012 05 27 13:28:31
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Applications Linux

 > ALGORITHME DE FFT EN C

ALGORITHME DE FFT EN C


 Information sur la source

Note :
Aucune note
Catégorie :Applications Linux Classé sous :FFT, DIF, DIT, FFT real, IFFT real Niveau :Débutant Date de création :12/10/2007 Date de mise à jour :12/10/2007 22:34:16 Vu / téléchargé :22 998 / 771

Auteur : purcharse

Ecrire un message privé
Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

 Description

Les fonctionnalites:
DIF Radix2,  DIF Radix4
DIT Radix2,  DIT Radix4
FFT complex, IFFT complex
FFT real, IFFT real

Le mode d'emploi:
lguo@lguo-enst:~$ unzip -r Algo.zip
lguo@lguo-enst:~$ cd Algo/DIF
lguo@lguo-enst:~/Algo/DIF$ gcc -o FFT_DIF_R2 FFT_DIF_R2.c -lm
lguo@lguo-enst:~/Algo/DIF$ ./FFT_DIF_R2

lguo@lguo-enst:~$ cd Algo/FFT_Test_Linux
lguo@lguo-enst:~/Algo/FFT_Test _Linux$ make
lguo@lguo-enst:~/Algo/FFT_Test_Linux$ ./FFT

Source

  • /***********************************
  • // DIT radix-4 FFT complex
  • //
  • // 1. Maximium points are 1024.
  • //
  • // 2. The last stage is 2 DFT ( for 8, 32, 128, 512...)
  • // or all stages are 4 DFT ( for 4, 16, 64, 256, 1024 ...).
  • //
  • // 3. The functions special for FFT real .
  • //
  • // 24 juillet 2007
  • // purcharse*gmail.com
  • ************************************/
  • #include "FFT.h"
  • static complex multicomplex( complex b1, complex b2) /* multiplication of complex */
  • {
  • complex b3;
  • b3.real=b1.real*b2.real-b1.imag*b2.imag;
  • b3.imag=b1.real*b2.imag+b1.imag*b2.real;
  • return(b3);
  • }
  • static int mylog2(int N) /* Max(N) = 4098 */
  • {
  • int k=0;
  • if (N>>12) { k+=12; N>>=12; }
  • if (N>>8) { k+=8; N>>=8; }
  • if (N>>4) { k+=4; N>>=4; }
  • if (N>>2) { k+=2; N>>=2; }
  • if (N>>1) { k+=1; N>>=1; }
  • return k ;
  • }
  • static void BitReverse(complex *xin, int N)
  • {
  • int LH, i, j, k;
  • struct complex tmp;
  • LH=N/2;
  • j = N/2;
  • for( i = 1; i <= (N -2); i++)
  • {
  • if(i < j)
  • {
  • tmp = xin[j];
  • xin[j] = xin[i];
  • xin[i] = tmp;
  • }
  • k = LH;
  • while(j >= k)
  • {
  • j = j-k;
  • k = k/2;
  • }
  • j = j + k;
  • }
  • }
  • static void DFT_2(complex *b1, complex *b2)
  • {
  • struct complex tmp;
  • tmp = *b1;
  • (*b1).real = (*b1).real + (*b2).real;
  • (*b1).imag = (*b1).imag + (*b2).imag;
  • (*b2).real = tmp.real - (*b2).real;
  • (*b2).imag = tmp.imag - (*b2).imag;
  • }
  • static void DFT_4(complex* b0, complex* b1, complex* b2, complex* b3)
  • {
  • /*variables locales*/
  • struct complex temp[4];
  • /*calcul x1*/
  • temp[0].real=(*b0).real+(*b1).real;
  • temp[0].imag=(*b0).imag+(*b1).imag;
  • /*calcul x2*/
  • temp[1].real=(*b0).real-(*b1).real;
  • temp[1].imag=(*b0).imag-(*b1).imag;
  • /*calcul x3*/
  • temp[2].real=(*b2).real+(*b3).real;
  • temp[2].imag=(*b2).imag+(*b3).imag;
  • /*calcul x4 + multiplication with -j*/
  • temp[3].imag=(*b3).real-(*b2).real;
  • temp[3].real=(*b2).imag-(*b3).imag;
  • /*the last stage*/
  • (*b0).real=temp[0].real+temp[2].real;
  • (*b0).imag=temp[0].imag+temp[2].imag;
  • (*b1).real=temp[1].real+temp[3].real;
  • (*b1).imag=temp[1].imag+temp[3].imag;
  • (*b2).real=temp[0].real-temp[2].real;
  • (*b2).imag=temp[0].imag-temp[2].imag;
  • (*b3).real=temp[1].real-temp[3].real;
  • (*b3).imag=temp[1].imag-temp[3].imag;
  • }
  • static void FFT_R4(complex *xin, int N, int m)
  • {
  • int i, L, j;
  • double ps1, ps2, ps3;
  • int le,B;
  • struct complex w[4];
  • for( L = 1; L <= m; L++)
  • {
  • le = pow(4 ,L);
  • B = le/4; /*the distance of buttefly*/
  • for(j = 0; j <= B-1 ; j++)
  • {
  • // ps0 = (TWICEPI/N) * 0 * j;
  • // w[0].real = cos(ps0);
  • // w[0].imag = -sin(ps0);
  • ps1 = ((TWICEPI)/le)*2*j;
  • w[1].real = cos(ps1);
  • w[1].imag = -sin(ps1);
  • ps2 = (TWICEPI/le)*j;
  • w[2].real = cos(ps2);
  • w[2].imag = -sin(ps2);
  • ps3 = (TWICEPI/le)*3*j;
  • w[3].real = cos(ps3);
  • w[3].imag = -sin(ps3);
  • for(i = j; i <= N-1; i = i + le) /* controle those same butteflies*/
  • {
  • /* multiple with W */
  • // xin[i] = multicomplex(xin[i], w[0]);
  • xin[i + B] = multicomplex(xin[i + B], w[1]);
  • xin[i + 2*B] = multicomplex(xin[i + 2*B], w[2]);
  • xin[i + 3*B] = multicomplex(xin[i + 3*B], w[3]);
  • /* DFT-4 */
  • DFT_4(xin + i, xin + i + B, xin + i + 2*B, xin + i + 3*B);
  • }
  • }
  • /*
  • printf("*****N°%d **********\n", L);
  • for(i=0;i<N;i++)
  • {
  • printf("%.8f\t\t",xin[i].real);
  • printf("%.8f\n",xin[i].imag);
  • }
  • */
  • }
  • }//end of FFT_R4
  • static void FFT_L2(complex *xin, int N)
  • { /* For the last stage 2 DFT*/
  • int j, B;
  • double p, ps ;
  • struct complex w;
  • B = N/2;
  • for(j = 0; j <= B - 1; j++)
  • {
  • ps = (TWICEPI/N)*j;
  • w.real = cos(ps);
  • w.imag = -sin(ps);
  • /* multiple avec W */
  • xin[j+ B] = multicomplex(xin[j + B], w);
  • DFT_2(xin + j ,xin + j + B);
  • }
  • }//end of FFT_L2
  • /**************** FFT complex ***************/
  • void RunFFT(complex *xin, int N)
  • {
  • int m, i;
  • BitReverse(xin, N);
  • m = mylog2(N);
  • if( (m%2) == 0 )
  • {
  • /*All the stages are radix 4*/
  • FFT_R4(xin, N, m/2);
  • }
  • else
  • {
  • /*the last stage is radix 2*/
  • FFT_R4(xin, N, m/2);
  • FFT_L2(xin, N);
  • }
  • }
  • void RunIFFT(complex *xin,int N)
  • { /* inverse FFT */
  • int i;
  • for(i=0; i < N + 1 ; i++)
  • {
  • xin[i].imag = -xin[i].imag;
  • }
  • RunFFT(xin,N);
  • for(i = 0; i < N + 1 ; i++)
  • {
  • xin[i].real = xin[i].real/N;
  • xin[i].imag = -xin[i].imag/N;
  • }
  • }
  • /************** FFT real ****************/
  • void RunFFTR(complex *xin, int N)
  • {
  • int i;
  • double ps;
  • complex *Realin;
  • complex Realtmp1;
  • complex Realtmp2;
  • complex w;
  • Realin = (complex *)malloc((N/2)*sizeof(complex));
  • /*** X(n)= A(2n) +j*A(2n+1) ***/
  • for(i = 0 ; i < N/2 ; i++)
  • {
  • Realin[i].real = xin[2*i].real;
  • Realin[i].imag = xin[2*i + 1].real;
  • }
  • RunFFT(Realin, N/2);
  • for(i = 0; i < N/2 ; i++)
  • {
  • /***** factor w *****/
  • ps = (TWICEPI/N)*i;
  • w.real = cos(ps);
  • w.imag = -sin(ps);
  • /***** conjugue *****/
  • Realtmp1.real = Realin[(N/2) - i].real;
  • Realtmp1.imag = -Realin[(N/2) - i].imag;
  • if(i == 0)
  • {
  • Realtmp1.real = Realin[0].real;
  • Realtmp1.imag = -Realin[0].imag;
  • }
  • /***** part 2 *****/
  • Realtmp2.real = Realin[i].imag - Realtmp1.imag;
  • Realtmp2.imag = Realtmp1.real - Realin[i].real;
  • if(i > 0)
  • Realtmp2 = multicomplex(Realtmp2, w);
  • /**** part 1 ****/
  • Realtmp1.real = Realin[i].real + Realtmp1.real;
  • Realtmp1.imag = Realin[i].imag + Realtmp1.imag;
  • xin[i].real = (Realtmp1.real + Realtmp2.real)/2;
  • xin[i].imag = (Realtmp1.imag + Realtmp2.imag)/2;
  • xin[N/2 + i].real = (Realtmp1.real - Realtmp2.real)/2;
  • xin[N/2 + i].imag = (Realtmp1.imag - Realtmp2.imag)/2;
  • }
  • }
  • void RunIFFTR(complex *xin, int N)
  • {
  • int i;
  • double ps;
  • complex *Realin;
  • complex Realtmp1;
  • complex Realtmp2;
  • complex w;
  • Realin = (complex *)malloc((N/2)*sizeof(complex));
  • /*** X(n)= A(2n) +j*A(2n+1) ***/
  • for(i = 0 ; i < N/2 ; i++)
  • {
  • Realin[i].real = xin[2*i].real;
  • Realin[i].imag = xin[2*i + 1].real;
  • }
  • RunIFFT(Realin, N/2);
  • for(i = 0; i < N/2 ; i++)
  • {
  • /***** factor w *****/
  • ps = (TWICEPI/N)*i;
  • w.real = cos(ps);
  • w.imag = -sin(ps);
  • /***** conjugue *****/
  • Realtmp1.real = Realin[(N/2) - i].real;
  • Realtmp1.imag = -Realin[(N/2) - i].imag;
  • if(i == 0)
  • {
  • Realtmp1.real = Realin[0].real;
  • Realtmp1.imag = -Realin[0].imag;
  • }
  • /***** part 2 *****/
  • Realtmp2.real = Realin[i].imag - Realtmp1.imag;
  • Realtmp2.imag = Realtmp1.real - Realin[i].real;
  • if(i > 0)
  • Realtmp2 = multicomplex(Realtmp2, w);
  • /**** part 1 ****/
  • Realtmp1.real = Realin[i].real + Realtmp1.real;
  • Realtmp1.imag = Realin[i].imag + Realtmp1.imag;
  • xin[i].real = (Realtmp1.real + Realtmp2.real)/2;
  • xin[i].imag = (Realtmp1.imag + Realtmp2.imag)/2;
  • xin[N/2 + i].real = (Realtmp1.real - Realtmp2.real)/2;
  • xin[N/2 + i].imag = (Realtmp1.imag - Realtmp2.imag)/2;
  • }
  • }
/***********************************
// DIT radix-4  FFT  complex 
//
// 1. Maximium points are 1024.
//
// 2. The last stage is 2 DFT ( for 8, 32, 128, 512...)
// or all stages are 4 DFT ( for 4, 16, 64, 256, 1024 ...).
//
// 3. The functions special for FFT real .
//
// 24 juillet 2007
// purcharse*gmail.com
************************************/
#include "FFT.h"

static  complex multicomplex( complex b1, complex b2)  /* multiplication of complex */
{
 complex b3;
b3.real=b1.real*b2.real-b1.imag*b2.imag;
b3.imag=b1.real*b2.imag+b1.imag*b2.real;
return(b3);
}

static int mylog2(int N) 	/* Max(N) = 4098 */
{
  int k=0;
  
  if (N>>12) { k+=12; N>>=12; }
  if (N>>8) { k+=8; N>>=8; }
  if (N>>4) { k+=4; N>>=4; }
  if (N>>2) { k+=2; N>>=2; }
  if (N>>1) { k+=1; N>>=1; }
  return k ;
}

static void BitReverse(complex *xin, int N)
{
	int LH, i, j, k;
	struct complex tmp;

			LH=N/2;    
			j = N/2;

			for( i = 1; i <= (N -2); i++)
			{
				if(i < j)
				{
					tmp = xin[j];
					xin[j] = xin[i];
					xin[i] = tmp;
				}
			k = LH;
				while(j >= k)
				{
					j = j-k;
					k = k/2;
				}

			j = j + k;

			}

}

static void DFT_2(complex *b1, complex *b2)
{
struct complex tmp;
  tmp = *b1;

  (*b1).real = (*b1).real + (*b2).real;
  (*b1).imag = (*b1).imag + (*b2).imag;

  (*b2).real = tmp.real - (*b2).real;
  (*b2).imag = tmp.imag - (*b2).imag;	
}

static void DFT_4(complex* b0,  complex* b1, complex* b2, complex* b3)
{
  /*variables locales*/
  struct complex temp[4];
  
  /*calcul x1*/
  temp[0].real=(*b0).real+(*b1).real;		
  temp[0].imag=(*b0).imag+(*b1).imag;

  /*calcul x2*/
  temp[1].real=(*b0).real-(*b1).real;		
  temp[1].imag=(*b0).imag-(*b1).imag;

  /*calcul x3*/
  temp[2].real=(*b2).real+(*b3).real;	
  temp[2].imag=(*b2).imag+(*b3).imag;

  /*calcul x4 + multiplication with -j*/
  temp[3].imag=(*b3).real-(*b2).real;		
  temp[3].real=(*b2).imag-(*b3).imag; 

  /*the last stage*/
  (*b0).real=temp[0].real+temp[2].real;
  (*b0).imag=temp[0].imag+temp[2].imag;
  
  (*b1).real=temp[1].real+temp[3].real;     
  (*b1).imag=temp[1].imag+temp[3].imag; 
  
  (*b2).real=temp[0].real-temp[2].real;     
  (*b2).imag=temp[0].imag-temp[2].imag;
  
  (*b3).real=temp[1].real-temp[3].real; 
  (*b3).imag=temp[1].imag-temp[3].imag;
}



static void FFT_R4(complex *xin, int N, int m)
{
		int  i, L, j;
		double  ps1, ps2, ps3;
		int le,B;
		struct complex w[4];

		for( L = 1; L <= m; L++)
		{
			le = pow(4 ,L);
			B = le/4;       /*the distance of buttefly*/
		
 			for(j = 0; j <= B-1 ; j++)	
  			{
			       //  ps0 = (TWICEPI/N) * 0 * j;
			       //  w[0].real = cos(ps0);
			       //  w[0].imag = -sin(ps0);
	
				   ps1 = ((TWICEPI)/le)*2*j;
				   w[1].real = cos(ps1);
				   w[1].imag = -sin(ps1);

				   ps2 = (TWICEPI/le)*j;
				   w[2].real = cos(ps2);
				   w[2].imag = -sin(ps2);

				   ps3 = (TWICEPI/le)*3*j;
				   w[3].real = cos(ps3);
				   w[3].imag = -sin(ps3);

				   for(i = j; i <= N-1; i = i + le)	/* controle those same butteflies*/
				     {
						/* multiple with W */
				 //   xin[i] = multicomplex(xin[i], w[0]);
				      xin[i + B] = multicomplex(xin[i + B], w[1]);
				      xin[i + 2*B] = multicomplex(xin[i + 2*B], w[2]);
				      xin[i + 3*B] = multicomplex(xin[i + 3*B], w[3]);
						/* DFT-4 */
				      DFT_4(xin + i, xin + i + B, xin + i + 2*B, xin + i + 3*B);
				     }
  		      }
		/*
		printf("*****N°%d **********\n", L);
		for(i=0;i<N;i++)
		{
		printf("%.8f\t\t",xin[i].real);
		printf("%.8f\n",xin[i].imag);
		}
		*/
		}
	
}//end of FFT_R4

static void FFT_L2(complex *xin, int N)
{				/* For the last stage 2 DFT*/
	int j, B;
	double p, ps ;
	struct complex w;

		B = N/2;   			
		for(j = 0; j <= B - 1; j++)
		{			
			ps = (TWICEPI/N)*j;
		        w.real = cos(ps);
			w.imag = -sin(ps);

	    	 	/* multiple avec W */
            		 xin[j+ B] = multicomplex(xin[j + B], w);
			 DFT_2(xin + j ,xin + j + B);
		}
				
}//end of FFT_L2


/**************** FFT complex ***************/

 void RunFFT(complex *xin, int N)
{
	int m, i;
	BitReverse(xin, N);
	m = mylog2(N);
	if( (m%2) == 0 )
	{
		/*All the stages are radix 4*/
		FFT_R4(xin, N, m/2);
	}
	else 
	{
		/*the last stage is radix 2*/
		FFT_R4(xin, N, m/2);
		FFT_L2(xin, N);
	}
}

 void RunIFFT(complex *xin,int N)
{			/* inverse FFT */
      int i;
    
      for(i=0; i < N + 1 ; i++)
      { 
	xin[i].imag = -xin[i].imag;
      }

      RunFFT(xin,N);

      for(i = 0; i < N + 1 ; i++)
      { 
	xin[i].real = xin[i].real/N;
	xin[i].imag = -xin[i].imag/N;
      }
}

/**************     FFT real   ****************/

void RunFFTR(complex *xin, int N)
{
	int i;
	double ps;
	complex *Realin;
	complex Realtmp1;
	complex Realtmp2;
	complex w;

	Realin	= (complex *)malloc((N/2)*sizeof(complex));

			/*** X(n)= A(2n) +j*A(2n+1) ***/
	for(i = 0 ; i < N/2 ; i++)
	{
		Realin[i].real = xin[2*i].real;
		Realin[i].imag = xin[2*i + 1].real;
	}
	
	RunFFT(Realin, N/2);

	for(i = 0; i < N/2 ; i++)
	{
			/*****	factor w *****/
		ps = (TWICEPI/N)*i;
		w.real = cos(ps);
		w.imag = -sin(ps);

			/*****  conjugue *****/
	       Realtmp1.real = Realin[(N/2) - i].real;
	       Realtmp1.imag = -Realin[(N/2) - i].imag;	

		if(i == 0)
	       {
	       Realtmp1.real = Realin[0].real;
	       Realtmp1.imag = -Realin[0].imag;	
	       }	
			/*****	part 2 *****/ 
	       Realtmp2.real = Realin[i].imag - Realtmp1.imag;
	       Realtmp2.imag = Realtmp1.real - Realin[i].real;
	       if(i > 0)
	       Realtmp2 = multicomplex(Realtmp2, w);

			/****  part 1 ****/
	       Realtmp1.real = Realin[i].real + Realtmp1.real;	
	       Realtmp1.imag = Realin[i].imag + Realtmp1.imag;	
	
	       xin[i].real = (Realtmp1.real + Realtmp2.real)/2;
	       xin[i].imag = (Realtmp1.imag + Realtmp2.imag)/2;
	
	       xin[N/2 + i].real = (Realtmp1.real - Realtmp2.real)/2;
	       xin[N/2 + i].imag = (Realtmp1.imag - Realtmp2.imag)/2;
			
	}

}

void RunIFFTR(complex *xin, int N)
{

	int i;
	double ps;
	complex *Realin;
	complex Realtmp1;
	complex Realtmp2;
	complex w;

	Realin	= (complex *)malloc((N/2)*sizeof(complex));

			/*** X(n)= A(2n) +j*A(2n+1) ***/
	for(i = 0 ; i < N/2 ; i++)
	{
		Realin[i].real = xin[2*i].real;
		Realin[i].imag = xin[2*i + 1].real;
	}
	
	RunIFFT(Realin, N/2);

	for(i = 0; i < N/2 ; i++)
	{
			/*****	factor w *****/
		ps = (TWICEPI/N)*i;
		w.real = cos(ps);
		w.imag = -sin(ps);

			/*****  conjugue *****/
	       Realtmp1.real = Realin[(N/2) - i].real;
	       Realtmp1.imag = -Realin[(N/2) - i].imag;	

		if(i == 0)
	       {
	       Realtmp1.real = Realin[0].real;
	       Realtmp1.imag = -Realin[0].imag;	
	       }	
			/*****	part 2 *****/ 
	       Realtmp2.real = Realin[i].imag - Realtmp1.imag;
	       Realtmp2.imag = Realtmp1.real - Realin[i].real;
	       if(i > 0)
	       Realtmp2 = multicomplex(Realtmp2, w);

			/****  part 1 ****/
	       Realtmp1.real = Realin[i].real + Realtmp1.real;	
	       Realtmp1.imag = Realin[i].imag + Realtmp1.imag;	
	
	       xin[i].real = (Realtmp1.real + Realtmp2.real)/2;
	       xin[i].imag = (Realtmp1.imag + Realtmp2.imag)/2;
	
	       xin[N/2 + i].real = (Realtmp1.real - Realtmp2.real)/2;
	       xin[N/2 + i].imag = (Realtmp1.imag - Realtmp2.imag)/2;
			
	}
	
}


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  •   Algo
    •   DIF
    •   DIT
    •   FFT_Test_Linux
      •   fft
      •   test
      • FFTTélécharger ce fichier [Réservé aux membres club]66 209 octets
      • FFT.oTélécharger ce fichier [Réservé aux membres club]11 844 octets
      • FFTTest.oTélécharger ce fichier [Réservé aux membres club]7 796 octets
      • MakefileTélécharger ce fichier [Réservé aux membres club]1 144 octets
      • t000008.oTélécharger ce fichier [Réservé aux membres club]4 204 octets
      • t000016.oTélécharger ce fichier [Réservé aux membres club]4 340 octets
      • t000032.oTélécharger ce fichier [Réservé aux membres club]4 596 octets
      • t000064.oTélécharger ce fichier [Réservé aux membres club]5 108 octets
      • t000128.oTélécharger ce fichier [Réservé aux membres club]6 140 octets
      • t000256.oTélécharger ce fichier [Réservé aux membres club]8 220 octets
      • t000512.oTélécharger ce fichier [Réservé aux membres club]12 316 octets
      • t001024.oTélécharger ce fichier [Réservé aux membres club]20 516 octets

Télécharger le zip


 Historique

12 octobre 2007 22:34:16 :
change rien

 Sources de la même categorie

Source avec Zip TRAITEMENT D'IMAGE PGM par Jios
Source avec une capture COLORIMÈTRE NUMÉRIQUE LINUX par valchek
Source avec Zip TRAITEMENTS D'IMAGES AU FORMAT PGM AVEC LES ALGORITHMES DE C... par lemout
Source avec Zip ALGORITHME ACO INTERFACE GTK par RyBeN
Source avec Zip COMPRESSER SES SAUVEGARDES SMSBACKUPRESTORE (ANDROID) EN C A... par ThalLab

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture FFT2D, IMAGE, SPECTRE, FILTRE PASSE-BAS PASSE-HAUT par JCDjcd
Source avec Zip Source avec une capture POLYNOME CARACTERISTIQUE par JCDjcd
Source avec Zip CLASSE CSOUND par bobbyantho
Source avec Zip Source avec une capture EQUALIZER (WIN32) par gagah1

Commentaires et avis

Commentaire de ghuysmans99 le 13/10/2007 08:36:39

pourquoi tu ne fais pas toute la compil dans un makefile ?

Commentaire de Patrice99 le 13/10/2007 09:58:03

Voir aussi en VB 2005 Express :
VBWaveComp : Le comparateur de spectre audio en VB .Net
Vers un "benchmark" de la compression audio
www.vbfrance.com/code.aspx?ID=5319

Commentaire de JCDjcd le 14/10/2007 15:17:24

Bon alors en fait du fait un FFT avec le bit reverse.
Cet algorithme est plus difficile a implementer.
Ton code n'est pas lisible, on sait pas ou l'on va.
Meme si je connais le principe, je ne comprends pas.
On peut faire une FFT directement.
A toute fin utile, voici ma version :
# //-------------------------------------------------
# // on decompose le polynome P = A0 + B0 avec les coefficients
# // de degres pairs (en A0) et impairs (en B0)
# // alors on a :
# // P(w) = A0(w) + B0(w)
# // = A(w^2) + w.B(w^2)
# // or w^2 est une racine nieme, donc on se ramene a un cas
# // de taille deux fois moins grand
# static void polyFFT(
# P_COMPLEX res,
# P_COMPLEX tabCoeff,
# int stepi,
# int n,
# P_COMPLEX w
# )
# {
#
# if(1 == n)
# {
# // P(z)=constante
# res->re = tabCoeff->re;
# res->im = tabCoeff->im;
# }
# else
# {
# int k;
# COMPLEX w2,wPowk;
#
#
# // strategie diviser pour regner
#
# // calcul du carre de <w>
# MulComplex(&w2,w,w);
# // appel recursif
# polyFFT(res ,tabCoeff ,2*stepi,n/2,&w2); // coefficients pairs
# polyFFT(res + n/2,tabCoeff + stepi ,2*stepi,n/2,&w2); // coefficients impairs
#
# // on calcule la FFT a partir de ce que l'on vient de calculer
# wPowk.re = 1.;
# wPowk.im = 0.;
# for(k=0;k<n/2;k++)
# {
# COMPLEX A,B;
#
# A = res[k];
# B = res[k + n/2];
# MulComplex(&B,&B,&wPowk);
#
# AddComplex(res + k ,&A,&B);
# SubComplex(res + k + n/2,&A,&B);
#
# MulComplex(&wPowk,&wPowk,w);
# }
# }
# } // polyFFT()

bien plus courte (normalement bien indentee)

Commentaire de JCDjcd le 14/10/2007 15:18:23

bon en gros va sur http://www.cppfrance.com/codes/MULTIPLICATION-POLYNOMES-LOG_32745.aspx

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Il serait très important de lire ceci svp ... [ par NitRic ] Bonjour, j'aimerais bien savoir pourquoi on ma bloqué l'accès sur le chat? Qu'est-ce que j'ai fais?J'étais innactif, un moment donné, software caused fft inverse [ par perig ] SalutJ'ai un projet en C, c'est du traitement de l'image pour ca je dois utiliser la fft.J'ai trouvé des sources ici sur les fft 1D et 2D mais moi il comment dit on en Français a=3; [ par pixelhate ] Comment lit-on ou énonce-t-on en français l'instruction de c++ suivante :a=3"a affectation trois" ou "trois affecte a" ou "a est affecté partrois"ou Dialog dit Verouille [ par DarkOrion ] Bonjour, je voudrais savori comment creer un dialog dit verouille, c'est a dire qui requiert une action sur celui ci, et si on clique sur le bureau pa MouseEnter [ par drpsico ] bonjour je voudrais savoir pourquoi quand je fais&nbsp;void __fastcall TForm1::Label4MouseEnter(TObject *Sender)il me dit qu'il faux que je&nbsp;inclu Crée un programme, propement dit [ par scano93 ] J'ai h&#233;sit&#233;, mais je me suis dit, autant cr&#233;e un nouveau sujet, &#231;a pourrait peut-&#234;tre aider les futurs programmeurs. J'expliq declaration de variables [ par Darkan ] &nbsp;&nbsp; Bonjour a tous!J'aimerais savoir s'il y avait possibilit&#233; de d&#233;clarer des variables dans un autre fichier que dans le fichier p Optimisation et modification du codeC pour lire 4pixels au lieu 1 [ par zorrofes ] Bonjour,j ai besoin de votre aide. J' ai reussi a optimiser mon code et de diminuer un peu le nombre de cycles lors de l execution. Ce code permet de fft 2D [ par gasougasou ] Bonjour, je recherche un code source pour effectuer la transform&#233;e de Fourier sur des images en langage C (pas de C++).Merci Thread et multiprocesseur [ par themaste ] Salut a tous!Voila, j'ai une appli multithread, avec un principal, et 3 autres dit "secondaire".Le premier est principale dans le sens ou c'est lui qu


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,640 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales