1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| int Processing :: fft1d( float *a, int n, int isgn )
{
int l,l1,l2,j,jj,i,ii,k,nh,nm;
float *cr;
float den,p,q;
float ur,vr,wr,urtemp;
float pi,x;
float nf =(float)(n);
/* traduction de éléments du tableau */
a--;
/* Alloue un espace pour le tableau de travail. */
if ((cr=(float *)malloc(nf*sizeof(float)))==NULL) return(-1);
/* translate l'origine des tableaux de travail*/
cr--;
/*Transformée inverse et directe*/
if ( isgn < 0 )
den=1.0;
else
den=(float)(n);
/*constantes de mise à jour*/
pi = (float)(4.0 * atan( 1.0 ));
p = (float)(n);
q = (float)(log( p ) / log( 2.0 ));
k = (int)(q);
nh = n/2;
nm = n-1;
/*routine d'inversion des bits*/
for ( i=nh+1, j=1; i<=n; i++, j++ )
{
cr[j] = a[i];
}
for ( i=1; i<=nh; i++, j++ )
{
cr[j] = a[i];
}
for ( i=1, j=1; i<=nm; i++ )
{
if ( i < j )
{
vr = cr[j];
cr[j] = cr[i];
cr[i] = vr;
}
jj = nh;
while ( jj < j )
{
j -= jj;
jj = jj/2;
}
j += jj;
}
/*Transformée de Fourrier rapide*/
for ( l=1; l<=k; l++ )
{
l1 = (int)(ldexp( 1.0, l ));
x = (2 * pi * (float) isgn) / (float)(l1);
wr = (float)(cos( x ));
l2 = l1/2;
ur = 1.0;
for ( j=1; j<=l2; j++ )
{
for ( i=j; i<=n; i+=l1 )
{
ii = i + l2;
vr = (cr[ii] * ur );
cr[ii] = cr[i] - vr;
cr[i] = cr[i] + vr;
}
urtemp = ur;
ur = (ur * wr) ;
}
}
/*Echelle de sortie dépendant des transformées inverse ou directe*/
for ( i=1; i<=n; i++ )
{
cr[i] = cr[i] / den;
}
for ( i=nh+1, j=1; i<=n; i++, j++ )
{
a[j] = cr[i];
}
for ( i=1; i<=nh; i++, j++ )
{
a[j] = cr[i];
}
/* Espace libre du tableau de travail.*/
cr++;
free( cr );
a++;
return(1);
} |