硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3859|回复: 7
收起左侧

[DSP] ARM DSP库新增正切函数arm_atan2_f32.c,arm_atan2_q15.c等

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106520
QQ
发表于 2022-4-23 00:52:02 | 显示全部楼层 |阅读模式
CMSIS_5/CMSIS/DSP/Source/FastMathFunctions at develop · ARM-software/CMSIS_5 (github.com)

image.png

[C] 纯文本查看 复制代码
/* ----------------------------------------------------------------------
 * Project:      CMSIS DSP Library
 * Title:        arm_atan2_f32.c
 * Description:  float32 Arc tangent of y/x
 *
 * $Date:        06 July 2021
 * $Revision:    V1.10.0
 *
 * Target Processor: Cortex-M and Cortex-A cores
 * -------------------------------------------------------------------- */
/*
 * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the License); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * [url]www.apache.org/licenses/LICENSE-2.0[/url]
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "dsp/fast_math_functions.h"        

/*

atan for argument between in [0, 1.0]


*/

#define ATANHALFF32 0.463648f
#define PIHALFF32 1.5707963267948966192313f

#define ATAN2_NB_COEFS_F32 10

static const float32_t atan2_coefs_f32[ATAN2_NB_COEFS_F32]={0.0f
,1.0000001638308195518f
,-0.0000228941363602264f
,-0.3328086544578890873f
,-0.004404814619311061f
,0.2162217461808173258f
,-0.0207504842057097504f
,-0.1745263362250363339f
,0.1340557235283553386f
,-0.0323664125927477625f
};

__STATIC_FORCEINLINE float32_t arm_atan_limited_f32(float32_t x)
{
    float32_t res=atan2_coefs_f32[ATAN2_NB_COEFS_F32-1];
    int i=1;
    for(i=1;i<ATAN2_NB_COEFS_F32;i++)
    {
        res = x*res + atan2_coefs_f32[ATAN2_NB_COEFS_F32-1-i];
    }


    return(res);
}

__STATIC_FORCEINLINE float32_t arm_atan_f32(float32_t x)
{
   int sign=0;
   float32_t res=0.0f;

   if (x < 0.0f)
   {
      sign=1;
      x=-x;
   }

   if (x > 1.0f)
   {
      x = 1.0f / x;
      res = PIHALFF32 - arm_atan_limited_f32(x);
   }
   else
   {
     res += arm_atan_limited_f32(x);
   }


   if (sign)
   {
     res = -res;
   }

   return(res);
}


/**
  @ingroup groupFastMath
 */

/**
  @defgroup atan2 ArcTan2

  Computing Arc tangent only using the ratio y/x is not enough to determine the angle
  since there is an indeterminacy. Opposite quadrants are giving the same ratio.

  ArcTan2 is not using y/x to compute the angle but y and x and use the sign of y and x
  to determine the quadrant.

 */

/**
  @addtogroup atan2
  @{
 */

/**
  @brief       Arc Tangent of y/x using sign of y and x to get right quadrant
  @param[in]   y  y coordinate
  @param[in]   x  x coordinate
  @param[out]  result  Result
  @return  error status.
 
  @par         Compute the Arc tangent of y/x:
                   The sign of y and x are used to determine the right quadrant
                   and compute the right angle.
*/


arm_status arm_atan2_f32(float32_t y,float32_t x,float32_t *result)
{
    if (x > 0.0f)
    {
        *result=arm_atan_f32(y/x);
        return(ARM_MATH_SUCCESS);
    }
    if (x < 0.0f)
    {
        if (y > 0.0f)
        {
           *result=arm_atan_f32(y/x) + PI;
        }
        else if (y < 0.0f)
        {
           *result=arm_atan_f32(y/x) - PI;
        }
        else
        {
            if (signbit(y))
            {
               *result= -PI;
            }
            else
            {
               *result= PI;
            }
        }
        return(ARM_MATH_SUCCESS);
    }
    if (x == 0.0f)
    {
        if (y > 0.0f)
        {
            *result=PIHALFF32;
            return(ARM_MATH_SUCCESS);
        }
        if (y < 0.0f)
        {
            *result=-PIHALFF32;
            return(ARM_MATH_SUCCESS);
        }
    }
    

    return(ARM_MATH_NANINF);

}

/**
  @} end of atan2 group
 */

回复

使用道具 举报

0

主题

3

回帖

3

积分

新手上路

积分
3
发表于 2022-4-23 09:12:45 | 显示全部楼层
这个好,SDR解调FM正好用上。
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106520
QQ
 楼主| 发表于 2022-4-23 09:31:05 | 显示全部楼层
pspice 发表于 2022-4-23 09:12
这个好,SDR解调FM正好用上。

不容易,终于开始完善三角函数支持了。
回复

使用道具 举报

0

主题

1

回帖

1

积分

新手上路

积分
1
发表于 2022-8-17 17:27:44 | 显示全部楼层
棒。正好机器人逆运动学要用
回复

使用道具 举报

3

主题

4

回帖

13

积分

新手上路

积分
13
发表于 2023-5-28 19:44:06 | 显示全部楼层
请问一下,最简单的移植方法是什么样的啊?
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106520
QQ
 楼主| 发表于 2023-5-29 01:33:41 | 显示全部楼层
wangjiahao88 发表于 2023-5-28 19:44
请问一下,最简单的移植方法是什么样的啊?

最简单的办法是MDK RTE一键添加。

DSP视频教程第2期:系统介绍ARM DSP数字信号处理库以及超简单的移植方法分享(2022-01-27)
https://www.armbbs.cn/forum.php? ... 0766&fromuid=58
(出处: 硬汉嵌入式论坛)
回复

使用道具 举报

3

主题

137

回帖

146

积分

初级会员

积分
146
发表于 2023-6-25 11:34:35 | 显示全部楼层
最新版的ARM DSP地址是多少呢,楼主位地址失效了
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106520
QQ
 楼主| 发表于 2023-6-25 14:36:16 | 显示全部楼层
浴火重生 发表于 2023-6-25 11:34
最新版的ARM DSP地址是多少呢,楼主位地址失效了

DSP库独立出来了

https://github.com/ARM-software/CMSIS-DSP
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-4-23 20:26 , Processed in 0.235298 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表