由TI-28xx範例程式
源代码在线查看: fftrd.c
/* ==============================================================================
System Name: Real FFT - Software Test Bench (STB)
File Name: FFTRD.C
Description: Primary System file for demonstrating the Real FFT module
Originator: Advanced Embeeded Control (AEC) - Texas Instruments
Target dependency: x28x
Description:
============
*/
#include
#include
/* Create an instance of Signal generator module */
SGENTI_1 sgen = SGENTI_1_DEFAULTS;
/* Create an instance of DATALOG Module */
DLOG_4CH dlog=DLOG_4CH_DEFAULTS;
/* Create an Instance of FFT module */
#define N 128
#pragma DATA_SECTION(ipcb, "FFTipcb");
#pragma DATA_SECTION(mag, "FFTmag");
RFFT32 fft=RFFT32_128P_DEFAULTS;
long ipcb[N+2];
long mag[N/2+1];
/* Define window Co-efficient Array and place the
.constant section in ROM memory */
const long win[N/2]=HAMMING128;
/* Create an instance of FFTRACQ module */
RFFT32_ACQ acq=FFTRACQ_DEFAULTS;
int xn,yn;
void main()
{
/* DATALOG module initialisation */
dlog.iptr1=&xn;
dlog.iptr2=&yn;
dlog.trig_value=0x800;
dlog.size=0x400; /* Can log 1024 Samples */
dlog.init(&dlog);
/* Signal Generator module initialisation */
sgen.offset=0;
sgen.gain=0x7fff; /* gain=1 in Q15 */
sgen.freq=10000; /* freq = (Required Freq/Max Freq)*2^15 */
/* = (931/3051.7)*2^15 = 10000 */
sgen.step_max=10000; /* Max Freq= (step_max * sampling freq)/65536 */
/* Max Freq = (10000*20k)/65536 = 3051.7 */
/* Initialize acquisition module */
acq.buffptr=ipcb;
acq.tempptr=ipcb;
acq.size=N;
acq.count=N;
acq.acqflag=1;
/* Initialize FFT module */
fft.ipcbptr=ipcb;
fft.magptr=mag;
fft.winptr=(long *)win;
fft.init(&fft);
/*---------------------------------------------------------------------------
Nothing running in the background at present
----------------------------------------------------------------------------*/
while(1)
{
sgen.calc(&sgen);
xn=sgen.out;
yn=sgen.out;
dlog.update(&dlog);
acq.input=((unsigned long)xn) acq.update(&acq);
if (acq.acqflag==0) // If the samples are acquired
{
RFFT32_brev(ipcb,ipcb,N);
RFFT32_brev(ipcb,ipcb,N); // Input samples in Real Part
fft.win(&fft);
RFFT32_brev(ipcb,ipcb,N);
RFFT32_brev(ipcb,ipcb,N); // Input after windowing
fft.calc(&fft);
fft.split(&fft);
fft.mag(&fft);
acq.acqflag=1; // Enable the next acquisition
}
}
} /* End: main() */