当前位置: 首页 > ds >正文

DSP使用三角函数问题

问题

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

在这里插入图片描述
X64 Windows计算器计算的sin(110000),上面那个数值明显是不对的

##

分析

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

//! \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π范围内(理论上说这个范围内的精度是最好的)

// 将角度归一化到[-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;
}

调试看归一化后的函数值

在这里插入图片描述

http://www.xdnf.cn/news/13530.html

相关文章:

  • 卷积神经网络参数量计算
  • 常用ADB命令
  • AIGC 基础篇 Python基础 04 for循环与while循环
  • Java 语言特性(面试系列2)
  • 自动K码对齐
  • Kotlin基础语法一
  • float负数浮点值强转uint16_t
  • NIFI的处理器:ConsumeMQTT 2.4.0
  • 【Zephyr 系列 17】多协议网关实战:BLE + LoRa + UART + MQTT 综合调度系统设计与实现
  • CoW模式、线程的本地存储和生产者-消费者模式
  • 线程分离属性
  • 【Python】 -- 趣味代码 - 扫雷游戏
  • 使用obsutil工具在OBS上完成基本的数据存取【玩转华为云】
  • LLM 推理:LLM 路由和分层技术的表征和分析
  • 进行性核上性麻痹护理指南:全维度守护健康
  • LIGHT (数据库操作)
  • 【Css】css修改滚动条的样式
  • MySQL InnoDB更新流程
  • Python格式化:让数据输出更优雅
  • 场景题目记录
  • Java - Mysql数据类型对应
  • JxBrowser 8.8.0 版本发布啦!
  • 小天互连IM系统:即时通讯在远程工作中的应用
  • 系统思考:恶性循环
  • 走线太长导致的下冲(Undershoot)现象及解决
  • matplotlib画图报错
  • 使用 pytdx,`TdxHq_API` 接口下载数据的 AI 编程指引提示词
  • 微软PowerBI考试 PL300-选择 Power BI 模型框架【附练习数据】
  • 第二十章 BKP
  • 华为认证入门怎么选?