📄 fftdisplay.c
字号:
#include "math.h"
#include "dsp1io.h"
extern float *FFT_buff;
/************************************************************
name: fftdisplay
*************************************************************
description: translate FFT results output format
to SPC3,display, and indicator.
*************************************************************
prototype: void fftdisplay(void);
*************************************************************
reference: none
*************************************************************
revision history:
date content by version
03MAR02 create tom yue 3.01
26JUN02 comment tom yue 3.02
13JUL02 modify&comment ZhiguoTan 3.11
*************************************************************
algorithm: none
**************************************************************/
void fftdisplay(void)
{
unsigned *pfft,i,k,*pt,index;
unsigned long sample_rate;
unsigned long sample_freq;
float a_coef,t0,t1,*pf;
sample_rate=dsp1in.preset & 0xfe00;
switch(sample_rate) { //translate bit sign to sample_rate
case FFT_F300:
sample_freq=300;
break;
case FFT_F100:
sample_freq=100;
break;
case FFT_F30:
sample_freq=30;
break;
case FFT_F10:
sample_freq=10;
break;
case FFT_F3:
sample_freq=3;
break;
case FFT_F1:
sample_freq=1;
break;
default:
sample_freq=600;
break;
}
dsp1out.fftspc3.samples_freq=sample_freq; //output samples_frequency for SPC3
dsp1out.fftindicator.samples_freq=sample_freq;//output samples_frequency for indicator
dsp1out.fftdisplay.samples_freq=sample_freq; //output samples_frequency for display
dsp1out.fftspc3.stop_freq=sample_freq*10000/4; //output stop frequency for SPC3
dsp1out.fftindicator.stop_freq=sample_freq*10000/4; //output stop frequency for indicator
dsp1out.fftdisplay.stop_freq=sample_freq*10000/4; //output stop frequency for display
/*************************************/
/* prepare data for SPC3 */
/*************************************/
pfft=(unsigned *)dsp1out.fftspc3.dsp1addr;
pf=(float *)(FFT_buff+0x800);
//find maximum
t1=0.0; //clear t1
index=0;
for(i=0;i<1024;i++){
t0=FFT_buff[i]; //read fft results buffers
if(t1<t0)
{
t1=t0; //get maximum
index=i;
}
pf[i]=t0; //transform integer to SPC3 buffer
}
dsp1out.fftspc3.ampscale=t1*10000/2048;//707.1*t1/2048; //set amplitude scaling,units is um,RMS express
//a_coef=10000.0/t1; //normalize
a_coef = 10000.0/2048; // do not normalize, but scaled
for(i=0;i<1024;i++) pfft[i]=a_coef*pf[i];//transform data to SPC3 buffer
dsp1out.fftspc3.maxAmp_freq=index*sample_freq*10000/4096; //Frequency of the largest amplitude FFT result for SPC3
dsp1out.fftindicator.maxAmp_freq=index*sample_freq*10000/4096; //Frequency of the largest amplitude FFT result indicator
dsp1out.fftdisplay.maxAmp_freq=index*sample_freq*10000/4096; //Frequency of the largest amplitude FFT result display
/*************************************/
/* prepare date for indicator */
/*************************************/
pt=(unsigned *)dsp1out.fftindicator.dsp1addr;
pfft=(unsigned *)pf; //copy upper address
t1=0.0; //set max and pointer
for(i=0;i<256;i++){ //4:1 compress data
t0=0.0;
for(k=0;k<4;k++)
{
if(t0<FFT_buff[4*i+k])
{
t0=FFT_buff[4*i+k]; //get the maximum of every 4 data
}
}
if(t1<t0) t1=t0; //get max
pf[i]=t0; //save results
}
dsp1out.fftindicator.ampscale=t1*10000/2048;//707.1 * t1/2048;
//set amplitude scaling
a_coef=116.0/t1; //match indicator display
for(i=0;i<256;i++) pfft[i]=a_coef*pf[i];//normalize
//compress byte to word by 2:1
//one data in the high part of int16, next data in low part of int16
for(i=0;i<128;i++) pt[i]=(pfft[2*i]<<8)+pfft[2*i+1];
/*************************************/
/* prepare data for display */
/*************************************/
//for LCD 128*64, compress data 8:1
pt=(unsigned *)dsp1out.fftdisplay.dsp1addr;
pfft=(unsigned *)pf; //copy this address
t1=0.0; //set max and pointer
for(i=0;i<128;i++){ //8:1 compress data
t0=0.0;
for(k=0;k<8;k++)
{
if(t0<FFT_buff[8*i+k])
{
t0=FFT_buff[8*i+k]; //get the maximum of every 8 data
}
}
if(t1<t0) t1=t0; //get max
pf[i]=t0; //save results
}
dsp1out.fftdisplay.ampscale=t1*10000/2048;//ampliteude scaling compress
a_coef=53.0/t1; //match LCD display
for(i=0;i<128;i++) pfft[i]=a_coef*pf[i]; //ampliteude scaling compress
//compress byte to word by 2:1
//one data in the high part of int16, next data in low part of int16
for(i=0;i<64;i++) pt[i]=(pfft[2*i]<<8)+pfft[2*i+1];
dsp1out.FFT_rem_time=0; //inform mcu0 FFT finish
}
/****************************file end************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -