/**
******************************************************************************
* @file FFT_Demo/src/main.c
* @author MCD Application Team
* @version V2.0.0
* @date 04/27/2009
* @brief Main program body
******************************************************************************
* @copy
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2009 STMicroelectronics</center></h2>
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include <math.h>
#include "stm3210b_lcd.h"
#include "stm32_dsp.h"
#include "table_fft.h"
/** @addtogroup FFT_Demo
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define PI2 6.28318530717959
#define NPT 64 /* NPT = No of FFT point*/
#define DISPLAY_RIGHT 310 /* 224 for centered, 319 for right-aligned */
#define DISPLAY_LEFT 150 /* 224 for centered, 319 for right-aligned */
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
extern uint16_t TableFFT[];
extern volatile uint32_t TimingDelay ;
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 freqinc1,uint32_t freqinc2);
void MygSin(long nfill, long Fs, long Freq1, long Freq2, long Ampli);
void powerMag(long nfill, char* strPara);
void In_displayWaveform(uint32_t DisplayPos);
void Out_displayWaveform(uint32_t DisplayPos);
void displayPowerMag(uint32_t DisplayPos, uint32_t scale);
void DisplayTitle(void);
void DSPDemoInit(void);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval : None
*/
int main(void)
{
DSPDemoInit();
DisplayTitle();
while (1)
{
MyDualSweep(30,30);
}
}
/**
* @brief Produces a combination of two sinewaves as input signal
* @param eq1: frequency increment for 1st sweep
* Freq2: frequency increment for 2nd sweep
* @retval : None
*/
void MyDualSweep(uint32_t freqinc1,uint32_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);
}
}
/**
* @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
* @retval : None
*/
void MygSin(long nfill, long Fs, long Freq1, long Freq2, long Ampli)
{
uint32_t 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;
lBUFIN[i]= ((short)fZ) << 16 ; /* sine_cosine (cos=0x0) */
}
}
/**
* @brief Removes the aliased part of the spectrum (not tested)
* @param ill: length of the array holding power mag
* @retval : None
*/
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 lX,lY;
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 Displays the input array before filtering
* @param splayPos indicates the beginning Y address on LCD
* @retval : None
*/
void In_displayWaveform(uint32_t DisplayPos)
{
uint8_t aScale;
uint16_t cln;
for (cln=0; cln < 64; cln++) /* original upper limit was 60 */
{
/* Clear previous line */
LCD_SetTextColor(White);
LCD_DrawLine(48,DisplayPos-(2*cln),72,Vertical);
/* and go back to normal display mode */
LCD_SetTextColor(Black);
aScale = lBUFIN[cln]>>(10 + 16); /* SINE IS LEFT ALIGNED */
if (aScale > 127) /* Negative values */
{
aScale = (0xFF-aScale) + 1; /* Calc absolute value */
LCD_DrawLine(84-aScale,DisplayPos-(2*cln),aScale,Vertical);
}
else /* Display positive values */
{
LCD_DrawLine(84,DisplayPos-(2*cln),aScale,Vertical);
}
}/* for */
}
/**
* @brief Displays the output array after filtering
* @param splayPos indicates the beginning Y address on LCD
* @retval : None
*/
void Out_displayWaveform(uint32_t DisplayPos)
{
uint8_t aScale;
uint16_t cln;
for (cln=0; cln < 64; cln++) /* original upper limit was 60 */
{
aScale = lBUFOUT[cln]>>(10 + 16); /* SINE IS LEFT ALIGNED */
if (aScale > 127) /* Negative values */
{
aScale = (0xFF-aScale) + 1; /* Calc absolute value */
LCD_DrawLine(156-aScale,DisplayPos-(2*cln),aScale,Vertical);
}
else /* Display positive values */
{
LCD_DrawLine(156,DisplayPos-(2*cln),aScale,Vertical);
}
}/* for */
}
/**
* @brief Displays the power magnitude array following a FFT
* @param splayPos indicates the beginning Y address on LCD
* : scale allows to normalize the result for optimal display
* @retval : None
*/
void displayPowerMag(uint32_t DisplayPos, uint32_t scale)
{
uint16_t aScale;
uint16_t cln;
for (cln=0; cln < 64; cln++)
{
/* Clear previous line */
LCD_SetTextColor(White);
LCD_DrawLine(120,DisplayPos-(2*cln),72,Vertical);
/* and go back to normal display mode */
LCD_SetTextColor(Red);
aScale =lBUFMAG[cln]>>scale ; /* spectrum is always divided by two */
/* Power Mag contains only positive values */
LCD_DrawLine(192-aScale,DisplayPos-(2*cln),aScale,Vertical);
}/* for */
}
/**
* @brief Dis

小波思基
- 粉丝: 104
最新资源
- cognitoidentityprovider-jvm-1.5.32-sources.jar
- cybrid-api-bank-kotlin-0.123.66.jar
- cloudtraildata-jvm-0.31.0-beta-javadoc.jar
- chimesdkmeetings-jvm-0.29.0-beta.jar
- redwood-layout-modifiers-iosarm64-0.13.0-javadoc.jar
- pact-jvm-provider-junit_2.12-3.5.16.jar
- singlestep-kdf-0.1.0-javadoc.jar
- dlm-1.4.27-javadoc.jar
- cybrid-api-organization-java-v0.123.564-sources.jar
- devicefarm-jvm-1.0.12.jar
- wisp-lease-testing-2025.07.30.145520-ed3cdfa-javadoc.jar
- sparkling-water-doc_2.11-3.32.0.5-1-2.1-javadoc.jar
- codeconnections-jvm-1.2.47-sources.jar
- kotlinx-serialization-flf-macosx64-0.0.21-metadata.jar
- codeconnections-jvm-1.3.3.jar
- h2o-ext-authsupport-3.16.0.12.jar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



评论0