/* Includes ------------------------------------------------------------------*/
#include <math.h>
#include "stm32_dsp.h"
#include "stm32f10x_lib.h"
#include "table_fft.h"
#include "fftdemo.h"
//#include "bsp.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define PI2 6.28318530717959
#define NPT 64 /* NPT = No of FFT point*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
extern u16 TableFFT[];
long lBUFIN[NPT]; /* Complex input vector */
long lBUFOUT[NPT]; /* Complex output vector */
long lBUFMAG[NPT + NPT/2];/* Magnitude vector */
/* Private function prototypes -----------------------------------------------*/
/*******************************************************************************
* Function Name : MygSin
* Description : Produces a combination of two sinewaves as input signal
* Input : Freq1: frequency increment for 1st sweep
* Freq2: frequency increment for 2nd sweep
* Output : None
* Return : None
*******************************************************************************/
void MyDualSweep(u32 freqinc1,u32 freqinc2)
{
u32 freq;
for (freq=1000; freq <4000; freq+=freqinc1)
{
MygSin(NPT, 8000, freq, 0, 32767);
//GPIOC->BSRR = GPIO_Pin_7;
// Frequency resolution is fs/N
cr4_fft_64_stm32(lBUFOUT, lBUFIN, NPT);
//GPIOC->BRR = GPIO_Pin_7;
powerMag(NPT,"2SIDED");
//In_displayWaveform(DISPLAY_RIGHT);
//displayPowerMag(DISPLAY_RIGHT, 9);
//while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9) == 0x00);
}
for (freq=40; freq <4000; freq+=freqinc2)
{
MygSin(NPT, 8000, freq, 160, 32767/2);
// GPIOC->BSRR = GPIO_Pin_7;
//cr4_fft_64_stm32(lBUFOUT, lBUFIN, NPT);
// GPIOC->BRR = GPIO_Pin_7;
powerMag(NPT,"2SIDED");
while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9) == 0x00);
}
}
/*******************************************************************************
* Function Name : MygSin
* Description : Produces a combination of two sinewaves as input signal
* Input : nfill: length of the array holding input signal
* Fs: sampling frequency
* Freq1: frequency of the 1st sinewave
* Freq2: frequency of the 2nd sinewave
* Ampli: scaling factor
* Output : None
* Return : None
*******************************************************************************/
void MygSin(long nfill, long Fs, long Freq1, long Freq2, long Ampli)
{
u32 i;
float fFs, fFreq1, fFreq2, fAmpli;
float fZ,fY;
fFs = (float) Fs;
fFreq1 = (float) Freq1;
fFreq2 = (float) Freq2;
fAmpli = (float) Ampli;
for (i=0; i < nfill; i++)
{
fY = sin(PI2 * i * (fFreq1/fFs)) + sin(PI2 * i * (fFreq2/fFs));
fZ = fAmpli * fY;
//printf("%f ",fY);
lBUFIN[i]= ((short)fZ) << 16 ; /* sine_cosine (cos=0x0) */
}
}
/*******************************************************************************
* Function Name : onesided
* Description : Removes the aliased part of the spectrum (not tested)
* Input : nfill: length of the array holding power mag
* Output : None
* Return : None
*******************************************************************************/
void onesided(long nfill)
{
u32 i;
lBUFMAG[0] = lBUFMAG[0];
lBUFMAG[nfill/2] = lBUFMAG[nfill/2];
for (i=1; i < nfill/2; i++)
{
lBUFMAG[i] = lBUFMAG[i] + lBUFMAG[nfill-i];
lBUFMAG[nfill-i] = 0x0;
}
}
/*******************************************************************************
* Function Name : powerMag
* Description : Compute power magnitude of the FFT transform
* Input : nfill: length of the array holding power mag
* : strPara: if set to "1SIDED", removes aliases part of spectrum (not tested)
* Output : None
* Return : None
*******************************************************************************/
void powerMag(long nfill, char* strPara)
{
s32 lX,lY;
u32 i;
for (i=0; i < nfill; i++)
{
lX= (lBUFOUT[i]<<16)>>16; /* sine_cosine --> cos */
lY= (lBUFOUT[i] >> 16); /* sine_cosine --> sin */
{
float X= 64*((float)lX)/32768;
float Y = 64*((float)lY)/32768;
float Mag = sqrt(X*X+ Y*Y)/nfill;
lBUFMAG[i] = (u32)(Mag*65536);
}
}
//if (strPara == "1SIDED")
onesided(nfill);
}
float* fft64test(long* IN, u16 l)
{
for(u16 i=0;i<NPT;i++)
lBUFIN[i]=IN[i];
cr4_fft_64_stm32(lBUFOUT, lBUFIN, NPT);
powerMag(NPT,"1SIDED");
float I[NPT/2];
for(u8 temp=0;temp<NPT/2;temp++)
I[temp]=(lBUFMAG[temp]*0.01684-0.01684);//*(1-0.015);//校正值
return(I);
}
/*******************************************************************************
* Function Name : Delay
* Description : Inserts a delay time.
* Input : nCount: specifies the delay time length (time base 10 ms).
* Output : None
* Return : None
*******************************************************************************/
//void Delay(u32 nCount)
//{
//
// /* Enable the SysTick Counter */
// SysTick_CounterCmd(SysTick_Counter_Enable);
//
// while (nCount--)
// {
// while (SysTick_GetFlagStatus(SysTick_FLAG_COUNT) == RESET);
// }
//
// /* Disable the SysTick Counter */
// SysTick_CounterCmd(SysTick_Counter_Disable);
//
// /* Clear the SysTick Counter */
// SysTick_CounterCmd(SysTick_Counter_Clear);
//}
//
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
//
DSPLib.rar_DSPLIB_fft库 高效率
版权申诉
5星 · 超过95%的资源 104 浏览量
2022-09-22
22:33:46
上传
评论
收藏 60KB RAR 举报
Kinonoyomeo
- 粉丝: 74
- 资源: 1万+