¡Utilice el lenguaje VC para escribir el código fuente del programa de transformación de Fourier de señal!
void FFT 1(float a_r 1[], float a_im[], int ex, bool inv)
{
int i, longitud = 1;
flotador * sin _ tbl
flotador * cos _ tbl
flotador * buf
for(I = 0 ;i<ex;i++)
{
longitud* = 2;
}
sin_tbl = (float * )malloc(longitud * tamaño de(float));
cos _ TBL =(float *)malloc(longitud * tamaño de(float));
buf =(float * )malloc(longitud * tamaño de(float));
cstb(length, inv, sin_tbl, cos _ TBL);
fft1core(a_r1, a_im, length, ex, sin_tbl, cos_tbl, buf) ;
Gratis (sin_TBL);
Gratis (cos_TBL);
Gratis (buf);
}
Dos dimensiones:
void FFT2(float *a_rl, float *a_im, bool inv, int xsize, int ysize)
{
float *b_rl , *b_im
float *hsin_tbl, *hcos_tbl, *vsin_tbl, *vcos_tbl
float *buf_x, *buf_y ;
int I;
b _ rl =(float *)calloc(xsize * ysize, sizeof(float));
b _ im =( float *)calloc(xsize * ysize, sizeof(float));
hsin_tbl=(float *)calloc(xsize, sizeof(float));
hcos_tbl=(float * )calloc(xsize, sizeof(float));
vsin_tbl=(float *)calloc(ysize, sizeof(float));
VCO _ TBL = (float *)calloc (ysize, sizeof(float));
buf _ x =(float *)malloc(xsize * sizeof(float));
buf _ y =(float *)malloc (ysize * sizeof(float));
cstb(xsize, inv, hsin_tbl, hcos_TBL);
cstb(ysize, inv, vsin_tbl, VCO_TBL);
int x _ exp =(int)(log(double( xsize))/log(2.0));
for(I = 0;i<ysizei++)
{
FFT 1 núcleo(& amp(*(a_rl +i*xsize)), & amp(*(a_im+i*xsize)), xsize, x_exp, hsin_t
bl, hcos_tbl, buf_x);
}
rvmtx1(a_rl, b_rl, xsize, ysize); ;
int y_exp =(int)(log(double(ysize))/log(2.0));
for(I = 0;i<xsizei++)
{
FFT 1 núcleo(& amp(*(b_rl+i*ysize)), & amp(*(b_im+i*ysize)), ysize, y_exp, vsin_tbl, vcos _ tbl, buf _ y);
}
rvmtx2(b_rl, a_rl, xsize, ysize);
rvmtx2(b_im, a_im, xsize, ysize); p>
Gratis (b_rl);
Gratis (b_im);
Gratis (hsin_TBL);
Gratis (hcos_TBL);
gratis(vsin_TBL);
Gratis(VCO_TBL);
Gratis(buf_x);
Gratis(buf_y);
}
Función utilizada:
void fft1core(float a_rl[], float a_im[], int length, int ex, float sin_tbl[], float cos_tbl[], float buf [])
{
int i, j, k, w, j1, J2
int número, lenb, timb
float xr, yr, yi, nrml
for(I = 1; i & lt longitud ;i+=2)
{
a _ rl[ I]=-a_rl[I];
a_im[I]=-a_im[I]
}
número =; 1;
lenb = longitud
for(I = 0; i<ex;i++)
{
lenb/= 2;
timb = 0;
for(j = 0; j & ltlenbk++)
{
w = 0;
for(k = 0; k & ltlenbk++)
{
j 1 = Tim b+ k
J2 = j 1+lenb;
xr = a_rl[j 1];
Xi = a_im[j 1];
año = a_rl[J2];
yi = a_im[J2]
a_rl[j 1]= xr+yr;
a_im[j 1]= Xi+yi;
xr = xr-yr;
Xi = Xi-yi;
a _ rl[J2]= xr * cos _ TBL[ w]-Xi * sin _ TBL[w];
a _ im [J2]= xr * sin _ TBL[w]+Xi * cos _ TBL[w];
w+=número;
}
Tim b+ =(2 * lenb);
}
número * = 2;
}
birv(a_rl, longitud, ex, b
uf);
birv(a_im, longitud, ex, buf);
for(I = 1; i< longitud; i+=2)
{
a_rl[I]=-a_rl[I];
a_im[I]=-a_im[I];
}
nrml=1/sqrt(flotador(longitud)).
for(I = 0;i<length;i++)
{
a _ rl[I]* = nrml;
a_im [I]* = nrml;
}
}
void cstb(int length, bool inv, float sin_tbl[], float cos_tbl[])
{
int I;
Punto flotante xx, arg
xx = float((-PI)* 2/longitud);
si (!inv)
{
xx =-xx;
}
para(I = 0;i<length;i++)
{
arg = i * xx
sin _ TBL[I]= sin (arg);
cos _ TBL[I]= cos(arg);
}
}
void birv(float a[], int length, int ej, float b[])
{
int i, ii, k, bit
for(I = 0 ;i<length;i++)
{
for(k=0,ii=i,bit=0;;bit<<=1,ii>>= 1)
{
bit =(ii & amp; 1)|bit;
if(++k==ex)
{
Romper;
}
}
b[I]= a[bit];
}
for(I = 0;i<longitud ;i++)
{
a[I]= b[I];
p>}
}
void rvmtx1(float *a, float *b, int xsize, int ysize)
{
int i, j
for(j; = 0; j & ltysizej++)
{
for(I = 0; i & ltxsizei++)
{
*(b+ I * ysize+j)= *(a+j * xsize+I);
}
}
}
nulo rvmtx2(float *a, float *b, int xsize, int ysize)
{
int i, j
for(j = 0; j; & ltysizej++)
{
for(I = 0; i & ltxsizei++)
{
*(b+j * xsize +I)= *(a+I * ysize+j);
}
}
}