This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

做FFT,很奇怪



这个做FFT一次程序不会跑飞,但循环做,程序就会跑飞,不知道为啥,

#include <math.h>
#include "data.h"
#include "function.h"
#include "dsp_fft16x32.h"
/* ======================================================================== */
/* Macro definition                                                         */
/* ======================================================================== */
#define PI  (3.141592654)
#define NN  (32)
/* ======================================================================== */
/* Input and output arrays                                                  */
/* ======================================================================== */
#pragma DATA_ALIGN(x, 8)
#pragma DATA_ALIGN(y, 8)
int x[2*NN];
int y[2*NN];
unsigned  mag[NN];
/* -------------------------------------------------------------------- */
/*  Automatically generated twiddle-factor array.                       */
/*      Number of points:    32                                         */
/*      Scale factor:        32767.500000000                            */
/*      Appropriate FFTs:    DSP_fft16x32, DSP_ifft16x32                */
/*      Required alignment:  8 byte (double-word)                       */
/* -------------------------------------------------------------------- */
#pragma DATA_ALIGN(w, 8);
const short w[2 * 30] =
{
    0x0000,  0x7FFF,  0x0000,  0x7FFF,  0x0000,  0x7FFF,  0x18F8,  0x7D89,
    0x30FB,  0x7641,  0x471C,  0x6A6D,  0x30FB,  0x7641,  0x5A82,  0x5A82,
    0x7641,  0x30FB,  0x471C,  0x6A6D,  0x7641,  0x30FB,  0x7D89, -0x18F8,
    0x5A82,  0x5A82,  0x7FFF,  0x0000,  0x5A82, -0x5A82,  0x6A6D,  0x471C,
    0x7641, -0x30FB,  0x18F8, -0x7D89,  0x7641,  0x30FB,  0x5A82, -0x5A82,
   -0x30FB, -0x7641,  0x7D89,  0x18F8,  0x30FB, -0x7641, -0x6A6D, -0x471C,
    0x0000,  0x7FFF,  0x0000,  0x7FFF,  0x0000,  0x7FFF,  0x5A82,  0x5A82,
    0x7FFF,  0x0000,  0x5A82, -0x5A82
};
void main(void)
{
	int i;
	memset(mag,0,sizeof(unsigned int)*NN);
	PLL_INIT();

	while(1)
	{
		for(i=0;i<NN;i++)
			{
				x[2*i] = 32767./(2*NN) *(cos(2*PI*1875*i/9600) );
				x[2*i+1]=32767./(2*NN) *(sin(2*PI*1875*i/9600) );
			}
			//显示频率为(fs/N)*位置
			DSP_fft16x32(w, NN, x, y);
			for(i=0;i<NN;i++)
				mag[i]=sqrt(y[2*i]*y[2*i]+y[2*i+1]*y[2*i+1]);//求变换后的幅度
			i = 0 ;
	}
}

见程序,求解答