cordic | Trigonometric functions for fixed-point numbers
kandi X-RAY | cordic Summary
kandi X-RAY | cordic Summary
Trigonometric functions for fixed-point numbers
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of cordic
cordic Key Features
cordic Examples and Code Snippets
Community Discussions
Trending Discussions on cordic
QUESTION
I'm using CLang. Is there a way for a certain function or whole .cpp
to treat SFINAE as error? If there is an option --sfinae-as-error
, or #pragma sfinae_disable
/#pragma sfinae_enable
for a certain function?
It seems that due to SFINAE my function specialization has disappeared (became unusable) and I don't know how to find the reason why it has failed (where SFINAE comes from), basically I have unintentional SFINAE case and I want to find out the line that causes it.
To explain this, I have a small method:
...ANSWER
Answered 2021-Jun-07 at 14:08Basically my build system just outputted last screen of errors, it truncated errors to last screen showing on console. Of cause in the beginning of screen it showed tiny message that truncation happened but I didn't noticed that. And when I restored whole log there appeared following lines:
QUESTION
How to calculate trigonometric functions: arctangent, arcsine or, at least, sine and cosine in VHDL? I have a value in IEEE 754 single-precision floating-point format (t.e. a sign, a mantissa, an exponent) (picture below). As I know, it could be implemented as a look-up table or via CORDIC algorithm. Both implementations are suitable for me. Precision up to Pi/1000 would be enought. The implementation should be synthesizable. Device - Artix-7 FPGA.
Similar code in C:
...ANSWER
Answered 2019-Dec-11 at 17:36You said "I have a value in IEEE 754 single-precision floating-point format ". I would definitely try to avoid using IEEE format numbers. It make things unnecessary complex. I don't know where that number came from or how you got that into the FPGA but the first thing to do is to try to convert that to a fixed point format.
Xilinx have off-the-shelf Cordic code for you for Arc Tan
. That would make your life a lot easier. As expected it does not accept IEEE numbers but does work with "signed fractions" and precision sizes between 8 and 48 bits. You should get their Cordic IP manual and read up on what it can do. I have not seen Cordic code for asin
yet.
You might need to put in some effort to control the I/O as the IP only works with streaming AXI4 interfaces.
What does surprise me is that you provide you example in C code but are talking about using VHDL. I would expect anybody familiar with C to use (System) Verilog as the langues are very, very close. Also at the risk of upsetting some people: if at all possible use System Verilog. Verilog has had several more iterations then VHDL and is much closer to how modern languages are used these days.
QUESTION
I am making a library for math functions, intended to test and challenge my programming and math skills. A necessary part of this is trig: Sine, Cosine, Tangent, and derivatives/inverses, using degrees or radians.
I have spent hours searching the web for implementation of Taylor Series or CORDIC algorithm using degrees AND/OR radians, to no avail.
...ANSWER
Answered 2019-Nov-12 at 21:50The Taylor series for the sin function is straightforward to implement. Note that any reference which gives a Taylor series for a trigonometric function will assume the input is in radians, unless specified otherwise.
QUESTION
I am trying to implement the CORDIC algorithm for approximating a sine function in single precision, on architecture with no FPU. I compare the result obtained from my implementation with results obtained from standard C math functions. I tried implementing in two ways: 1) directly using floating-point operations, 2) converting the input to fixed-point and using integer based operations. I compare the results obtained from sinf(), sin() and sin() cast to float. The comparison is based on comparing the hexadecimal representations of the result with the expected from math functions.
In (1) the implementation uses double types, then the result is cast to float. My calculated values are always off by at least one hexadecimal digit, no matter how many iterations are done with CORDIC.
In (2), initially the input was mapped to a 32 bit integer. The error was the same as in (1). Only after, increasing the fixed point size to 64 bit (and the number of iterations to 64) the precision improved. But yet, there are ranges of input for which the algorithm is not precise. If I would increase the fixed point size to 128 bit (and the number of iterations to 128), it may be enough to obtain precise values but it is completely unpractical.
The algorithm in (1) is a modified version from the book https://www.jjj.de/fxt/fxtbook.pdf
...ANSWER
Answered 2019-May-16 at 10:14I gave it a shot but as mentioned in the comments you can not expect exact bit match as math goniometrics is usually based on Chebyshev polynomials. Also you do not have defined the cordic_1K
constant. After some search I managed to do this in C++/VCL:
QUESTION
I am calculating the intersection point of two lines given in the polar coordinate system:
...ANSWER
Answered 2017-Dec-10 at 11:22With the help of one of my colleagues I figured out a quite easy solution that does not require any hand written implementations or manipulation of the fixed point data:
use #include "hls_math.h"
and the hls::sinf()
and hls::cosf()
functions.
It is important to say that the input of the functions should be ap_fixed<32, I>
where I <= 32
. The output of the functions can be assigned to different types e.g., ap_fixed<16, I>
Example:
QUESTION
I'm trying to implement fast atan2(float) with 11 bits accuracy in mantissa. The atan2 implementation will be used for image processing. So it might be better to be implemented with SIMD instruction(The impl targeting x86(with SSE2) & ARM(with vpfv4 NEON)).
For now, I use chebyshev polynomial approximation(https://jp.mathworks.com/help/fixedpoint/examples/calculate-fixed-point-arctangent.html).
I'm willing to implement vectorized code manually. I will use SSE2(or later) & NEON wrapper library. I plan or tried these implementation option
- vectorized Polynomial approximation
- chebyshev polynomial(now implemented)
- scalar look up table ( + linear interpolation)
- vectorized look up table (is this possible? I'm not familiar with NEON, so I don' know some instructions like VGATHER in NEON)
- vectorized CORDIC method (this may be slow since it require 12+ rotation iterations to get 11bits accuracy)
else good idea?
...ANSWER
Answered 2017-Sep-16 at 16:32The first thing you would want to check is whether your compiler is able to vectorize atan2f (y,x)
when applied to an array of float
s. This usually requires at least a high optimization level such as -O3
and possibly specifying a relaxed "fast math" mode, in which errno
handling, denormals and special inputs such as infinities and NaNs are largely ignored. With this approach, accuracy may be well in excess of what is required, but it may be hard to beat a carefully tuned library implementation with respect to performance.
The next thing to try is to write a simple scalar implementation with sufficient accuracy, and have the compiler vectorize it. Typically this means avoiding anything but very simple branches which can be converted to branchless code through if-conversion. An example of such code is the fast_atan2f()
shown below. With the Intel compiler, invoked as icl /O3 /fp:precise /Qvec_report=2 my_atan2f.c
, this is vectorized successfully: my_atan2f.c(67): (col. 9) remark: LOOP WAS VECTORIZED.
Double checking the generated code through disassembly shows that fast_atan2f()
has been inlined and vectorized using SSE instructions of the *ps
flavor.
If all else fails, you could translate the code of fast_atan2()
into platform-specific SIMD intrinsics by hand, which should not be all that hard to do. I do not have sufficient experience to do it quickly though.
I have used a very simple algorithm in this code, which is a simple argument reduction to produce a reduced argument in [0,1], followed by a minimax polynomial approximation, and a final step mapping the result back to the full circle. Core approximation was generated with the Remez algorithm and is evaluated using a 2nd-order Horner scheme. Fused-multiply add (FMA) can be used where available. Special cases involving infinities, NaNs, or 0/0
are not handled, for the sake of performance.
QUESTION
#include
#include
#include
using namespace std;
double bisection(double errorVal, double userNum){
double upper=userNum, lower=0;
double mid=(lower+upper)/2.0;
while(!(fabs(mid*mid-userNum)<=errorVal)){
mid=(lower+upper)/2.0;
if(mid*mid>userNum){
upper=mid;
}else{
lower=mid;
}
}
return mid;
}
int main(){
double errorVal=0, userNum=0;
std::cout<<"Please enter a number (larger than 0) to calculate its square root, and the desired margin of error."<>userNum>>errorVal;
bisection(errorVal,userNum);
std::cout<<"The calculated result is "<<<<". The amount of error is "<
...ANSWER
Answered 2017-Aug-05 at 16:00Square roots of numbers smaller than 1 are larger then the initial number (remember the root function). As userNum
is the upper bound of possible results, those roots cannot be computed with your code.
As a solution: add
QUESTION
I tried to translate the MATLAB language on Cordic wikipedia webpage
However when I type those:
...ANSWER
Answered 2017-Jul-14 at 20:29You get the same result for different input because in
QUESTION
I am using Altera De0 nano Soc FPGA, and Quartus 16.1 lite edition. After doing a search on internet, I found that to get sin
, cos
and atan
Altera's CORDIC IP core can be used directly. And also found lookup table (LUT) can be used for sin or cos (mostly available in google) but how to get sin
inverse (ARCSIN
) in VHDL
?
I have found a sin
and cos
lookup table, is there a way to generate sin
inverse?
ANSWER
Answered 2017-Jun-29 at 09:40Yes there is.
For instance using CORDIC...One of my first hits on Google: A survey of CORDIC algorithms for FPGA based computer
QUESTION
I have been trying to create custom calculator for calculating trigonometric functions. Aside from Chebyshev pylonomials and/or Cordic algorithm I have used Taylor series which have been accurate by few places of decimal.
This is what i have created to calculate simple trigonometric functions without any modules:
...ANSWER
Answered 2017-May-30 at 18:02The question is broad in scope, but here are some simple ideas (and code!) that might serve as a starting point for computing arctan
. First, the good old Taylor series. For simplicity, we use a fixed number of terms; in practice, you might want to decide the number of terms to use dynamically based on the size of x
, or introduce some kind of convergence criterion. With a fixed number of terms, we can evaluate efficiently using something akin to Horner's scheme.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cordic
Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page