
特别说明:完整45期数字信号处理教程,原创高性能示波器代码全开源地址:链接 第11章 StatisticsMathFunctions的使用(一) 本期教程主要讲解统计函数中的最大值,最小值,平均值和功率的计算。 11.1 最大值Maximum 11.2 最小值Minimum 11.3 平均值Mean 11.4 功率Power 11.5 总结 11.1 最大值Maximum 这部分函数用于计算数组中的最大值,并返回数组中的最大值和最大值在数组中的位置。 11.1.1 arm_max_f32此函数的使用比较简单,函数定义如下: void arm_max_f32(float32_t * pSrc, uint32_t blockSize, float32_t * pResult, uint32_t * pIndex) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult maximum value returned here [out] *pIndex index of maximum value returned here 11.1.2 arm_max_q31函数定义如下: void arm_max_q31(q31_t * pSrc, uint32_t blockSize, q31_t * pResult, uint32_t * pIndex) 参数定义: [in] *pSrc points to the input vector [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函数定义如下: void arm_max_q15(q15_t * pSrc, uint32_t blockSize, q15_t * pResult, uint32_t * pIndex) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult maximum value returned here [out] *pIndex index of maximum value returned here 11.1.4 arm_max_q7函数定义如下: void arm_max_q7(q7_t * pSrc, uint32_t blockSize, q7_t * pResult, uint32_t * pIndex) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult maximum value returned here [out] *pIndex index of maximum value returned here 11.1.5 实例讲解实验目的: 1. 学习FastMathFunctions中最大值的求解 实验内容: 1. 按下按键K1, 串口打印函数DSP_Max的输出结果 实验现象: 通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下: ![]() 程序设计:
1. 这里10个浮点随机数是通过matlab生成的,生成方法很简单,在命令窗口输入命令: rand(1, 10) %1行10列 获取结果如下: ![]() 如果想获取整形随机数,可以使用函数: randi(32768, 1, 10) %生成的随机数不超过32768, 1行10列。 ![]() 2. 使用stdlib.h中的rand生成伪随机数。 3. 通过对32768求余获得可以用于函数arm_max_q15的数据。 4. 通过对128求余获得可以用于函数arm_max_q7的数据。 11.2 最小值Minimum 这部分函数用于计算数组中的最小值,并返回数组中的最小值和最小值在数组中的位置。 11.2.1 arm_min_f32此函数的使用比较简单,函数定义如下: void arm_ min _f32(float32_t * pSrc, uint32_t blockSize, float32_t * pResult, uint32_t * pIndex) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult maximum value returned here [out] *pIndex index of maximum value returned here 11.2.2 arm_ min _q31函数定义如下: void arm_ min _q31(q31_t * pSrc, uint32_t blockSize, q31_t * pResult, uint32_t * pIndex) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult maximum value returned here [out] *pIndex index of maximum value returned here 11.2.3 arm_ min _q15函数定义如下: void arm_ min _q15(q15_t * pSrc, uint32_t blockSize, q15_t * pResult, uint32_t * pIndex) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult maximum value returned here [out] *pIndex index of maximum value returned here 11.2.4 arm_ min _q7函数定义如下: void arm_ min _q7(q7_t * pSrc, uint32_t blockSize, q7_t * pResult, uint32_t * pIndex) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult maximum value returned here [out] *pIndex index of maximum value returned here 11.2.5 实例讲解实验目的: 1. 学习FastMathFunctions中最小值的求解 实验内容: 1. 按下按键K2, 串口打印函数DSP_Min的输出结果 实验现象: 通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下: ![]() 程序设计:
1. 这里求最小值跟上面求最大值基本是一样的。 |
11.3 平均值Mean 这部分函数用于计算数组的平均值。公式描述如下: Result = (pSrc[0] + pSrc[1] + pSrc[2] + ... + pSrc[blockSize-1]) / blockSize; 11.3.1 arm_mean_f32此函数的使用比较简单,函数定义如下: void arm_mean_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 mean value returned here 11.3.2 arm_ mean _q31函数定义如下: void arm_mean_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 mean value returned here 注意事项: 求平均前的数据之和是赋值给了64位累加器,然后再求平均。 11.3.3 arm_ mean _q15函数定义如下: void arm_mean_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 mean value returned here 注意事项: 求平均前的数据之和是赋值给了32位累加器,然后再求平均。 11.3.4 arm_ mean _q7函数定义如下: void arm_mean_q7(q7_t * pSrc, uint32_t blockSize, q7_t * pResult) 参数定义: [in]*pSrc points to the input vector [in] blockSize length of the input vector [out]*pResult mean value returned here 注意事项: 求平均前的数据之和是赋值给了32位累加器,然后再求平均。 11.3.5 实例讲解实验目的: 1. 学习FastMathFunctions中平均值的求解 实验内容: 1. 按下按键K3, 串口打印函数DSP_Mean的输出结果 实验现象: 通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下: ![]() 程序设计:
这部分函数用于计算数组的功率。公式描述如下: Result = pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + pSrc[2] * pSrc[2] + ... + pSrc[blockSize-1] * pSrc[blockSize-1]; 11.4.1 arm_power_f32函数定义如下: void arm_power_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 sum of the squares value returned here 11.4.2 arm_power_q31函数定义如下: void arm_power_q31(q31_t * pSrc, uint32_t blockSize, q63_t * pResult) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult sum of the squares value returned here 注意事项: 输入参数是1.31格式,两个数据的乘积就是1.31*1.31 = 2.62格式,这里将此结果右移14位,也就是将低14位数据截取掉,最终的输出做64位饱和运算,结果是16.48格式。 11.4.3 arm_power_q15函数定义如下: void arm_power_q15(q15_t * pSrc, uint32_t blockSize, q63_t * pResult) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult sum of the squares value returned here 注意事项: 输入参数是1.15格式,两个数据的乘积就是1.15*1.15 = 2.30格式,最终的输出做64位饱和运算,结果是34.30格式。 11.4.4 arm_power_q7函数定义如下: void arm_power_q7(q7_t * pSrc, uint32_t blockSize, q31_t * pResult) 参数定义: [in] *pSrc points to the input vector [in] blockSize length of the input vector [out] *pResult sum of the squares value returned here 注意事项: 输入参数是1.7格式,两个数据的乘积就是1.7*1.7 = 2.14格式,最终的输出做32位饱和运算,结果是18.14格式。 11.4.5 实例讲解实验目的: 1. 学习FastMathFunctions中功率的求解 实验内容: 1. 按下摇杆UP键, 串口打印函数DSP_Power的输出结果 实验现象: 通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下: ![]() 程序设计:
本期教程就跟大家讲这么多,有兴趣的可以深入研究这些函数源码的实现。 |
牛掰冷死! |
谢谢分享啊 |
谢谢分享啊 |
不错,学习一下。 |
学习了 帮顶![]() |