# sqt function required for rms calculation

Status
Not open for further replies.

#### habbas33

##### Newbie level 5
i want to calculate rms values of some signals.

xrms = sqrt{ 1/n*( x_1^2 + x_2^2 + ...... + x_n^2 ) }.

but the problem is sqrt operation. i have used cordac but it does not gives precise values u can either give integers or fractions. I have also tried sqrt function from fixed_alg_ug pkg but its not synthesizable because it depends on real_math pkg.
i need a sqrt code which can give me precise answer for example

when 48 goes to => sqrt => gives 6.928 => not 7

#### TrickyDicky

fixed point will be precise to the nearest 2^-N, where N is the number of fraction bits. I guess with cordic you didnt give enough fraction bits.
Have you also considered a look up table (it uses less resources and has smaller latency than cordic.)

#### habbas33

##### Newbie level 5
fixed point will be precise to the nearest 2^-N, where N is the number of fraction bits. I guess with cordic you didnt give enough fraction bits.
Have you also considered a look up table (it uses less resources and has smaller latency than cordic.)

to get result in fraction, cordic can only take 1 bit integer...

can u please explain the how can i use look up table method because i dont have known values of inputs and ouputs

#### axcdd

##### Full Member level 3
Code:
to get result in fraction, cordic can only take 1 bit integer...

can you change your cordic 'vendor' ?
Richard Herveille cordic core is 16bit in /20 bit out length in standard.

#### TrickyDicky

A look up table is just a ROM. The input address is the X value, the output is the squaroot answer. The ROM values need to be pre-calculated (this can easily be done with something like matlab and can even be generated in VHDL).

#### FvM

##### Super Moderator
Staff member
Most FPGA vendors have IP (Megafunction, core generator, ...) for integer squareroot. It can be applied for fixed point calculations by applying suitable scaling.

The first point to write synthesizable code for operations like this is to design the involved number formats.

Status
Not open for further replies.