#include#include #include //**************************************************************************************#ifndef M_PI #define M_PI 3.14159265358979323846#endif#define DATA_LEN 64#define SAMPLE_FREQ 1000 // Hzunsigned char sin_data[64] = {0x7F,0x8B,0x98,0xA4,0xB0,0xBB,0xC6,0xD0,0xD9,0xE2, 0xE9,0xEF,0xF5,0xF9,0xFC,0xFE,0xFE,0xFE,0xFC,0xF9,0xF5,0xEF,0xE9,0xE2,0xD9,0xD0, 0xC6,0xBB,0xB0,0xA4,0x98,0x8B,0x7F,0x73,0x66,0x5A,0x4E,0x43,0x38,0x2E,0x25,0x1C, 0x15,0x0F,0x09,0x05,0x02,0x00,0x00,0x00,0x02,0x05,0x09,0x0F,0x15,0x1C,0x25,0x2E, 0x38,0x43,0x4E,0x5A,0x66,0x73};typedef struct{ double r; double i;} cplx_t;//**************************************************************************************void cplx_exp(cplx_t *x, cplx_t *r){ double expx = exp(x->r); r->r = expx*cos(x->i); r->i = expx*sin(x->i);}// 复数乘法void cplx_mul(cplx_t *x, cplx_t *y, cplx_t *r){ r->r = x->r*y->r-x->i*y->i; r->i = x->r*y->i+x->i*y->r;}// 比特反置void bit_reverse(cplx_t *x, int N){ unsigned int i = 0,j = 0,k = 0; cplx_t tmp; int bit_num = log(0.0+N)/log(2.0); // 比特位数 for (i=0; i >= 1; } if (j>i) { tmp = x[i]; x[i] = x[j]; x[j] = tmp; } }}void fft(cplx_t *x, int N){ cplx_t u,d,p,W,tmp; int i=0,j=0,k=0,l=0; double M = floor(log(0.0+N)/log(2.0)); // zhiqiu 换底公式 if (log(0.0+N)/log(2.0)-M > 0) { printf("The length of x (N) must be a power of two!!!\n"); return; } bit_reverse(x,N); for (i = 0; i < M; i++) { l = 1< < N; i++) x[i].i = -x[i].i; fft(x,N); for (i = 0;i < N; i++) { x[i].r = x[i].r/(N+0.0); x[i].i = -x[i].i/(N+0.0); }}//**************************************************************************************int main(int argc, const char * argv[]){ int i; cplx_t x[DATA_LEN]; for (i=0;i