Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Depending on how much accuracy you need you may be able to avoid the squares and the square root operation. There is a section on this topic in <a href="http://rads.stackoverflow.com/amzn/click/0131089897" rel="nofollow">Understanding Digital Signal Processing by Rick Lyons</a> (section 10.2, <em>"High-Speed Vector-Magnitude Approximation"</em>, starting at page 400 in my edition).</p> <p>The approximation is essentially:</p> <pre><code>magnitude = alpha * min + beta * max </code></pre> <p>where max and min are the maximum and minimum absolute values of the real and imaginary components, and alpha and beta are two constants which are chosen to give a reasonable error distribution over the range of interest. These constants can be represented as fractions with power of 2 divisors to keep the arithemtic simple/efficient. In the book he suggests alpha = 15/16, beta = 15/32, and you can then simplify the formula to:</p> <pre><code>magnitude = (15 / 16) * (max + min / 2) </code></pre> <p>which might be implemented as follows using integer operations:</p> <pre><code>magnitude = 15 * (max + min / 2) / 16 </code></pre> <p>and of course we can use shifts for the divides:</p> <pre><code>magnitude = (15 * (max + (min &gt;&gt; 1))) &gt;&gt; 4 </code></pre> <p>Error is +/- 5% over a quadrant.</p> <p>More information on this technique here: <a href="http://www.dspguru.com/dsp/tricks/magnitude-estimator" rel="nofollow">http://www.dspguru.com/dsp/tricks/magnitude-estimator</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload