⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_fftexample.c

📁 MICROCHIP的DSPIC系列的30F6014单片机的32点FFT计算
💻 C
字号:
#include <p30Fxxxx.h>
#include <dsp.h>
#include "fft.h"

_FOSC(CSW_FSCM_OFF & XT_PLL8);          /* XT with 8xPLL oscillator, Failsafe clock off */
_FWDT(WDT_OFF);                         /* Watchdog timer disabled */
_FBORPOR(PBOR_OFF & MCLR_EN);           /* Brown-out reset disabled, MCLR reset enabled */
_FGS(CODE_PROT_OFF);                    /* Code protect disabled */
extern void SquareMagnitudeCplx(int, fractcomplex*, fractional*); /*This function computes the squared magnitude of elements in a complex vector */
extern fractcomplex sigCmpx[FFT_BLOCK_LENGTH] __attribute__ ((section (".ydata, data, ymemory"), aligned (FFT_BLOCK_LENGTH * 2 *2)));      		/* of an input signal. For this example, */
/* Global Definitions */
extern const fractcomplex twiddleFactors[FFT_BLOCK_LENGTH/2]__attribute__ ((space(auto_psv), aligned (FFT_BLOCK_LENGTH*2)));
extern long SpecPower[8];
extern long Temp;
extern fractional *preal= &sigCmpx[0].real ;
extern float Spec[8];
extern long long BuffHspec;
extern long temp;

int main(void)
{
    
	FFT32();
    while (1);
}

void FFT32(void)
{
    int i = 0;
    fractional *p_real = &sigCmpx[0].real ;
	fractcomplex *p_cmpx = &sigCmpx[0] ;
	for ( i = 0; i < FFT_BLOCK_LENGTH; i++ )
	{					
		*p_real = *p_real >>1 ;		
		*p_real++;			
	}				
	p_real = &sigCmpx[(FFT_BLOCK_LENGTH/2)-1].real ;	
	p_cmpx = &sigCmpx[FFT_BLOCK_LENGTH-1] ; 
	for ( i = FFT_BLOCK_LENGTH; i > 0; i-- ) 
	{				
		(*p_cmpx).real = (*p_real--);
		(*p_cmpx--).imag = 0x0000;
	}
	FFTComplexIP (LOG2_BLOCK_LENGTH, &sigCmpx[0], (fractcomplex *) __builtin_psvoffset(&twiddleFactors[0]), (int) __builtin_psvpage(&twiddleFactors[0]));
	BitReverseComplex (LOG2_BLOCK_LENGTH, &sigCmpx[0]);
	SquareMagnitudeCplx(FFT_BLOCK_LENGTH, &sigCmpx[0], &sigCmpx[0].real);
    GetSpectra(); //get the spectra proportion
}
void GetSpectra()
{   
    int j=0;
    temp=0;
    *preal=&sigCmpx[0].real;
    for(j=0;j<8;j++)
   {
     SpecPower[j]=*preal; 
     *preal++;
     temp=*preal;
     SpecPower[j]+=temp<<16;
     *preal++;
   }
     for(j=1;j<8;j++)
   { 
       BuffHspec+=SpecPower[j];
       Spec[j]=SpecPower[j];
       Spec[j]/=SpecPower[0];
   }
       Spec[0]=BuffHspec;
       Spec[0]/=SpecPower[0]; 
}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -