如题一共测试了三个fft的例子,都是调用fft库函数,在ccs5.3 条件下都编译调试通过了,能够运行,但均没有得到正确的波形,不知道是这三个算法都有问题,还是我看波形的位置和方式不对。恳请各位前辈帮助指导。我看的是Tools->graph->single time ->ipcbptr 这样是看输入的正弦波吧?
然后用Tools->graph->FFT magnitude ->sfft_f.mag 这样看FFT计算的幅值结果?
下面是第一个例子中(见附件一)计算的关键几步:
@ltbytyn
//Clean up all buffers
for(i=0; i < BUFFER_SIZE; i++){
SigBuffer
= 0;
InBuffer_f = 0;
MagBuffer_f = 0;
}
//Set the Signal Amplitude
a1 = _IQ15(0.33);
a2 = _IQ15(0.33);
a3 = _IQ15(0.33);
//Set the Signal Frequency
FreqMult1 =_IQ15(1);
FreqMult2 = _IQ15(0);
FreqMult3 = _IQ15(0);
//Calculating the digital frequency
b1 = _IQ15mpy(_IQ15(BASE_FREQ),FreqMult1);
b2 = _IQ15mpy(_IQ15(BASE_FREQ),FreqMult2);
b3 = _IQ15mpy(_IQ15(BASE_FREQ),FreqMult3);
k1 = _IQ15div(b1,_IQ15(SAMPLING_FREQ));
k2 = _IQ15div(b2,_IQ15(SAMPLING_FREQ));
k3 = _IQ15div(b3,_IQ15(SAMPLING_FREQ));
//Calculating the increments, in radians, for each of the
//3 sine waveforms
RadIncrements1 = _IQ15mpy(_IQ15(TWO_PI),k1);
RadIncrements2 = _IQ15mpy(_IQ15(TWO_PI),k2);
RadIncrements3 = _IQ15mpy(_IQ15(TWO_PI),k3);
//=================================
//Initializing Fixed point Routines
//=================================
// Initialize the FFT
sfft_f.ipcbptr= ipcb; // FFT computation buffer
sfft_f.magptr= MagBuffer_f; // Magnitude output buffer
sfft_f.winptr=(long *)win; // Window coefficient array
sfft_f.init(&sfft_f); // Twiddle factor pointer initialization
for( ;; ) //Infinte loop
{
//=================================
// Generating the input signal
//=================================
for(i = 0;i < BUFFER_SIZE; i++){
Rad1 = _IQ15mpy(RadIncrements1 ,_IQ15(i));
Rad2 = _IQ15mpy(RadIncrements2 ,_IQ15(i));
Rad3 = _IQ15mpy(RadIncrements3 ,_IQ15(i));
b1 = _IQ15sin(Rad1);
b2 = _IQ15sin(Rad2);
b3 = _IQ15sin(Rad3);
SigBuffer = (_IQ15mpy(a1,b1) + _IQ15mpy(a2,b2) + _IQ15mpy(a3,b3));
ipcbsrc = _IQtoIQ30(SigBuffer);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%FIXED POINT OPERATIONS%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//=================================
// Performing the FFT@ltbytyn
//=================================
//Clean up data buffer
for(i=0; i < (BUFFER_SIZE*2); i=i+2){
ipcb =0;
ipcb[i+1] = 0;
}
// real FFT bit reversing
RFFT32_brev(ipcbsrc, ipcb, BUFFER_SIZE);
sfft_f.calc(&sfft_f); // Compute the FFT
sfft_f.mag(&sfft_f); // Obtain the magnitude square , Q30 format (abs(ipcbsrc)/2^16).^2
//=================================
// END OF OPERATIONS
//=================================
asm(" NOP");
} //End of the infinite loop
}
此帖出自小平头技术问答
一周热门 更多>