|
- int main(void)
- {
- int i;
- delay_init(); //延时函数初始化
- uart_init(115200);
- LCD_Init();
- LCD_Clear(BLACK);
-
- TIM1_Int_Init(74,4); //192KHz采样频率
- ADC1_Configuration(); //ADC初始化
- DMA_Configuration(); //DMA初始化
- while(1)
- {
- for(i=0;i<NPT;i++)
- {
- lBufInArray[i]=ADC_Value[i]<<16;
- }
- cr4_fft_1024_stm32(lBufOutArray, lBufInArray, NPT);
- GetPowerMag();
- lcd_show_fft(lBufMagArray);
- }
- }
- u32 lBufInArray[NPT];
- u32 lBufOutArray[NPT];
- u32 lBufMagArray[NPT];
- float PI2=6.28318530717959;
- u32 Fs=192000;
- /******************************************************************
- 函数名称:InitBufInArray()
- 函数功能:模拟采样数据,采样数据中包含3种频率正弦波
- 参数说明:
- 备 注:在lBufInArray数组中,每个数据的高16位存储采样数据的实部,
- 低16位存储采样数据的虚部(总是为0)
- *******************************************************************/
- void InitBufInArray(void)
- {
- unsigned short i;
- float fx;
- for(i=0; i<NPT; i++)
- {
- fx = 1000 * sin(PI2 * i * 1000.0 / Fs) +
- 3000 * sin(PI2 * i * 3000.0 / Fs) +
- 4000 * sin(PI2 * i * 5000.0 / Fs);
- lBufInArray[i] = ((signed short)fx) << 16;
- }
- }
- /******************************************************************
- 函数名称:GetPowerMag()
- 函数功能:计算各次谐波幅值
- 参数说明:
- 备 注:先将lBufOutArray分解成实部(X)和虚部(Y),然后计算幅值(sqrt(X*X+Y*Y)
- *******************************************************************/
- void GetPowerMag(void)
- {
- signed short lX,lY;
- float X,Y,Mag;
- unsigned short i;
- for(i=0; i<NPT/2; i++)
- {
- lX = (lBufOutArray[i] << 16) >> 16;
- lY = (lBufOutArray[i] >> 16);
- X = NPT * ((float)lX) / 32768;
- Y = NPT * ((float)lY) / 32768;
- Mag = sqrt(X * X + Y * Y) / NPT;
- if(i == 0)
- lBufMagArray[i] = (unsigned long)(Mag * 32768);
- else
- lBufMagArray[i] = (unsigned long)(Mag * 65536);
- }
- }
复制代码
|
|