# Tag Info

26

Your implementation is going to be slow, and the excuse "I need it to take a fixed amount of time" does not justify this. Using plain tables smells like cargo culting as well. So I'm not tackling what you did wrong in your code, but what you did wrong in even thinking about your implementation. First, google how to implement cosine on a micro ...

5

One remark is that you should get rid of all the needless branching and code repetition. It's bad for performance and code maintenance both. Given an angle you should be able to: Take it's absolute value. Divide by PI/2. Convert to unsigned integer, truncating decimals. Then you'll either have an index from 0 to 3 or you started with an angle larger than 2*...

5

#define PI 3.14... could use a few more digits! sine should work for numbers greater than 2.0 * PI. sine should work for negative numbers. same for cosine. if(temp > 2*PI) { temp -= 2*PI; } is ineffective for numbers greater than 4.0 * PI. if(rem > 0){ // sine value for given argument isn't directly in the lut if(index == (TABLE_SIZE-1)){ ...

3

In my testing (using C++ std::sin(), which should be the same function) the Standard Library sin() is about 9 times faster than the float version of LUT sine shown in @user673679's answer. If approximation suites you, as suggested already, You might find some help in Faster Math Functions (part 2) by Robin Green (part 1 also available). Here are couple ...

3

Doxygen errors It's great that you are using Doxygen to document the code, and also that you include the formulas that your filter implements. However, you did not use the right opening and closing tags for the formulas. You have to use \f$...\f$ instead of $\f...$\f. Furthermore, you cannot use $\LaTeX$ commands in the normal text in Doxygen, use Doxygen'...

3

I have heard that the sqrt function from the standard library isn't good choice due to the unpredictable number of iterations used during calculation. The goal of standard functions do not generally include a uniform time requirement. Far more often, a precise and correct as able solution is sought. Speed is of secondary concern. my observations four ...

2

A key missing specification is the precision needed for the result as that steers algorithm design. Going forward that arg may be wide ranging and table look-up precision is good enough: I'd recommend simplifications: Pass the table in via global unless there might be more than 1 table. Perform as much as possible with integer math. With such low ...

Only top voted, non community-wiki answers of a minimum length are eligible