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
| #define PI 3.141592
#define SWAP(a,b) tempr=(a);(a)=(b);(b)=tempr
/* ******** FFT ********************************/
void FFT(float data[], int N, int isign)
{
int n,mmax,m,j,istep,i;
float wtemp,wr,wpr,wpi,wi,theta,tempr,tempi;
n=N * 2;
j=0;
for (i=0;i<n/2;i+=2) {
if (j > i) {
SWAP(data[j],data[i]);
SWAP(data[j+1],data[i+1]);
if((j/2)<(n/4)){
SWAP(data[(n-(i+2))],data[(n-(j+2))]);
SWAP(data[(n-(i+2))+1],data[(n-(j+2))+1]);
}
}
m=n/2;
while (m >= 2 && j >= m) {
j -= m;
m = m/2;
}
j += m;
}
mmax=2;
//external loop
while (n > mmax)
{
istep = mmax<< 1;
theta=isign*(6.2831853/mmax);
wtemp=sin(0.5*theta);
wpr = -2.0*wtemp*wtemp;
wpi=sin(theta);
wr=1.0;
wi=0.0;
//internal loops
for (m=0;m<mmax;m+=2) {
for (i= m;i<=n;i+=istep) {
j=i+mmax;
tempr=wr*data[j-1]-wi*data[j];
tempi=wr*data[j]+wi*data[j-1];
data[j-1]=data[i-1]-tempr;
data[j]=data[i]-tempi;
data[i-1] += tempr;
data[i] += tempi;
}
wr=(wtemp=wr)*wpr-wi*wpi+wr;
wi=wi*wpr+wtemp*wpi+wi;
}
mmax=istep;
}
} |
Partager