avatar

松果工作室

欢迎光临

  • 首页
  • ESP
  • LVGL
  • freeRTOS
  • 快速笔记
  • 考察日志
  • 个人收藏
  • 我的服务
Home (LIB)使用 FFT
文章

(LIB)使用 FFT

Posted 2024-02-29 Updated 2024-02- 29
By YCP
7~10 min read

参考https://blog.csdn.net/m0_51220742/article/details/124869371

#include "fft_test.h"

#include "arm_math.h"
#include "arm_const_structs.h"
#include "stdio.h"


#define Fs 100000
#define FFT_LENGTH 1024

float32_t lBufInArray[FFT_LENGTH*2] = {0};
float32_t lBufOutArray[FFT_LENGTH / 2] = {0};
uint16_t ADC_Value[FFT_LENGTH] = {0};

void InitBufInArray(void)
{
  unsigned short i;
  float fx;
  for(i = 0; i < FFT_LENGTH; i++)
  {
    fx = 1024 * sin(2 * PI * i * 13500.0 / Fs)
         + 512 * sin(2 * PI * i * 8500.0 / Fs)
         + 512 * sin(2 * PI * i * 3500.0 / Fs);

    ADC_Value[i] = fx + 2048;
  }
}

void FFT(void)
{
  InitBufInArray();
  for (int i = 0; i < FFT_LENGTH; i++)
  {
    lBufInArray[i * 2] = ADC_Value[i]; //实部赋值
    lBufInArray[i * 2 + 1] = 0; //虚部赋值
  }
  arm_cfft_f32(&arm_cfft_sR_f32_len1024, lBufInArray, 0, 1);
  arm_cmplx_mag_f32(lBufInArray, lBufOutArray, FFT_LENGTH);

  for (int i = 1; i < FFT_LENGTH/2; i++)
  {
    lBufOutArray[i] /= 512;
  }

  for(int16_t i = 1; i < FFT_LENGTH/2; i++)
  {
    printf("%f\n", lBufOutArray[i]);
  }
}

坑和笔记
Others
License:  CC BY 4.0
Share

Further Reading

Sep 27, 2025

(LIB)一个好用的Modbus解析函数

一个好用的Modbus解析函数 包含03/10/04/06 #include <stdio.h> #include <stdint.h> #include <string.h> #

Jun 21, 2024

(LIB)环形滤波算法

#include <stdio.h> #include <stdlib.h> #define BUFFER_SIZE 10 // 缓冲区大小 #define THRESHOLD 180

Jun 17, 2024

(STM32)STM32 ADC采集的三种方式

采样周期 单个采集模式 ADC_Settings: 程序使用 uint16_t ADC_Read(

OLDER

(Linux)Docker 中开启 SSH

NEWER

(Linux)MJPG_Streamer 网络监控

Recently Updated

  • (ESP-IDF)LVGL 模拟器
  • (ESP-IDF)LVGL 自定义对象加入编码器组
  • (ESP-IDF)vscode配置文件
  • (Elec)来复再生式晶体管单管收音机
  • (ESP-IDF)ESPNOW

Trending Tags

LVGL WCH Linux Elec ThatProject freeRTOS STM ESP Flutter Others

Contents

©2026 松果工作室. Some rights reserved.

Using the Halo theme Chirpy