DSP使用三角函数问题

问题

当浮点数很大时,作为三角函数的入参,计算出来的结果会让人大跌眼镜!

X64 Windows计算器计算的sin(110000),上面那个数值明显是不对的

分析

查看sinf函数原型,是通过查表法来实现的,也就说芯片内部不可能维护一个巨大的表格,入参很大会有误差

C++ 复制代码
//! \brief Single-Precision Floating-Point Sine (radians)
//! \param[in] X single precision floating point argument
//! \return the sine of a floating-point argument X (in radians) using table
//! look-up and Taylor series expansion between the look-up table entries.
//!
//! \note 
//! -# This is a standard C math function and requires "math.h" to be 
//! included
//! -# For COFF executables float and double are both single precision
//! 32-bit floating point types, therefore, the double and float variant of 
//! this function may be used interchangeably.
//!
//! <table>
//! <caption id="multi_row">Performance Data</caption>
//! <tr><th>Cycles <th> Comment 
//! <tr><td> 38 <td> Cycle count includes the call and return
//! </table>
//
float32_t sinf (float32_t X);

解决

需要将角度值限制在±2π范围内(理论上说这个范围内的精度是最好的)

Plain 复制代码
// 将角度归一化到[-2π, 2π]范围内
float normalize_angle(float angle)
{
    const float two_pi = 2.0f * PI;
    float normalized = fmodf(angle, two_pi);
    if(normalized < -PI) normalized += two_pi;
    if(normalized > PI) normalized -= two_pi;
    return normalized;
}

调试看归一化后的函数值

相关推荐
功夫熊猫大侠8 天前
几何绘图与三角函数计算应用
三角函数·几何绘图
诗丶远方的田筠13 天前
TI dsp FSI (快速串行接口)
ti·dsp·fsi·快速串行接口
FPGA_ADDA1 个月前
基于RFSOC ZU28DR+DSP 6U VPX处理板
fpga开发·dsp·rfsoc28dr·zu28dr·射频采集
FPGA_ADDA2 个月前
基于FPGA 和DSP 的高性能6U VPX 采集处理板
fpga开发·dsp·6u vpx·8通道采集
加点油。。。。5 个月前
DSP+Simulink——点亮LED灯(TMSDSP28379D)超详细
matlab·自动化·c·dsp开发·simulink·dsp
十月旧城6 个月前
基于TMS320X281X/F28335的DSP入门到精通01_如何开始DSP的学习与开发
dsp
FakeOccupational6 个月前
【电路笔记 TMS320F28335DSP】DSP项目文件说明
笔记·dsp
巽星石8 个月前
【Blender Python】7.一些运算、三角函数以及随机
python·blender·三角函数·随机·环形阵列
江山如画,佳人北望9 个月前
智能平衡移动机器人-MBD开发介绍
dsp·ccs·matlab simulink