TI中文支持网
TI专业的中文技术问题搜集分享网站

调用controlsuilt的定点FFT库计算512点FFT,请问怎么将输出的幅值还原成真实值?

我用的28335,调用controlsuilt的定点FFT库例程计算512点FFT,代码如下,输出的是幅值的平方,而且是Q30格式,

fft.mag(&fft);/* Q31 format (abs(ipcbsrc)/2^16).^2 */  ,请问怎么将输出的幅值还原成真实值?
//######################################################################################
// $TI Release: C28x Fixed Point Library v1.01 $
// $Release Date: January 11,2011 $
//######################################################################################

#include "DSP28x_Project.h"
#include <fft.h>
#include "math.h"
#include "float.h"
/* Create an Instance of FFT module*/
#defineN512 								// FFT size

#pragma DATA_SECTION(ipcb, "FFTipcb");			// Input/output memory allocation
#pragma DATA_SECTION(ipcbsrc, "FFTipcbsrc");
long ipcbsrc[2*N];								
long ipcb[2*N];  

RFFT32  fft=RFFT32_512P_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
int xn,yn;										

float	RadStep = 0.1963495408494f;				// Simulated signal generation parameter
float	Rad = 0.0f;								// Initial value of Radstep

void main()
{unsigned long i;InitSysCtrl();
		DINT;
		InitPieCtrl();
		IER = 0x0000;
		IFR = 0x0000;
		InitPieVectTable();
		EINT;// Enable Global interrupt INTM
		ERTM;// Enable Global realtime interrupt DBGM// Generate sample waveforms:
		Rad = 0.0f;		

		//Clean up input/output buffer
		for(i=0; i < (N*2); i=i+2)
		{
		ipcb[i]  =0;
		ipcb[i+1] = 0;
		}

		//Simulated input signal
		for(i=0; i < N; i++)
		{
		ipcbsrc[i]  =(long)(2147483648*(sin(Rad) + cos(Rad*2.3567))/2);  //Q31
		Rad = Rad + RadStep;
		}

/*---------------------------------------------------------------------------	FFT Calculation
----------------------------------------------------------------------------*/
		RFFT32_brev(ipcbsrc, ipcb, N);	/* real FFT bit reversing*/

		fft.ipcbptr=ipcb;				/* FFT computation buffer	*/
		fft.magptr=ipcbsrc;				/* 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);			/* Q31 format (abs(ipcbsrc)/2^16).^2 */
		
		//asm("ESTOP0");
		for(;;);

} /* End: main() */

fw yang:同问

我用的28335,调用controlsuilt的定点FFT库例程计算512点FFT,代码如下,输出的是幅值的平方,而且是Q30格式,

fft.mag(&fft);/* Q31 format (abs(ipcbsrc)/2^16).^2 */  ,请问怎么将输出的幅值还原成真实值?
//######################################################################################
// $TI Release: C28x Fixed Point Library v1.01 $
// $Release Date: January 11,2011 $
//######################################################################################

#include "DSP28x_Project.h"
#include <fft.h>
#include "math.h"
#include "float.h"
/* Create an Instance of FFT module*/
#defineN512 								// FFT size

#pragma DATA_SECTION(ipcb, "FFTipcb");			// Input/output memory allocation
#pragma DATA_SECTION(ipcbsrc, "FFTipcbsrc");
long ipcbsrc[2*N];								
long ipcb[2*N];  

RFFT32  fft=RFFT32_512P_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
int xn,yn;										

float	RadStep = 0.1963495408494f;				// Simulated signal generation parameter
float	Rad = 0.0f;								// Initial value of Radstep

void main()
{unsigned long i;InitSysCtrl();
		DINT;
		InitPieCtrl();
		IER = 0x0000;
		IFR = 0x0000;
		InitPieVectTable();
		EINT;// Enable Global interrupt INTM
		ERTM;// Enable Global realtime interrupt DBGM// Generate sample waveforms:
		Rad = 0.0f;		

		//Clean up input/output buffer
		for(i=0; i < (N*2); i=i+2)
		{
		ipcb[i]  =0;
		ipcb[i+1] = 0;
		}

		//Simulated input signal
		for(i=0; i < N; i++)
		{
		ipcbsrc[i]  =(long)(2147483648*(sin(Rad) + cos(Rad*2.3567))/2);  //Q31
		Rad = Rad + RadStep;
		}

/*---------------------------------------------------------------------------	FFT Calculation
----------------------------------------------------------------------------*/
		RFFT32_brev(ipcbsrc, ipcb, N);	/* real FFT bit reversing*/

		fft.ipcbptr=ipcb;				/* FFT computation buffer	*/
		fft.magptr=ipcbsrc;				/* 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);			/* Q31 format (abs(ipcbsrc)/2^16).^2 */
		
		//asm("ESTOP0");
		for(;;);

} /* End: main() */

fw yang:

用的是定点库的2833x_FixedPoint_RFFT

原始信号幅值分别为1和6,除以7,总幅值为1;

但调用函数后计算结果再开根号分别为0.0714和0.4284,加起来幅值为0.5001,为原总幅值的一半,是否库有问题?请问如何复原幅值?

从目前结果看是乘以2可解决,但我也不确定到底是不是这样

赞(0)
未经允许不得转载:TI中文支持网 » 调用controlsuilt的定点FFT库计算512点FFT,请问怎么将输出的幅值还原成真实值?
分享到: 更多 (0)