如题一共测试了三个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
}
此帖出自小平头技术问答
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(2);
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)+341000000+277316429;
}
sin(2*pi*f*t) f是采样信号频率,t是采样时间
或者换算成sin(2*pi*f*i/(f*FFT_SIZE))
关于波形产生函数,例子中注释是这样说的:
//=================================
// Generating the sine waves
//=================================
//-----------------------------------------------------------------------------
// x(t) = A*Sin(omega*t + theta) ,omega->circular frequency, theta->phase
//
// Assume the phase to be 0, i.e. theta = 0
//
// x(t) = A*Sin(omega*t)
// omega = 2*pi*f
//
// We sample the Sine wave at atleast twice its maximum frequency f
// (Nyquist criteria) to get a discrete time representation
// fs(sampling frequency) = m*f, where m >= 2
// Ts(sampling period) = k*T, where k = 1/m(k<=0.5) and T = 1/f
//
// x(nTs) = A*Sin(2*pi*(1/T)*(n*Ts))
// x(n) = A*Sin(2*pi*(1/T)*(n*k*T)), Ts is implicit
// x(n) = A*Sin(2*pi*n*k)
//
// k is the freqeuncy related factor here.
上面的注释说明是和程序对应起来的,你看我的a1,a2,a3是正弦波幅值,b1,b2,b3是正弦波 ,比如b1 = _IQ15sin(Rad1);
而Rad1 = _IQ15mpy(RadIncrements1 ,_IQ15(i));即RadIncrements1*i(i从0到128)
RadIncrements1 = _IQ15mpy(_IQ15(TWO_PI),k1);即2*pi*k,两步连起来就是注释中说的2*pi*n*k
而k=f/fs(基频/采样频率),因为b1 = _IQ15mpy(_IQ15(BASE_FREQ),FreqMult1);
k1 = _IQ15div(b1,_IQ15(SAMPLING_FREQ) ;(此处b1在正弦波产生之前用来存储中间值,节省内存)
你看这样有问题吗?
不要让那些东西蒙蔽,你自己细细想一下,你画个正弦波(频率随便选),让后分N个点采样,你在算一下,采样点是否与计算值合适。
一周热门 更多>