H
hrj28
Unregistered / Unconfirmed
GUEST, unregistred user!
我找了一个C语言得fft代码。请大哥帮忙转成delphi的。谢谢了。在线等。
/*****************fft programe*********************/
*基二FFT算法*/
#include "math.h"
#include "stdio.h"
struct compx
{ double real;
double imag;
} compx ;
struct compx EE(struct compx b1,struct compx b2)
{
struct compx b3;
b3.real=b1.real*b2.real-b1.imag*b2.imag;
b3.imag=b1.real*b2.imag+b1.imag*b2.real;
return(b3);
}
void FFT(struct compx *xin,int N)
{
int f,m,LH,nm,i,k,j,L;
double p , ps ;
int le,B,ip;
float pi;
struct compx v,w,t;
LH=N/2;
f=N;
for(m=1;(f=f/2)!=1;m++){;}
nm=N-2;
j=N/2;
/*变址运算*/
for(i=1;i<=nm;i++)
{
if(i<j){t=xin[j];xin[j]=xin;xin=t;}
k=LH;
while(j>=k){j=j-k;k=k/2;}
j=j+k;
}
{
for(L=1;L<=m;L++)
{
le=pow(2,L);
B=le/2;
pi=3.14159;
for(j=0;j<=B-1;j++)
{
p=pow(2,m-L)*j;
ps=2*pi/N*p;
w.real=cos(ps);
w.imag=-sin(ps);
for(i=j;i<=N-1;i=i+le)
{
ip=i+B;
t=EE(xin[ip],w);
xin[ip].real=xin.real-t.real;
xin[ip].imag=xin.imag-t.imag;
xin.real=xin.real+t.real;
xin.imag=xin.imag+t.imag;
}
}
}
}
return ;
}
/*****************main programe********************/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
float result[257];
struct compx s[257];
int Num=16;
const float pp=3.14159;
main()
{
int i;
for(i=0;i<16;i++)
{
s.real=sin(pp*i/32);
s.imag=0;
}
FFT(s,Num);
for(i=0;i<16;i++)
{
printf("%.4f",s.real);
printf("+%.4fj/n",s.imag);
result=sqrt(pow(s.real,2)+pow(s.imag,2));
}
}
/*****************fft programe*********************/
*基二FFT算法*/
#include "math.h"
#include "stdio.h"
struct compx
{ double real;
double imag;
} compx ;
struct compx EE(struct compx b1,struct compx b2)
{
struct compx b3;
b3.real=b1.real*b2.real-b1.imag*b2.imag;
b3.imag=b1.real*b2.imag+b1.imag*b2.real;
return(b3);
}
void FFT(struct compx *xin,int N)
{
int f,m,LH,nm,i,k,j,L;
double p , ps ;
int le,B,ip;
float pi;
struct compx v,w,t;
LH=N/2;
f=N;
for(m=1;(f=f/2)!=1;m++){;}
nm=N-2;
j=N/2;
/*变址运算*/
for(i=1;i<=nm;i++)
{
if(i<j){t=xin[j];xin[j]=xin;xin=t;}
k=LH;
while(j>=k){j=j-k;k=k/2;}
j=j+k;
}
{
for(L=1;L<=m;L++)
{
le=pow(2,L);
B=le/2;
pi=3.14159;
for(j=0;j<=B-1;j++)
{
p=pow(2,m-L)*j;
ps=2*pi/N*p;
w.real=cos(ps);
w.imag=-sin(ps);
for(i=j;i<=N-1;i=i+le)
{
ip=i+B;
t=EE(xin[ip],w);
xin[ip].real=xin.real-t.real;
xin[ip].imag=xin.imag-t.imag;
xin.real=xin.real+t.real;
xin.imag=xin.imag+t.imag;
}
}
}
}
return ;
}
/*****************main programe********************/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
float result[257];
struct compx s[257];
int Num=16;
const float pp=3.14159;
main()
{
int i;
for(i=0;i<16;i++)
{
s.real=sin(pp*i/32);
s.imag=0;
}
FFT(s,Num);
for(i=0;i<16;i++)
{
printf("%.4f",s.real);
printf("+%.4fj/n",s.imag);
result=sqrt(pow(s.real,2)+pow(s.imag,2));
}
}