中间要填入的就是FFT运行的时间。请问采样点是怎样输入到FFT,如果是从A/D寄存器输入,又要怎样输入128,256个这么多点。还是输入FFT的必须为连续信号,也就是说:不能输入128个离散的呢,它的时间又是怎样测出来呢?我这有一段代码(仅仅是演示怎么用FFT库)
int *P_IOB_Data = 0x7005;
int *P_IOB_Dir = 0x7007;
int *P_IOB_Attrib = 0x7008;
int main()
{
int i, j, addr;
unsigned short k, max, sum, *port, *gOut;
int maxID;
*P_IOB_Dir = 0xFFFF;
*P_IOB_Attrib = 0xFFFF;
*P_IOB_Data = 0x0000;
SystemInitial();
maxID = Get_FFT256_Version();
InitFFT();
while(1)
{
addr = GetFFT();
max = maxID = 0;
gOut = addr;
while (*gOut == 1)
{
gOut+=2;
for(i=1;i<128; i++)
{
sum = *gOut++;
//---------------------------------------------------------------------------
// Get FFT Sample process
// User have to implement this according to get data from mic or line in
// return r1 = FFT sample
//
.public F_GetFFTSample
F_GetFFTSample: .proc
这里我贴出了FFT256 Library User’s Manual说明书的一些说明:
1.The FFT256 library provides 256 points Fast Fourier Transform. If the sampling rate is 8KHz, we have 128 points spectrum from 0 to 4KHz.(这个库是256个采样点的)
2.Users have to put the service loop in the main loop to keep entering the serviceregularly. Inside the FFT256service loop, there will be a mechanism to decide any task should be carried on. Some overhead will produced inevitably. The amount of overhead varies and depends on the payload of CPU.
Example:
In main.c
int main()
{
System_Initial();// System initial
InitFFT ();// FFT initial
while(1)// start FFT
{
addr = GetFFT();// Get FFT result
FFTServiceLoop ();// FFT Service loop
System_ServiceLoop();// Service loop for watchdog clear
}
return 0;
}
In isr.asm:
_FIQ:
Push r1, r5 to [sp] // Save registers
Call F_FFTService_ISR // Interrupt service routine
R1 = C_IRQ0_TMA
[P_INT_Clear] = R1 // Clear interrupt flag
Pop r1, r5 from [sp] // restore registers
reti
Remark:
1. This function is used in assembly only and it can be hooked on the _FIQ, _IRQ1 or _IRQ2:
label. (See isr.asm for details)
2. The F_FFTSerivce_ISR will not take up any time to process the Interrupt routine except
minor overheads if the program is not in FFT mode. It is possible for users to place
user-define function in the same FIQ or IRQ.
3. This function calls the F_GetFFTSample to get data from mic or line in.
3.How to use the FFT256 library
Main()
{
InitFFT (); // FFT initial
while(1)
{
addr = GetFFT();
FFTServiceLoop ();
System_ServiceLoop();
} // end of while
return 0;
} // end of main
其中,函数GetFFT()说明:
返回值:int*: spectrum address
Library: FFT256.lib
Remark:
1. address[0] is spectrum ready flag
2. address[1:128] are FFT results from 0 to 4KHz while sampling rate is 8KHz.
函数InitFFT()说明:
Remark:
1. This function initializes the Kernel of FFT.
2. The hardware setting is opened for user’s reference (see SystemInitial in system.asm). It
initializes the System Clock, Timer A, ADC, DAC and enables the Timer A FIQ at the sample rate
on 8KHz.
a stable signal pattern (e.g. a 1kHz sine-wave) input to the Sunplus's A/D input pin for your FFT data input and trial calculation.
Regarding to the FFT time consumption measurement:
1. the start point is measured during the input data is ready (e.g. the Window size is 128, so after A/D convert complete the 128th data sampling, it's the starting point)
2. the end point is counted during the output data is ready (same as the example above, when the 128th output data is done, that is the end point)
How to mark the starting and end point, you may use programming to read the time, or program the GPIO (e.g. to generate a pulse) on Sunplus to indicate the start and end point.
引用 19 楼 zhongyuanceshi 的回复:
How to mark the starting and end point, you may use programming to read the time, or program the GPIO (e.g. to generate a pulse) on Sunplus to indicate the start and end point.