Files
player/Project/Src/MyApp/fft2d.c

127 lines
2.5 KiB
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#include "string.h"
#include "stdio.h"
#include "arm_math.h"
#include "stm32f4xx.h"
#include "mymem.h"
#include "fft2d.h"
int FFT2D_Init (FFT2D_Struct *fft2d,int len)
{
fft2d->fftLen=len;
if (arm_rfft_fast_init_f32 (&fft2d->fftStruct,len)==0)
{
fft2d->imgBuff=mymalloc (len*len*sizeof (float32_t));
fft2d->columnOutBuff=mymalloc (len*sizeof (float32_t));
fft2d->rowInBuff=mymalloc (len*sizeof (float32_t));
if ((fft2d->imgBuff!=0) &&(fft2d->columnOutBuff!=0) && (fft2d->rowInBuff!=0))
return 0;
else
{
myfree(fft2d->imgBuff);
myfree(fft2d->columnOutBuff);
myfree(fft2d->rowInBuff);
}
}
return -1;
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>Ҷ<EFBFBD>任ָ<E4BBBB><D6B8>ͼ<EFBFBD><CDBC>
2025-06-27 00:32:57 +08:00
void FFT2D_Rfft (FFT2D_Struct *fft2d,float32_t *img,int xsize,int ysize)
{
2025-07-05 19:47:28 +08:00
//<2F>任512<31><32>
2025-06-27 00:32:57 +08:00
for (int i=0;i<fft2d->fftLen;i++)
{
2025-07-05 19:47:28 +08:00
//<2F>һ<E4BBBB><D2BB>
2025-06-27 00:32:57 +08:00
if (i<ysize)
{
for (int j=0;j<fft2d->fftLen;j++)
{
if (j<xsize)
{
fft2d->rowInBuff[j]=img[i*xsize+j];
}
else
{
fft2d->rowInBuff[j]=0;
}
}
}
else
{
for (int j=0;j<fft2d->fftLen;j++)
{
fft2d->rowInBuff[j]=0;
}
}
arm_rfft_fast_f32 (&fft2d->fftStruct,fft2d->rowInBuff,fft2d->imgBuff+i*fft2d->fftLen,0);
}
2025-07-05 19:47:28 +08:00
//<2F>任512<31><32>
2025-06-27 00:32:57 +08:00
for (int i=0;i<fft2d->fftLen;i++)
{
2025-07-05 19:47:28 +08:00
//<2F>һ<E4BBBB><D2BB>
2025-06-27 00:32:57 +08:00
for (int j=0;j<fft2d->fftLen;j++)
{
fft2d->rowInBuff[j]=fft2d->imgBuff[j*fft2d->fftLen+i];
}
arm_rfft_fast_f32 (&fft2d->fftStruct,fft2d->rowInBuff,fft2d->columnOutBuff,0);
for (int j=0;j<fft2d->fftLen;j++)
{
fft2d->imgBuff[j*fft2d->fftLen+i]=fft2d->columnOutBuff[j];
}
}
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>Ҷ<EFBFBD><D2B6><EFBFBD><EFBFBD><E4BBBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>任FFT2D_Struct.imgBuff <20>д洢<D0B4><E6B4A2>ͼ<EFBFBD><CDBC>
2025-06-27 00:32:57 +08:00
void FFT2D_Rifft (FFT2D_Struct *fft2d,float32_t *img)
{
float32_t *inImg=0;
if (img) inImg=img; else inImg=fft2d->imgBuff;
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>任512<31><32>
2025-06-27 00:32:57 +08:00
for (int i=0;i<fft2d->fftLen;i++)
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>һ<E4BBBB><D2BB>
2025-06-27 00:32:57 +08:00
for (int j=0;j<fft2d->fftLen;j++)
{
fft2d->rowInBuff[j]=inImg[j*fft2d->fftLen+i];
}
arm_rfft_fast_f32 (&fft2d->fftStruct,fft2d->rowInBuff,fft2d->columnOutBuff,1);
for (int j=0;j<fft2d->fftLen;j++)
{
fft2d->imgBuff[j*fft2d->fftLen+i]=fft2d->columnOutBuff[j];
}
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>任512<31><32>
2025-06-27 00:32:57 +08:00
for (int i=0;i<fft2d->fftLen;i++)
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>һ<E4BBBB><D2BB>
2025-06-27 00:32:57 +08:00
for (int j=0;j<fft2d->fftLen;j++)
{
fft2d->rowInBuff[j]=fft2d->imgBuff[i*fft2d->fftLen+j];
}
arm_rfft_fast_f32 (&fft2d->fftStruct,fft2d->rowInBuff,fft2d->imgBuff+i*fft2d->fftLen,1);
}
}
void FFT2D_Delete (FFT2D_Struct *fft2d)
{
myfree(fft2d->imgBuff);
myfree(fft2d->columnOutBuff);
myfree(fft2d->rowInBuff);
}