资源简介
对STM32的FIR设计,有详细的讲解。
代码片段和文件信息
#include “stm32f10x.h“
#include
#include “stm32_dsp.h“
#include “table_fft.h“
#define PI2 6.28318530717959
#define NPT 64 /* NPT = No of FFT point*/
extern uint16_t TableFFT[];
long lBUFIN[NPT]; /* Complex input vector */
long lBUFOUT[NPT]; /* Complex output vector */
long lBUFMAG[NPT + NPT/2];/* Magnitude vector */
/* Private function prototypes -----------------------------------------------*/
void MyDualSweep(uint32_t freqinc1uint32_t freqinc2);
void MygSin(long nfill long Fs long Freq1 long Freq2 long Ampli);
void powerMag(long nfill char* strPara);
void onesided(long nfill);
int main(void)
{
//DSPDemoInit();
// Displaytitle();
while (1)
{
MygSin(NPT 64*8 8 0 32767);
cr4_fft_64_stm32(lBUFOUT lBUFIN NPT);
powerMag(NPT“2SIDED“);
powerMag(NPT“1SIDED“);
MyDualSweep(3030);
}
}
void MyDualSweep(uint32_t freqinc1uint32_t freqinc2)
{
uint32_t freq;
for (freq=40; freq <4000; freq+=freqinc1)
{
MygSin(NPT 8000 freq 0 32767);
//GPIOC->BSRR = GPIO_Pin_7;
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“);
//In_displayWaveform(DISPLAY_LEFT);
//displayPowerMag(DISPLAY_LEFT 8);
//while (GPIO_ReadInputDataBit(GPIOB GPIO_Pin_9) == 0x00);
}
}
void onesided(long nfill)
{
uint32_t 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;
}
}
/**
* @brief Compute power magnitude of the FFT transform
* @param ill: length of the array holding power mag
* : strPara: if set to “1SIDED“ removes aliases part of spectrum (not tested)
* @retval : None
*/
void powerMag(long nfill char* strPara)
{
int32_t lXlY;
uint32_t 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] = (uint32_t)(Mag*65536);
}
}
if (strPara == “1SIDED“) onesided(nfill);
}
/**
* @brief Produces a combination of two sinewaves as input signal
* @param ill: 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
* @retva
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 140313 2013-07-12 09:38 firtest.uvgui_dell.bak
....... 18229 2013-07-12 17:04 firtest.uvopt
文件 19109 2013-07-10 17:27 firtest.uvproj
文件 15984 2013-07-12 16:06 firtest_Target 1.dep
文件 3153 2013-07-10 15:08 my_fir_filter.s
文件 181 2013-06-14 10:27 saw.ini
文件 126004 2013-07-10 10:31 sine_data.h
文件 3236 2011-06-27 14:20 stm32f10x_conf.h
文件 4481 2011-07-15 16:50 stm32f10x_it.c
文件 3531 2013-07-12 09:40 2sine.h
文件 536 2013-07-11 17:20 analog0.ini
文件 49438 2013-07-12 17:04 Book1.xlsx
文件 1535 2011-07-21 10:34 debugfunc.ini
文件 3469 2011-07-24 10:56 dsptest.c
文件 10967 2013-07-12 09:39 FIR_Filter.c
....... 142786 2013-07-12 17:04 firtest.uvgui.dell
----------- --------- ---------- ----- ----
542952 16
评论
共有 条评论