kaos
Joined: 03 May 2007 Posts: 4 Location: Spain
|
FFT_PIC |
Posted: Sun May 06, 2007 5:18 am |
|
|
I have programmed a function "FFT_PIC" and I want to share the code to know if is possible to improve it.
Code: |
//-----------------------------------------------------------------------------------------------------//
#define BYTES 4
#define PUNTOS 1<<BYTES
//-----------------------------------------------------------------------------------------------------//
const unsigned int Orden[] = { 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 } ;
const float u1d[] = { -1.000000, 0.000000, -1.000000, 0.707107, 0.000000, -0.707107, -1.000000, 0.923880, 0.707107, 0.382683, 0.000000, -0.382683, -0.707107, -0.923880, -1.000000 } ;
const float u2d[] = { 0.000000, -1.000000, 0.000000, -0.707107, -1.000000, -0.707107, 0.000000, -0.382683, -0.707107, -0.923880, -1.000000, -0.923880, -0.707107, -0.382683, -0.000000 } ;
//-----------------------------------------------------------------------------------------------------//
void FFT_PIC(float *x,float *y)
{
int l,l1,i,l2,i1,j,cont;
float u1,u2,t1,t2,temp;
l2 = 1;
cont = 0;
for(l=0;l<BYTES;l++)
{
l1 = l2;
l2 <<= 1;
u1 = 1.0;
u2 = 0.0;
for(j=0;j<l1;j++)
{
for(i=j;i<PUNTOS;i+=l2)
{
i1 = i + l1;
temp = x[Orden[i1]];
t1 = (u1 * temp);
temp = y[ Orden[i1] ];
temp = (u2 * temp);
t1 = t1 - temp;
temp = y[ Orden[i1] ];
t2 = (u1 * temp);
temp = x[ Orden[i1] ];
temp = (u2 * temp);
t2 = t2 + temp;
temp = x[ Orden[i] ];
temp = temp - t1;
x[Orden[i1]] = temp;
temp = y[ Orden[i] ];
temp = temp - t2;
y[Orden[i1]] = temp;
x[Orden[i]] += t1;
y[Orden[i]] += t2;
}
cont++;
u1 = u1d[cont];
u2 = u2d[cont];
}
}
for(i=0;i<PUNTOS;i++)
{
x[i] /= PUNTOS;
y[i] /= PUNTOS;
}
}
|
|
|