Approximation of the square root of the sum of two squares on the microcontroller

I am working on implementing the FFT algorithm in an assembly on an 8-bit microcontroller (HCS08) for fun. Once the algorithm is complete, I will have an array of 8-bit real / imaginary pairs, and I want to find the value of each of these values. That is, if x is complex, I want to find

|x| = sqrt(Re{x}^2 + Im{x}^2)  

Now I have access to the 16-bit register and 8-bit register. I thought about just squaring them, adding them and taking the square root of the result, but this creates a problem: the maximum possible value of the sum of the squares of two 8-bit numbers is ~ 130 thousand, which is more than the maximum value may contain 16-bit register (65.5 thousand).

I came up with a routine that calculates the integer square root of a 16-bit number, which seems to work fine, but obviously I'm not guaranteed to work with values ​​that fit in 16 bits. Now I think that there is an algorithm that will approximate what I need directly, but I can not find anything. Any ideas are greatly appreciated.

To summarize: Let's say I have a vector with two 8-bit components, and I want to find the length of the vector. How can I approximate this without calculating the squares and square roots?

Thank!

+5
source share
6 answers

65535, 4 ( 2 ), 2. , , , 8 .

+3

-, . , ( ) :

Mag ~= Alpha * max(|I|, |Q|) + Beta * min(|I|, |Q|)

Alpha Beta. , .., , ALU.

+6

, x :

x = r[cos(w) + i sin(w)]

w = arctan(Im(x)/Re(x)),

|x| = r = Re(x)/cos(w)

, , , ( , : -/)

0

, ,

|x| ~ max(|Re{x}|,|Im{x}|) + min(|Re{x}|,|Im{x})/2;

| x | - 0 12%.

0

, sqrt. :

magnitude = sqrt(re*re+im*im); // calculate magnitude of complex FFT output value
magnitude_dB = 20*log10(magnitude); // convert magnitude to dB

:

magnitude_sq = re*re+im*im; // calculate squared magnitude of complex FFT output value
magnitude_dB = 10*log10(magnitude_sq);  // convert squared magnitude to dB
0

All Articles