【安富莱DSP教程】第14章 SupportFunctions的使用(二)
特别说明:完整45期数字信号处理教程,原创高性能示波器代码全开源地址:链接第14章 SupportFunctions的使用(二)本期教程主要讲解支持函数中的Q7,Q15和Q31分别向其它类型数据转换。
14.1 定点数Q7转换
14.2 定点数Q15转换
14.3 定点数Q31转换
14.4 总结
14.1 定点数Q7转换
14.1.1 arm_q7_to_float
公式描述:
pDst = (float32_t) pSrc / 128; 0 <= n < blockSize.
函数定义如下:
void arm_q7_to_float(q7_t * pSrc, float32_t * pDst, uint32_t blockSize)
参数定义:
*pSrc points to the Q7 input vector
*pDst points to the floating-point output vector
blockSize length of the input vector
14.1.2 arm_q7_to_q31
公式描述:
pDst = (q31_t) pSrc << 24; 0 <= n < blockSize.
函数定义如下:
void arm_q7_to_q31(q7_t * pSrc, q31_t * pDst, uint32_t blockSize)
参数定义:
*pSrc points to the Q7 input vector
*pDst points to the Q31 output vector
blockSize length of the input vector
14.1.3 arm_q7_to_q15
公式描述:
pDst = (q15_t) pSrc << 8; 0 <= n < blockSize.
函数定义如下:
void arm_q7_to_q15(q7_t * pSrc, q15_t * pDst, uint32_t blockSize)
参数定义:
*pSrc points to the Q7 input vector
*pDst points to the Q15 output vector
blockSize length of the input vector
14.1.4 实例讲解
实验目的:
1. 学习SupportFunctions中Q7格式数据的转换
实验内容:
1. 按下按键K1, 串口打印函数DSP_Q7的输出结果
实验现象:
通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
程序设计:
/*
*********************************************************************************************************
* 函 数 名: DSP_Q7
* 功能说明: Q7格式数据向其它格式转换
* 形 参:无
* 返 回 值: 无
*********************************************************************************************************
*/
static void DSP_Q7(void)
{
float32_t pDst;
uint32_t pIndex;
q31_t pDst1;
q15_t pDst2;
q7_tpSrc;
for(pIndex = 0; pIndex < 10; pIndex++)
{
pSrc = rand()%128;
printf("pSrc[%d] = %d\r\n", pIndex, pSrc);
}
/*****************************************************************/
arm_q7_to_float(pSrc, pDst, 10);
for(pIndex = 0; pIndex < 10; pIndex++)
{
printf("arm_q7_to_float: pDst[%d] = %f\r\n", pIndex, pDst);
}
/*****************************************************************/
arm_q7_to_q31(pSrc, pDst1, 10);
for(pIndex = 0; pIndex < 10; pIndex++)
{
printf("arm_q7_to_q31: pDst1[%d] = %d\r\n", pIndex, pDst1);
}
/*****************************************************************/
arm_q7_to_q15(pSrc, pDst2, 10);
for(pIndex = 0; pIndex < 10; pIndex++)
{
printf("arm_q7_to_q15: pDst2[%d] = %d\r\n", pIndex, pDst2);
}
/*****************************************************************/
printf("******************************************************************\r\n");
} 14.2 定点数Q15转换
14.2.1 arm_q15_to_float
公式描述:
pDst = (float32_t) pSrc / 32768; 0 <= n < blockSize.
函数定义如下:
void arm_q15_to_float(q15_t * pSrc, float32_t * pDst, uint32_t blockSize)
参数定义:
*pSrc points to the Q15 input vector
*pDst points to the floating-point output vector
blockSize length of the input vector
14.2.2 arm_q15_to_q31
公式描述:
pDst = (q31_t) pSrc << 16; 0 <= n < blockSize.
函数定义如下:
void arm_q15_to_q31(q15_t * pSrc, q31_t * pDst, uint32_t blockSize)
参数定义:
*pSrc points to the Q15 input vector
*pDst points to the Q31 output vector
blockSize length of the input vector
14.2.3 arm_q15_to_q7
公式描述:
pDst = (q7_t) pSrc >> 8; 0 <= n < blockSize.
函数定义如下:
void arm_q7_to_q15(q7_t * pSrc, q15_t * pDst, uint32_t blockSize)
参数定义:
*pSrc points to the Q15 input vector
*pDst points to the Q7 output vector
blockSize length of the input vector
14.2.4 实例讲解
实验目的:
1. 学习SupportFunctions中Q15格式数据的转换
实验内容:
1. 按下按键K1, 串口打印函数DSP_Q7的输出结果
实验现象:
通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
程序设计:
/*
*********************************************************************************************************
* 函 数 名: DSP_Q15
* 功能说明: Q15格式数据向其它格式转换
* 形 参:无
* 返 回 值: 无
*********************************************************************************************************
*/
static void DSP_Q15(void)
{
float32_t pDst;
uint32_t pIndex;
q31_t pDst1;
q15_t pSrc;
q7_t pDst2;
for(pIndex = 0; pIndex < 10; pIndex++)
{
pSrc = rand()%32678;
printf("pSrc[%d] = %drn", pIndex, pSrc);
}
/*****************************************************************/
arm_q15_to_float(pSrc, pDst, 10);
for(pIndex = 0; pIndex < 10; pIndex++)
{
printf("arm_q15_to_float: pDst[%d] = %frn", pIndex, pDst);
}
/*****************************************************************/
arm_q15_to_q31(pSrc, pDst1, 10);
for(pIndex = 0; pIndex < 10; pIndex++)
{
printf("arm_q15_to_q31: pDst1[%d] = %drn", pIndex, pDst1);
}
/*****************************************************************/
arm_q15_to_q7(pSrc, pDst2, 10);
for(pIndex = 0; pIndex < 10; pIndex++)
{
printf("arm_q15_to_q7: pDst2[%d] = %drn", pIndex, pDst2);
}
/*****************************************************************/
printf("******************************************************************rn");
}
14.3 定点数Q31转换
14.3.1 arm_q31_to_float
公式描述:
pDst = (float32_t) pSrc / 2147483648; 0 <= n < blockSize.
函数定义如下:
void arm_q31_to_float(q31_t * pSrc, float32_t * pDst, uint32_t blockSize)
参数定义:
*pSrc points to the Q31 input vector
*pDst points to the floating-point output vector
blockSize length of the input vector
14.3.2 arm_q31_to_q15
公式描述:
pDst = (q15_t) pSrc >> 16; 0 <= n < blockSize.
函数定义如下:
void arm_q31_to_q15(q31_t * pSrc, q15_t * pDst, uint32_t blockSize)
参数定义:
*pSrc points to the Q31 input vector
*pDst points to the Q15 output vector
blockSize length of the input vector
14.3.3 arm_q31_to_q7
公式描述:
pDst = (q7_t) pSrc >> 24; 0 <= n < blockSize.
函数定义如下:
void arm_q31_to_q7(q31_t * pSrc, q7_t * pDst, uint32_t blockSize)
参数定义:
*pSrc points to the Q31 input vector
*pDst points to the Q7 output vector
blockSize length of the input vector
14.3.4 实例讲解
实验目的:
1. 学习SupportFunctions中Q31格式数据的转换
实验内容:
1. 按下按键K1, 串口打印函数DSP_Q31的输出结果
实验现象:
通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
程序设计:
/*
*********************************************************************************************************
* 函 数 名: DSP_Q31
* 功能说明: Q31格式数据向其它格式转换
* 形 参:无
* 返 回 值: 无
*********************************************************************************************************
*/
static void DSP_Q31(void)
{
float32_t pDst;
uint32_t pIndex;
q31_t pSrc;
q15_t pDst1;
q7_t pDst2;
for(pIndex = 0; pIndex < 10; pIndex++)
{
pSrc = rand();
printf("pSrc[%d] = %drn", pIndex, pSrc);
}
/*****************************************************************/
arm_q31_to_float(pSrc, pDst, 10);
for(pIndex = 0; pIndex < 10; pIndex++)
{
printf("arm_q31_to_float: pDst[%d] = %frn", pIndex, pDst);
}
/*****************************************************************/
arm_q31_to_q15(pSrc, pDst1, 10);
for(pIndex = 0; pIndex < 10; pIndex++)
{
printf("arm_q31_to_q15: pDst1[%d] = %drn", pIndex, pDst1);
}
/*****************************************************************/
arm_q31_to_q7(pSrc, pDst2, 10);
for(pIndex = 0; pIndex < 10; pIndex++)
{
printf("arm_q31_to_q7: pDst2[%d] = %drn", pIndex, pDst2);
}
/*****************************************************************/
printf("******************************************************************rn");
}
14.4 总结
本期教程就跟大家讲这么多,有兴趣的可以深入研究这些函数源码的实现。
页:
[1]