本帖最后由 pangding 于 2012-12-18 16:36 编辑
我现在在学用dsp计算fft,芯片是2812的,现在输入一个简单的40HZ的正弦信号,采样1024HZ,采样1024个点做fft,看它的频率。可是我做256,512点的fft时结果都正常,调用1024点fft函数做时,结果就有问题了。我的程序是这样
#define N 1024 // FFT size
#pragma DATA_SECTION(ipcb, "FFTipcb"); // Input/output memory allocation
#pragma DATA_SECTION(ipcbsrc, "FFTipcbsrc");
#pragma DATA_SECTION(mag, "FFTmag");
long ipcbsrc[2*N];
long ipcb[2*N];
long mag[N];
long temp[N];
CFFT32 fft=CFFT32_1024P_DEFAULTS; // Header structure definition
/* Define window Co-efficient Array and place the
.constant section in ROM memory */
const long win[N/2]=HAMMING32; // Select window, not used in this example
void main()
{
unsigned long i;
InitSysCtrl();/*初始化系统*/
DINT;/*关中断*/
IER = 0x0000;
IFR = 0x0000; //清中断
InitPieCtrl();/*初始化PIE*/
InitPieVectTable(); /*初始化PIE中断矢量表*/
InitCpuTimers();/*初始化定时器0*/
InitPeripherals();/*初始化外设*/
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// Generate sample waveforms:
for(i=0; i < 2*N; i=i+2)
{
ipcbsrc =(long)(2147483648*(sin(2*3.1415*40*i/(2*1024)))); //Q31
ipcbsrc[i+1] = 0; //Q31
temp[i/2]=ipcbsrc;
}
//Clean up input/output buffer
for(i=0; i < (N*2); i=i+2)
{
ipcb =0;
ipcb[i+1] = 0;
}
/*---------------------------------------------------------------------------
Nothing running in the background at present
----------------------------------------------------------------------------*/
CFFT32_brev(ipcbsrc, ipcb, N); // Real part bit-reversing
CFFT32_brev(&ipcbsrc[1], &ipcb[1], N); // Imaginary part bit-reversing
fft.ipcbptr=ipcb; /* FFT computation buffer */
fft.magptr=mag; /* Magnitude output buffer */
fft.winptr=(long *)win; /* Window coefficient array */
fft.init(&fft); /* Twiddle factor pointer initialization */
fft.calc(&fft); /* Compute the FFT */
fft.mag(&fft); /* Q30 format (abs(ipcbsrc)/2^16).^2 */
//asm(" ESTOP0");
for(;;);
} /* End: main() */
这是结果图:
在中线之前为什么会出现两个频率?第一个峰值对应的频率正好i是40HZ,这两个频率还是对称的?做其他点的fft就一个频率,这是为什么?求帮助!
这是添加的cmd文件:
FFTipcb ALIGN[8192] :{} > ZONE6ipcb PAGE = 1
FFTmag : >ZONE6mag PAGE = 1
FFTtf : >ZONE6tf PAGE = 1
FFTipcbsrc : >ZONE6ipcbsrc PAGE = 1
ZONE6ipcb : origin = 0x100000, length = 0x001FFF
ZONE6mag : origin = 0x102000, length = 0x001FFF
ZONE6tf : origin = 0x104000, length = 0x001FFF
ZONE6ipcbsrc : origin = 0x106000, length = 0x001FFF
|