当前位置:网站首页>【嵌入式】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/cmsishttps://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,和采样点的频率一致。
边栏推荐
- poi追加写EXCEL文件
- Pointer advanced --- pointer array, array pointer
- 深度剖析C语言数据在内存中的存储
- ROS编译 调用第三方动态库(xxx.so)
- Is it safe to open an account in Zheshang futures?
- Indentation of tabs and spaces when writing programs for sublime text
- [brush questions] top101 must be brushed in the interview of niuke.com
- Light of domestic games destroyed by cracking
- egg. JS project deployment online server
- Roguelike游戏成破解重灾区,如何破局?
猜你喜欢
Roguelike游戏成破解重灾区,如何破局?
【MySQL】日志
Trying to use is on a network resource that is unavailable
Light of domestic games destroyed by cracking
个人电脑好用必备软件(使用过)
Sublime text using ctrl+b to run another program without closing other runs
Tcp/ip protocol
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
【ROS】usb_cam相机标定
sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
随机推荐
CISP-PTE实操练习讲解
Image, CV2 read the conversion and size resize change of numpy array of pictures
[MySQL] lock
poi追加写EXCEL文件
Roguelike游戏成破解重灾区,如何破局?
Double pointeur en langage C - - modèle classique
gcc动态库fPIC和fpic编译选项差异介绍
Research Report on supply and demand and development prospects of China's high purity aluminum market (2022 Edition)
Restful API design specification
软件卸载时遇到trying to use is on a network resource that is unavailable
JS pure function
Modify the video name from the name mapping relationship in the table
704 二分查找
Trying to use is on a network resource that is unavailable
Let the bullets fly for a while
PC easy to use essential software (used)
TCP/IP协议
深度剖析C语言指针
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
Introduction to the differences between compiler options of GCC dynamic library FPIC and FPIC