📄 firfft.c
字号:
/************************************************************
name: PD25XY-fftdisplay.c
description: If FFT is completed then return 0, else return fft buf index.
prototype: void firfft(float temp)
call: firfft(temp)
position: dsp1.mak
version: 1.0 date: 2001-12-19
author: tom yue date: 2001-12-19
check: tom yue date:
approval:
remark: The input is processed at following procedure:
1,filter (multirate multistage fir);
2,buffer the filtered data and window it
3,transform the windowed data to frequence domain
***********************************************************
history
date:23JUN02 by: TZG
update: add comment
***********************************************************/
#include "math.h"
#include "regs54xx.h"
#include "dsp1io.h"
#include "fir.h"
#include "fft.h"
void hamming_win_proc0(
float *x, /* the data which will be windowed */
int n, /* the number of the data which will be windowed */
float tx /* hamming window coefficient */);
extern float *FFT_buff;
extern int FFT_buf_counter;
unsigned firfft(float temp)
{
float t0; //remain time for FFT
unsigned ui; //corrently selected FFT rate
static unsigned ysample_rate=0; //past selected FFT rate
unsigned f0; //sample frequent
/* if the FFT stop command is 1, then do nothing but return 1 */
if(dsp1in.preset & CMD_FFTSTP) {
dsp1out.FFT_rem_time |=1;
FFT_buf_counter=0;
return 1;
}
/* get the FFT rate*/
ui=dsp1in.preset; ui &=0xfe00; //if the desired filter has been changed,
if(ysample_rate !=ui){ //initialize the filter-and-FFT system.
initial_filter();
FFT_buf_counter=0;
ysample_rate=ui;
}
//test function
/* static long n=0;
temp=sin(0.031415926*n);
n++;
*/
/* according to different FFT rate, do corresponding fir */
switch(ysample_rate){
case FFT_F300:
fir(5,temp);
f0=300;
break;
case FFT_F100:
fir(4,temp);
f0=100;
break;
case FFT_F30:
fir(3,temp);
f0=30;
break;
case FFT_F10:
fir(2,temp);
f0=10;
break;
case FFT_F3:
fir(1,temp);
f0=3;
break;
case FFT_F1:
fir(0,temp);
f0=1;
break;
default:
fir(6,temp);
f0=600;
break;
}
/* compute the remain time for FFT */
t0=(4096-FFT_buf_counter);t0 /=f0; t0+=1;
if(t0>4096/f0) t0=0;
dsp1out.FFT_rem_time=t0;
/* if the buffer is not full,then return the current index of buffer*/
if(FFT_buf_counter<4096) return FFT_buf_counter+1;
//test function
/* int i;
for(i=0;i<4096;i++)
{
FFT_buff[i]=2*sin(0.1*i);
}
FFT_buf_counter=4096;
*/
/* according to different FFT rate, add corresponding window */
// hamming_win_proc0(FFT_buff,4096,1);
/* compute the FFT */
fft(FFT_buff,4096);
int k;
for(k=0;k<4;k++)
{
FFT_buff[k]=0.0;
}
FFT_buf_counter=0;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -