第12章ARM官方DSP库的StatisticsMathFunctions的使用教程(二)

合集下载

第11章ARM官方DSP库的StatisticsMathFunctions的使用(一)

第11章ARM官方DSP库的StatisticsMathFunctions的使用(一)

[in] blockSize length of the input vector
[out] *pResult maximum value returned here
[out] *pIndex index of maximum value returned here
11.1.3 arm_max_q15
{
pSrc2[pIndex] = rand()%32768;
(3)
2015年01月15日
版本:1.0
第 3 页 共 13 页
安富莱
UM403
DSP 教程
STM32-V5 开发板系统篇手册
} arm_max_q15(pSrc2, 10, &pResult2, &pIndex); printf("arm_max_q15 : pResult = %d pIndex = %d\r\n", pResult2, pIndex);
q15_t pSrc2[10]; q15_t pResult2;
q7_t pSrc3[10]; q7_t pResult3;
arm_max_f32(pSrc, 10, &pResult, &pIndex); printf("arm_max_f32 : pResult = %f pIndex = %d\r\n", pResult, pIndex);
参数定义:
[in] *pSrc
points to the input vector
[in] blockSize length of the input vector
[out] *pResult maximum value returned here

第16章ARM官方DSP库的ControllerFunctions的使用教程(二)

第16章ARM官方DSP库的ControllerFunctions的使用教程(二)

第16章C o n t r o l l e r F u n c t i o n s的使用(二)本期教程主要讲解控制函数中的cos和sin函数数值的获取,这里使用的函数比起第10章中使用的sin和cos函数数值的获取要方便很多。

16.1 浮点数SIN和COS16.2 定点数SIN和COS16.3 Clark正变换和逆变换16.4 Park正变换和逆变换16.5总结16.1浮点数S I N和C O S16.1.1a r m_s i n_c o s_f32函数定义如下:void arm_sin_cos_f32(float32_t theta, float32_t * pSinVal, float32_t * pCosVal)参数定义:[in] theta input value in degrees[out] *pSinVal points to the processed sine output.[out] *pCosVal points to the processed cos output.注意事项:1.参数theta的单位是角度。

这里输入角度-180到179就能得到一个周期的正弦或者余弦数值。

16.1.2实例讲解实验目的:1. 学习ControllerFunctions中SIN和COS的求解实验内容:1. 按下按键K1, 串口打印函数DSP_SIN_COS的输出结果实验现象:通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:程序设计:/********************************************************************************************************** * 函 数 名: DSP_SIN_COS* 功能说明: 浮点数cos和sin计算* 形 参:无* 返 回 值: 无********************************************************************************************************* */static void DSP_SIN_COS(void){int16_t i;float32_t pSinVal;float32_t pCosVal;for(i = -180; i < 180; i++){arm_sin_cos_f32(i, &pSinVal, &pCosVal); (1) printf("i = %d pSinVal = %f pCosVal = %f\r\n", i, pSinVal, pCosVal);// printf("%f\r\n", pSinVal); (2) // printf("%f\r\n", pCosVal); (3) }}1.sin和cos数据的求解。

第21章ARM官方DSP库的InterpolationFunctions的使用

第21章ARM官方DSP库的InterpolationFunctions的使用
-0.604960695383043530, -0.597090287967934840, 0.187140422442966500, 0.418772124875992690,
-0.988588831792106880, 0.976338412038794010, 0.976903856413481100, -0.056495446835214236, 0.472033731854734240, 0.259311907228582830
uint32_t nValues)
参数定义:
[in] *pYData pointer to Q31 Linear Interpolation table
[in] x
input sample to process
[in] nValues number of table values
return y
processed output sample.
} arm_bilinear_interp_instance_q15;
2. 如果输入参数 x 在输入范围之下返回第一个样本值,如果相爱输入范围之上,式是 12.20。这样 32 位数据的 12 位整数部分用于样本数据的检测,所以最
大值就是 2 的 12 次方。后 20 位用于小数部分。
[in] x
input sample to process
[in] nValues number of table values
return y
processed output sample.
注意事项:
1. 结构 arm_linear_interp_instance_q15 的定义如下(在文件 arm_math.h 文件):
fxfyffxf1yffxfyf1fxf1yf1xxfyyfxy数据是由整数和小数两部分组成整数部分用来获取所在的插补样值的位置小数部分用于实际数据的处理

SES如何使用数学库arm_math让程序起飞?

SES如何使用数学库arm_math让程序起飞?

SES如何使用数学库arm_math让程序起飞?来源:技术让梦想更伟大作者:李肖遥最近在使用Nordic的52832开发,这也属于ARM Cortex M4架构,芯片具体不介绍了,主要是M4与M0、M3的最大不同就是具有FPU(浮点运算单元),这也正是我所需要的。

因为项目中有相关算法,涉及到卡尔曼滤波等等,需要支持浮点指令集,因此速度很重要。

使用了CMSIS DSP软件库的数学库arm_math后,在处理数学运算时能比M0/M3高出数十倍甚至上百倍的性能。

CMSIS DSP软件库是什么CMSIS DSP软件库是一套用于基于Cortex-M和Cortex-A处理器的设备的常用信号处理功能。

该库涵盖以下类别的功能:•基本的数学功能•快速的数学功能•复杂的数学函数•过滤功能•矩阵函数•转换功能•电机控制功能•统计功能•支持功能•插值功能•支持向量机功能(SVM)•贝叶斯分类器功能•距离功能该库通常具有单独的函数,用于对8位整数、16位整数、32位整数和32位浮点值进行运算。

库的使用介绍库安装程序在Lib文件夹中包含库的预构建版本,以下是预构建库的列表:•arm_cortexM7lfdp_math.lib(Cortex-M7,小端,双精度浮点单元)•arm_cortexM7bfdp_math.lib(Cortex-M7,大字节序,双精度浮点单元)•arm_cortexM7lfsp_math.lib(Cortex-M7,小端,单精度浮点单元)•arm_cortexM7bfsp_math.lib(Cortex-M7,大字节序和单精度浮点单元打开)•arm_cortexM7l_math.lib(Cortex-M7,小端)•arm_cortexM7b_math.lib(Cortex-M7,大端)•arm_cortexM4lf_math.lib(Cortex-M4,小端,浮点单元)•arm_cortexM4bf_math.lib(Cortex-M4,大端,浮点单元)•arm_cortexM4l_math.lib(Cortex-M4,小端)•arm_cortexM4b_math.lib(Cortex-M4,大端)•arm_cortexM3l_math.lib(Cortex-M3,小端)•arm_cortexM3b_math.lib(Cortex-M3,大端)•arm_cortexM0l_math.lib(Cortex-M0 / Cortex-M0 ,小端)•arm_cortexM0b_math.lib(Cortex-M0 / Cortex-M0 ,大端)•arm_ARMv8MBLl_math.lib(Armv8-M基线,小端)•arm_ARMv8MMLl_math.lib(Armv8-M主线,小端)•arm_ARMv8MMLlfsp_math.lib(Armv8-M主线,小字节序,单精度浮点单元)•arm_ARMv8MMLld_math.lib(Armv8-M主线,小端,DSP 指令)•arm_ARMv8MMLldfsp_math.lib(Armv8-M主线,小字节序,DSP指令,单精度浮点单元)库函数在位于Include文件夹中的公共文件arm_math.h中声明,只需包括此文件并在应用程序中链接适当的库,然后开始调用库函数就可以使用了。

第32章ARM官方DSP库实数FFT的实现

第32章ARM官方DSP库实数FFT的实现

第32章ARM官方DSP库实数FFT的实现ARM官方DSP库中提供了实数FFT(Fast Fourier Transform)的实现,用于在ARM处理器上进行实数信号的频域分析和相应的算法计算。

以下将介绍实数FFT的基本原理以及ARM官方DSP库中的实现。

实数FFT是一种特殊形式的快速傅里叶变换(FFT),它利用了实数序列的对称性和共轭对称性,减少了计算复杂度。

在实际应用中,很多信号都是实数形式的,如音频信号、生物信号等。

实数FFT可以将实数信号变换到频域进行频谱分析和滤波等处理。

实数FFT算法的基本思想是将实数序列拆分成两个复数序列,分别表示实数序列的偶数项和奇数项,然后对这两个复数序列进行FFT计算。

在ARM官方DSP库中,实数FFT算法采用了基于混合(Mixed-radix)的方法,结合了常规傅里叶变换算法和快速傅里叶变换算法的优点,以提高计算效率。

ARM官方DSP库中实数FFT的实现主要涉及以下几个函数:1. arm_rfft_fast_init_f32:该函数用于初始化实数FFT计算所需的配置结构体,包括输入序列的长度、窗函数和变换类型等。

2. arm_rfft_fast_f32:该函数用于执行实数FFT计算。

它将输入的实数序列拆分为两个复数序列,并对其进行FFT计算得到频域结果。

输出结果为幅度谱,包括正频率和负频率部分。

3. arm_rfft_fast_init_q31、arm_rfft_fast_q31:类似于上述函数,用于32位定点数的实数FFT计算。

4. arm_rfft_fast_init_q15、arm_rfft_fast_q15:类似于上述函数,用于16位定点数的实数FFT计算。

实数FFT的计算结果可以用于频谱分析、信号滤波、相关性计算等。

在ARM官方DSP库中,还提供了其他相关函数,如频谱幅度归一化、频谱偏移等,以方便进一步的信号处理。

总之,ARM官方DSP库中的实数FFT实现了高效的实数信号频域分析算法,为ARM处理器上的实时信号处理提供了强大的工具。

第18章ARM官方DSP库的ComplexMathFunctions的使用教程(二)

第18章ARM官方DSP库的ComplexMathFunctions的使用教程(二)

18.2.4 arm_cmplx_mult_cmplx_q15
公式描述: for(n=0; n<numSamples; n++) {
pDst[(2*n)+0] = pSrcA[(2*n)+0] * pSrcB[(2*n)+0] - pSrcA[(2*n)+1] * pSrcB[(2*n)+1]; pDst[(2*n)+1] = pSrcA[(2*n)+0] * pSrcB[(2*n)+1] + pSrcA[(2*n)+1] * pSrcB[(2*n)+0]; } 函数定义如下: void arm_cmplx_mult_cmplx_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t numSamples) 参数定义: [in] *pSrc points to the complex input vector [out] *pDst points to the real output vector [in] numSamples number of complex samples in the input vector 注意事项: 1. 数组pSrcA, pSrcB和pDst中存储的数据格式是(实部,虚部,实部,虚部……………)
18.1 复数模平方 ComplexMagSquared
18.1.1 arm_cmplx_mag_squared_f32
公式描述: for(n=0; n<numSamples; n++) {
pDst[n] = pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2; } 函数定义如下: void arm_cmplx_mag_squared_f32(float32_t * pSrc, float32_t * pDst, uint32_t numSamples) 参数定义: [in] *pSrc points to the complex input vector [out] *pDst points to the real output vector [in] numSamples number of complex samples in the input vector 注意事项: 1. 数组pSrc和pDst中存储的数据格式是(实部,虚部,实部,虚部……………)

第22章ARM官方DSP库的math_help中函数的使用

第22章ARM官方DSP库的math_help中函数的使用

安富莱 DSP 教程UM403 STM32-V5 开发板系统篇手册第22章 math_help 中函数的使用本期教程主要讲解 math_help 文件中函数的使用, 这个文件也是 ARM 官方提供的, 这些函数相对都 比较容易,同时使用频率也很高。

希望初学的同学学习并掌握。

21.1 函数讲解 21.3 总结22.1 函数讲解 22.1.1 函数目录在文件 math_help 文件中主要有以下函数:float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize); void arm_float_to_q12_20(float *pIn, q31_t * pOut, uint32_t numSamples); void arm_provide_guard_bits_q15(q15_t *input_buf, uint32_t blockSize, uint32_t guard_bits); void arm_provide_guard_bits_q31(q31_t *input_buf, uint32_t blockSize, uint32_t guard_bits); void arm_float_to_q14(float *pIn, q15_t *pOut, uint32_t numSamples); void arm_float_to_q30(float *pIn, q31_t *pOut, uint32_t numSamples); void arm_clip_f32(float *pIn, uint32_t numSamples); uint32_t arm_calc_guard_bits(uint32_t num_adds); void arm_apply_guard_bits (float32_t * pIn, uint32_t numSamples, uint32_t guard_bits); uint32_t arm_compare_fixed_q15(q15_t *pIn, q15_t * pOut, uint32_t numSamples); uint32_t arm_compare_fixed_q31(q31_t *pIn, q31_t *pOut, uint32_t numSamples); uint32_t arm_calc_2pow(uint32_t guard_bits);22.1.2 arm_snr_f32这个函数用于求信噪比:/** * @brief Caluclation of SNR * @param float* Pointer to the reference buffer * @param float* Pointer to the test buffer * @param uint32_t total number of samples * @return float SNR * The function Caluclates signal to noise ratio for the reference output * and test output */ float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize) { float EnergySignal = 0.0, EnergyError = 0.0; uint32_t i; float SNR; int temp; int *test; for (i = 0; i < buffSize; i++) { /* Checking for a NAN value in pRef array */ test = (int *)(&pRef[i]); temp = *test; (1)2015年01月15日版本:1.0第 1 页 共 7 页安富莱 DSP 教程if(temp == 0x7FC00000) { return(0); } /* Checking for a NAN value in pTest array */ test = (int *)(&pTest[i]); temp = *test; if(temp == 0x7FC00000) { return(0); } EnergySignal += pRef[i] * pRef[i]; EnergyError += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]); } /* Checking for a NAN value in EnergyError */ test = (int *)(&EnergyError); temp = *test; if(temp == 0x7FC00000) { return(0); } SNR = 10 * log10 (EnergySignal / EnergyError); return (SNR); }UM403 STM32-V5 开发板系统篇手册(2)1. 这里先补充一些信噪比方面的基础知识: 信噪比,即 SNR(Signal to Noise Ratio) ,又称为讯噪比。

第10章ARM官方DSP库的FastMathFunctions的使用

第10章ARM官方DSP库的FastMathFunctions的使用

