完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
转dsp系列教程
本期教程开始学习ARM官方的DSP库,这里我们先从基本数学函数开始。本期教程主要讲绝对值,加法,点乘和乘法四种运算。 8.1 绝对值(Vector Absolute Value) 8.2 求和(Vector Addition) 8.3 点乘(Vector Dot Product) 8.4 乘法(Vector Multiplication) 8.1 绝对值(Vector Absolute Value) 这部分函数主要用于求绝对值,公式描述如下: pDst[n] = abs(pSrc[n]), 0 <= n < blockSize. 特别注意,这部分函数支持目标指针和源指针指向相同的缓冲区。 8.1.1 arm_abs_f32 这个函数用于求32位浮点数的绝对值,源代码分析如下: [url=]复制代码[/url]
|
|
|
相关推荐
|
|
|
8.4.4 arm_mult_q7
这个函数用于求8位定点数的乘法,源代码分析如下: 复制代码 /** * @brief Q7 vector multiplication * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. * * Scaling and Overflow Behavior: (1) * par * The function uses saturating arithmetic. * Results outside of the allowable Q7 range [0x80 0x7F] will be saturated. */ void arm_mult_q7( q7_t * pSrcA, q7_t * pSrcB, q7_t * pDst, uint32_t blockSize) { uint32_t blkCnt; /* loop counters */ #ifndef ARM_MATH_CM0_FAMILY /* Run the below code for Cortex-M4 and Cortex-M3 */ q7_t out1, out2, out3, out4; /* Temporary variables to store the product */ /* loop Unrolling */ blkCnt = blockSize >> 2u; /* First part of the processing with loop unrolling. Compute 4 outputs at a time. ** a second loop below computes the remaining 1 to 3 samples. */ while(blkCnt > 0u) { /* C = A * B */ /* Multiply the inputs and store the results in temporary variables */ (2) out1 = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8); out2 = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8); out3 = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8); out4 = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8); /* Store the results of 4 inputs in the destination buffer in single cycle by packing */ *__SIMD32(pDst)++ = __PACKq7(out1, out2, out3, out4); (3) /* Decrement the blockSize loop counter */ blkCnt--; } /* If the blockSize is not a multiple of 4, compute any remaining output samples here. ** No loop unrolling is used. */ blkCnt = blockSize % 0x4u; #else /* Run the below code for Cortex-M0 */ /* Initialize blkCnt with number of samples */ blkCnt = blockSize; #endif /* #ifndef ARM_MATH_CM0_FAMILY */ while(blkCnt > 0u) { /* C = A * B */ /* Multiply the inputs and store the result in the destination buffer */ *pDst++ = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8); /* Decrement the blockSize loop counter */ blkCnt--; } } 1. 这个函数使用了饱和算法。 所得结果是Q7格式,范围 [0x80 0x7F]。 2. 将两个Q7格式的数据乘积左移7位,也就是丢掉低7位的数据,并将所得结果饱和到8位精度。 3. __PACKq7函数可以在一个时钟周期就能完成相应操作。 |
|
|
|
|
|
|
|
|
8.4.5 实例讲解
实验目的: 1. 四种类型数据的乘法。 实验内容: 1. 按下摇杆的UP键, 串口打印输出结果 实验现象: 通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下: |
|
|
|
|
|
|
|
|
程序设计:
复制代码 /* ********************************************************************************************************* * 函 数 名: DSP_Multiplication * 功能说明: 乘法 * 形 参:无 * 返 回 值: 无 ********************************************************************************************************* */ static void DSP_Multiplication(void) { static float32_t pSrcA[5] = {1.0f,1.0f,1.0f,1.0f,1.0f}; static float32_t pSrcB[5] = {1.0f,1.0f,1.0f,1.0f,1.0f}; static float32_t pDst[5]; static q31_t pSrcA1[5] = {1,1,1,1,1}; static q31_t pSrcB1[5] = {1,1,1,1,1}; static q31_t pDst1[5]; static q15_t pSrcA2[5] = {1,1,1,1,1}; static q15_t pSrcB2[5] = {1,1,1,1,1}; static q15_t pDst2[5]; static q7_t pSrcA3[5] = {0x70,1,1,1,1}; static q7_t pSrcB3[5] = {0x7f,1,1,1,1}; static q7_t pDst3[5]; pSrcA[0] += 1.1f; arm_mult_f32(pSrcA, pSrcB, pDst, 5); printf("arm_mult_f32 = %frn", pDst[0]); pSrcA1[0] += 1; arm_mult_q31(pSrcA1, pSrcB1, pDst1, 5); printf("arm_mult_q31 = %drn", pDst1[0]); pSrcA2[0] += 1; arm_mult_q15(pSrcA2, pSrcB2, pDst2, 5); printf("arm_mult_q15 = %drn", pDst2[0]); pSrcA3[0] += 1; arm_mult_q7(pSrcA3, pSrcB3, pDst3, 5); printf("arm_mult_q7 = %drn", pDst3[0]); printf("***********************************rn"); } 8.5 总结 本期教程就跟大家讲这么多,还是那句话,可以自己写些代码调用本期教程中讲的这几个函数,如果可以的话,可以自己尝试直接调用这些DSP指令。 |
|
|
|
|
|
|
|
【瑞萨RA6E2】瑞萨E2S软件安装过程,等待过程玩下97_e2 studio_ZGZZ
140 浏览 0 评论
483 浏览 0 评论
【原创】【RA4M2-SENSOR开发板评测】低功耗+USB综合测试
815 浏览 0 评论
1346 浏览 2 评论
804 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
16903 浏览 31 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 17:34 , Processed in 0.761444 second(s), Total 69, Slave 51 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