Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tracking square root of moving value

I have a control loop running at high frequency and need to compute a square root each cycle. Typical square root functions work fine but take excessive time. Since the value I'm taking the square root of doesn't change too much on each cycle, I would like to find an iterative square root that will converge and then track the correct result. This way I could do a single iteration at each time step, rather than many.

The problem is that all of the iterative square root methods I've seen will probably fail when the input is changing. In particular it looks like there will be problems when the input goes to zero and then increases again - the methods don't like to start with a guess of zero.

My input range is 0-4.5 and I need a precision of around 0.01 so using an increment/decrement of 0.01 could take far too long - I want it to mostly converge in 10 cycles or less.

FYI I'm using 16/32bit fixed point the input is 16bit q12. It's on a micro-controller so I'm not interested in using 1K for a lookup table. The code is also generated from a simulink model and their table lookup functions are rather full of overhead.

Is there a nice solution to this?

like image 204
phkahler Avatar asked Apr 12 '12 14:04

phkahler


People also ask

How do you use square roots to estimate benchmarks?

Benchmark numbers can be used to state that the square root of 60 is between 6 and 7. The square root of 60, estimated to two decimal places is 7.75. Example: The square root of some numbers (for example the number 44.89) is a rational number that terminates (6.7).

How do you get rid of a square root when rearranging?

To solve an equation with a square root in it, first isolate the square root on one side of the equation. Then square both sides of the equation and continue solving for the variable.


2 Answers

the range 0-4.5 is fairly small. With precision of 0.01, that's only 450 possible calculations. You could compute them all at compile time as constants and just do a look up during runtime.

like image 125
Colin D Avatar answered Sep 22 '22 04:09

Colin D


I would suggest you use a lookup table, if you know in advanced the ranges you are dealing with. Generate an array or hash table (depending on the language you're working in) to the level of precision you need and refer to this when you need your roots.

like image 35
deed02392 Avatar answered Sep 24 '22 04:09

deed02392