printf("%f\r\n", arm_sin_f32(i * PI / 128));
}
printf("***************************************************************\r\n");
for(i = 0; i < 256; i++) {
/* 这里是0 - 32767 对于[0 2*pi) */ printf("%d\r\n", arm_sin_q15(i*128)); } printf("***************************************************************\r\n");
注意输入参数 x 是弧度制即可,也就是说 sine 函数的一个周期对应于弧度[ 0 2*PI)。下面我们先通过 Matlab 绘制一个周期的 sine 曲线。新建一个.m 格式的脚本文件,并写入如下函数: x = 0:0.01:2*pi; plot(x, sine(x)) 运行后显示效果如下:
点击上面截图中的Tools->Data statistics,获取数据的分析结果,我们主要看Y轴。
10.2.3 arm_sin_q15
函数定义如下: q31_t arm_sin_q15(q15_t x) 使用中只需注意参数x的数值范围[0 2^15)相当于弧度[0 2*PI)即可。
10.3 平方根 sqrt
浮点数的平方根计算只需调用一条浮点指令即可,而定点数的计算要稍显麻烦。
10.3.1 arm_sqrt_f32
for(i = 0; i < 256; i++) {
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

版本:1.0
第 5 页 共 10 页
安富莱 DSP 教程
UM403 STM32-V5 开发板系统篇手册
程序设计:
/* ********************************************************************************************************* * 函 数 名: DSP_RMS * 功能说明: 求均方值 * 形 参:无 * 返 回 值: 无 ********************************************************************************************************* */ static void DSP_RMS(void) {
2015年01月15日
版本:1.0
第 4 页 共 10 页
安富莱 DSP 教程
[out] *pResult rms value returned here
UM403 STM32-V5 开发板系统篇手册
12.2.2 arm_rms_q31
函数定义如下:
void arm_rms_q31(q31_t * pSrc, uint32_t blockSize, q31_t * pResult)
q15_t pSrc2[10]; q15_t pResult2;
arm_rms_f32(pSrc, 10, &pResult); printf("arm_rms_f32 : pResult = %f\r\n", pResult);
/*****************************************************************/ for(pIndex = 0; pIndex < 10; pIndex++) {
[in] blockSize length of the input vector
[out] *pResult rms value returned here
注意事项:
输入参数是1.15格式,相乘后的的结果就是1.15*1.15 = 2.30格式,这种情况下,内部64位累加器的
的格式就是34.30。最终的输出结果要截取到低15位数据,然后通过饱和运算最终输出数据格式1.15。
函数定义如下:
void arm_rms_f32(float32_t * pSrc, uint32_t blockSize, float32_t * pResult)
参数定义:
[in] *pSrc
points to the input vector
[in] blockSize length of the input vector
12.1.2 arm_std_q31
此函数的使用比较简单,函数定义如下: void arm_std_q31(q31_t * pSrc, uint32_t blockSize, q31_t * pResult) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult standard deviation value returned here
差,然后再用此函数获取标准偏差作为对比。
在 matlab 的命令窗口输入如下命令:
rand(1,10) %1 行 10 列
然后再通过命令 std 获得标准偏差:
std(ans)
matlab 求得标准偏差数值是 0.2935,而 DSP 函数求得结果是 0.293485,基本是一致的。 2. 这个函数的使用还没有搞懂,有待后面解决。 3. 这个函数的使用还没有搞懂,有待后面解决。
累加器很容易溢出,并且这个函数不支持饱和运算。
12.2.3 arm_rms_q15
函数定义如下:
void arm_rms_q15(q15_t * pSrc, uint32_t blockSize, q15_t * pResult)
参数定义:
[in] *pSrc
points to the input vector
12.1 标准偏差 Standard deviation
这部分函数用于计算标准偏差,公式描述如下: Result = sqrt((sumOfSquares - sum2 / blockSize) / (blockSize - 1)) 其中: sumOfSquares = pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + ... + pSrc[blockSize-1] *
UM403 STM32-V5 开发板系统篇手册
(3)
printf("******************************************************************\r\n"); }
1. 这个是浮点数标准偏差求解,这里我们先用 matlab 生成一组随机的浮点数,并求解其对应的标准偏
float32_t pSrc[10] = {0.6557, 0.0357, 0.8491, 0.9340, 0.6787, 0.7577, 0.7431, 0.3922, 0.6555, 0.1712}; float32_t pResult; uint32_t pIndex;
q31_t pSrc1[10]; q31_t pResult1;
12.1.3 arm_std_q15
此函数的使用比较简单,函数定义如下: void arm_std_q15(q15_t * pSrc, uint32_t blockSize, q15_t * pResult) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult standard deviation value returned here 注意事项: 输入参数是1.15格式,相乘后的的结果就是1.15*1.15 = 2.30格式,这种情况下,内部64位累加器的 的格式就是34.30。最终的输出结果要截取到低15位数据,然后通过饱和运算最终输出数据格式1.15。
12.2 均方根 RMS
这部分函数用于计算标准偏差,公式描述如下: Result = sqrt(((pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + ... + pSrc[blockSize-1] *
pSrc[blockSize-1]) / blockSize));
12.2.1 arm_rms_f32
for(pIndex = 0; pIndex < 10; pIndex++)
{
pSrc1[pIndex] = rand();
}
arm_std_q31(pSrc1, 10, &pResult1);
(2)
printf("arm_std_q31 : pResult = %d\r\n", pResult1);
版本:1.0
第 2 页 共 10 页
安富莱 DSP 教程
UM403 STM32-V5 开发板系统篇手册
程序设计:
/* ********************************************************************************************************* * 函 数 名: DSP_Std * 功能说明: 求标准偏差 * 形 参:无 * 返 回 值: 无 ********************************************************************************************************* */ static void DSP_Std(void) {
12.2.4 实例讲解
实验目的: 1. 学习 StatisticsMathFunctions 中均方根的求解
实验内容: 1. 按下按键 K2, 串口打印函数 DSP_RMS 的输出结果
实验现象: 通过窗口上位机软件 SecureCRT(V5 光盘里面有此软件)查看打印信息现象如下:
2015年01月15日
2015年01月15日
版本:1.0
第 3 页 共 10 页
安富莱
DSP 教程
/*****************************************************************/ for(pIndex = 0; pIndex < 10; pIndex++) {
pSrc2[pIndex] = rand()%32768; } arm_std_q15(pSrc2, 10, &pResult2); printf("arm_std_q15 : pResult = %d\r\n", pResult2);
pSrc[blockSize-1] sum = pSrc[0] + pSrc[1] + pSrc[2] + ... + pSrc[blockSize-1]
12.1.1 arm_std_f32
此函数的使用比较简单,函数定义如下: void arm_std_f32(float32_t * pSrc, uint32_t blockSize, float32_t * pResult) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult standard deviation value returned here
相关文档
最新文档