当前位置:网站首页>【嵌入式】Cortex M4F DSP库
【嵌入式】Cortex M4F DSP库
2022-07-06 08:40:00 【好奇宝宝·权】
使用CM4内核自带的FPU需要在编译的时候添加编译选项:--cpu Cortex-M4.fp,以使能FPU指令集,否则使用的是普通Thumb2指令实现的DSP函数。同时还需添加宏定义:ARM_MATH_CM4,这在CMSIS DSP Library的arm_math.h里面用到。CMSIS DSP Library可以在ARM的官网找到:https://developer.arm.com/tools-and-software/embedded/cmsis
https://developer.arm.com/tools-and-software/embedded/cmsis
如果使用MDK的话,直接在Runtime Environment管理器里面添加DSP库,Floating Point Hardware选择Single Precision,预定义宏加上ARM_MATH_CM4,这样工程自动添加了DSP库:
上面那个库是使用FPU指令集生成的DSP库,下面的是没有使用FPU指令集......
DSP库测试:
static float sin_out[256];
static float fft_mag[256];
static float fft_out[256];
static void DSP_Test()
{
#define FFT_LENGTH 256
arm_rfft_fast_instance_f32 S;
// 创建一个t=2S钟之内的采样数据,采样点数FFT_LENGTH,采样周期T=t/FFT_LENGTH,采样频率F=1/T
for(uint16_t i = 0; i < FFT_LENGTH; i++)
{
sin_out[i] = arm_sin_f32(i*2*3.1416f/128) + 0.3f*arm_sin_f32(i*2*3.1416f/16); //
}
for(uint16_t i = 0; i < FFT_LENGTH; i++)
{
LOGI("%.4f\r\n",sin_out[i]);
DDL_DelayUS(1000);
}
arm_rfft_fast_init_f32(&S, FFT_LENGTH); //初始化1024点FFT参数
arm_rfft_fast_f32(&S,sin_out,fft_out,0); //计算FFT
arm_cmplx_mag_f32(fft_out,fft_mag, FFT_LENGTH); //计算模值
for(uint16_t i = 0; i < FFT_LENGTH / 2; i++)
{
LOGI("%4d %4.4f %4.4f\r\n", i, (float)i * 128 / FFT_LENGTH, fft_mag[i]);//frequency = N * sample frequency / FFT length
DDL_DelayUS(1000);
}
}
结果在Excel上画图,采样点图像(1Hz正弦波和8Hz正弦波叠加):

FFT计算结果:
两个波峰分别对应1Hz和8Hz,和采样点的频率一致。
边栏推荐
猜你喜欢

Detailed explanation of heap sorting

Cisp-pte practice explanation

企微服务商平台收费接口对接教程

Marathon envs project environment configuration (strengthen learning and imitate reference actions)

ROS编译 调用第三方动态库(xxx.so)

Pointer advanced --- pointer array, array pointer

Fibonacci sequence

Tcp/ip protocol

Bottom up - physical layer

堆排序详解
随机推荐
Fibonacci sequence
Image,cv2读取图片的numpy数组的转换和尺寸resize变化
Computer cleaning, deleted system files
Unified ordering background interface product description Chinese garbled
Target detection - pytorch uses mobilenet series (V1, V2, V3) to build yolov4 target detection platform
如何进行接口测试测?有哪些注意事项?保姆级解读
How to conduct interface test? What are the precautions? Nanny level interpretation
2022 Inner Mongolia latest construction tower crane (construction special operation) simulation examination question bank and answers
704 binary search
【ROS】usb_cam相机标定
What is CSRF (Cross Site Request Forgery)?
Roguelike game into crack the hardest hit areas, how to break the bureau?
Double pointeur en langage C - - modèle classique
深度剖析C语言指针
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
Light of domestic games destroyed by cracking
C语言深度解剖——C语言关键字
The mysqlbinlog command uses
poi追加写EXCEL文件
Bitwise logical operator