FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > FPGA

FPGA comp.arch.fpga newsgroup (usenet)

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-11-2006, 09:32 AM
Marko S
Guest
 
Posts: n/a
Default sqrt(a^2 + b^2) in synthesizable VHDL?

How do i calculate sqrt(a^2 + b^2) in synthesizable VHDL?

The signals a and b are 32 bit signed fix point numbers (std_logic_vector
(31 downto 0)).


Reply With Quote
  #2 (permalink)  
Old 05-11-2006, 10:18 AM
Michael Schöberl
Guest
 
Posts: n/a
Default Re: sqrt(a^2 + b^2) in synthesizable VHDL?

Marko S schrieb:
> How do i calculate sqrt(a^2 + b^2) in synthesizable VHDL?
> The signals a and b are 32 bit signed fix point numbers (std_logic_vector
> (31 downto 0)).


how accurate? how fast? latency?

a table with 64 Bits input, 32 Bits output will not fit into an FPGA
(but if you need the result with low latency, you might store some
precomputed data in an external ram)


or you could do something like max(a, b) + 0.5*min(a,b) ... and add a
newton raphson stage?


just for the sqrt(x) I once worked an idea to take len=ceil(log_2(x)) by
counting the length of x (leading 0s) ...
then you shift x>>(len/2) or something (+1?) ... this worked as a good
approximation and I added only one or two stages of a newton-raphson

The second approach was better in the first stage but uses more
cycles/ressources ... I'm not sure if the ressources balance on an FPGA
I did it for a TI-DSP - look at the thread "sqrt on C6414 DSP" on comp.dsp


bye,
Michael
Reply With Quote
  #3 (permalink)  
Old 05-11-2006, 10:38 AM
Ad
Guest
 
Posts: n/a
Default Re: sqrt(a^2 + b^2) in synthesizable VHDL?

Marko

a cordic algorithim in vectroing mode will calcualtes sqrt(a^2 - b^2)
which i am sure you can manipulate to get sqrt(a^2+b^2) by using signed
numbers and making b the negative (-6 as opposed to 6)

have a look at Ray Andrakas, survey of CORDIC algorithms for FPGA based
computers for infor on cordics, opencore.org also have a the vhdl for a
synthesisable cordic.

I ve just finished writing a excel function that performs the function
of a cordic if you want the vb for that then let me know and you can
have it test out your application before coding it.

good luck

Adam

Reply With Quote
  #4 (permalink)  
Old 05-11-2006, 10:41 AM
Kolja Sulimma
Guest
 
Posts: n/a
Default Re: sqrt(a^2 + b^2) in synthesizable VHDL?

Marko S schrieb:
> How do i calculate sqrt(a^2 + b^2) in synthesizable VHDL?


If you really need the results in random order, use cordic.
But often you can rearrange your computations to get away without the
root. That is your application?

Do you want to draw circles?

Kolja Sulimma
Reply With Quote
  #5 (permalink)  
Old 05-11-2006, 10:52 AM
Ad
Guest
 
Posts: n/a
Default Re: sqrt(a^2 + b^2) in synthesizable VHDL?

corerction the sqrt(a^2 - b^2) is for gven during the hyperbolic
extension, a normal cordic algorithim will provide sqrt(a^2 + b^2)

sorry about that

Ad

Reply With Quote
  #6 (permalink)  
Old 05-11-2006, 10:56 AM
Symon
Guest
 
Posts: n/a
Default Re: sqrt(a^2 + b^2) in synthesizable VHDL?

"Michael Schöberl" <[email protected]> wrote in message
news:4462f354$[email protected]..
> Marko S schrieb:
>> How do i calculate sqrt(a^2 + b^2) in synthesizable VHDL?
>> The signals a and b are 32 bit signed fix point numbers (std_logic_vector
>> (31 downto 0)).

>
> how accurate? how fast? latency?
>
> just for the sqrt(x) I once worked an idea to take len=ceil(log_2(x)) by
> counting the length of x (leading 0s) ...
> then you shift x>>(len/2) or something (+1?) ... this worked as a good
> approximation and I added only one or two stages of a newton-raphson
>

Hi Marko,
For square root, you could use modified Dijkstra's square root.

http://lib.tkk.fi/Diss/2005/isbn9512275279/article3.pdf

One clock per output bit. No multipliers.

HTH, Syms.


Reply With Quote
  #7 (permalink)  
Old 05-11-2006, 11:58 AM
Marko S
Guest
 
Posts: n/a
Default Re: sqrt(a^2 + b^2) in synthesizable VHDL?

Thank you all. I will have a look at "Dijkstra's square root". I have 2000
clock cycles at 40 Mhz to complete the calculation (It should be enough). It
is used for calculating the AM envelop after demodulating the signal with a
coherent detector



You can se the principle of the detector at
http://www.cycom.co.uk/art1.html.





"Symon" <[email protected]> wrote in message
news:4462fbb4$0$15793$[email protected]..
> "Michael Schöberl" <[email protected]> wrote in message
> news:4462f354$[email protected]..
>> Marko S schrieb:
>>> How do i calculate sqrt(a^2 + b^2) in synthesizable VHDL?
>>> The signals a and b are 32 bit signed fix point numbers
>>> (std_logic_vector (31 downto 0)).

>>
>> how accurate? how fast? latency?
>>
>> just for the sqrt(x) I once worked an idea to take len=ceil(log_2(x)) by
>> counting the length of x (leading 0s) ...
>> then you shift x>>(len/2) or something (+1?) ... this worked as a good
>> approximation and I added only one or two stages of a newton-raphson
>>

> Hi Marko,
> For square root, you could use modified Dijkstra's square root.
>
> http://lib.tkk.fi/Diss/2005/isbn9512275279/article3.pdf
>
> One clock per output bit. No multipliers.
>
> HTH, Syms.
>



Reply With Quote
  #8 (permalink)  
Old 05-11-2006, 07:27 PM
Ray Andraka
Guest
 
Posts: n/a
Default Re: sqrt(a^2 + b^2) in synthesizable VHDL?

Marko S wrote:
> Thank you all. I will have a look at "Dijkstra's square root". I have 2000
> clock cycles at 40 Mhz to complete the calculation (It should be enough). It
> is used for calculating the AM envelop after demodulating the signal with a
> coherent detector
>
>
>
> You can se the principle of the detector at
> http://www.cycom.co.uk/art1.html.
>
>
>
>
>
> "Symon" <[email protected]> wrote in message
> news:4462fbb4$0$15793$[email protected]..
>
>>"Michael Schöberl" <[email protected]> wrote in message
>>news:4462f354$[email protected]..
>>
>>>Marko S schrieb:
>>>
>>>>How do i calculate sqrt(a^2 + b^2) in synthesizable VHDL?
>>>>The signals a and b are 32 bit signed fix point numbers
>>>>(std_logic_vector (31 downto 0)).
>>>
>>>how accurate? how fast? latency?
>>>
>>>just for the sqrt(x) I once worked an idea to take len=ceil(log_2(x)) by
>>>counting the length of x (leading 0s) ...
>>>then you shift x>>(len/2) or something (+1?) ... this worked as a good
>>>approximation and I added only one or two stages of a newton-raphson
>>>

>>
>>Hi Marko,
>>For square root, you could use modified Dijkstra's square root.
>>
>>http://lib.tkk.fi/Diss/2005/isbn9512275279/article3.pdf
>>
>>One clock per output bit. No multipliers.
>>
>>HTH, Syms.
>>

>
>
>


You aren't really looking for square root, you are looking for vector
magnitude. Vector magnitude can be computed without computing the
square root. For arbitrary precision, you can use the cordic algorithm
in vectoring mode. It basically rotates the vector to the I axis using
a series of progressively smaller fixed angle rotations selected so that
each elemental rotation is done with a shift and add operation. After
rotating the vector the I axis, the magnitude is read directly from the
non-zero (I component) of the rotated vector. If you don't need a lot
of precision, there are table methods and linear approximations (the
most famous is "larger plus half smaller" that will often get you a good
enough answer with less computation. Either way, computing magnitude
using a square root is going about it the hard way (hardware-wise
anyway). For 32 bit arguments, CORDIC is going to be your best bet.
Reply With Quote
  #9 (permalink)  
Old 05-11-2006, 11:03 PM
[email protected]
Guest
 
Posts: n/a
Default Re: sqrt(a^2 + b^2) in synthesizable VHDL?

If you are targetting programmable hardware (which you most possible
are), you can get IP cores to work for you. Check out opencores.org or
Xilinx or Altera websites to find cores that provide functions you need.

Reply With Quote
  #10 (permalink)  
Old 05-12-2006, 04:10 AM
jtw
Guest
 
Posts: n/a
Default Re: sqrt(a^2 + b^2) in synthesizable VHDL?

Do you need the square root, or can you work with just the "sum of the
squares" (perhaps scaled)? If this is used for thresholding (amplitude
comparison), then the less-than/equal/greater-than relationship still holds.

JTW

"Marko S" <[email protected]> wrote in message
news:44630af8$0$15782$[email protected]..
> Thank you all. I will have a look at "Dijkstra's square root". I have 2000
> clock cycles at 40 Mhz to complete the calculation (It should be enough).
> It is used for calculating the AM envelop after demodulating the signal
> with a coherent detector
>
>
>
> You can se the principle of the detector at
> http://www.cycom.co.uk/art1.html.
>
>
>
>
>
> "Symon" <[email protected]> wrote in message
> news:4462fbb4$0$15793$[email protected]..
>> "Michael Schöberl" <[email protected]> wrote in message
>> news:4462f354$[email protected]..
>>> Marko S schrieb:
>>>> How do i calculate sqrt(a^2 + b^2) in synthesizable VHDL?
>>>> The signals a and b are 32 bit signed fix point numbers
>>>> (std_logic_vector (31 downto 0)).
>>>
>>> how accurate? how fast? latency?
>>>
>>> just for the sqrt(x) I once worked an idea to take len=ceil(log_2(x)) by
>>> counting the length of x (leading 0s) ...
>>> then you shift x>>(len/2) or something (+1?) ... this worked as a good
>>> approximation and I added only one or two stages of a newton-raphson
>>>

>> Hi Marko,
>> For square root, you could use modified Dijkstra's square root.
>>
>> http://lib.tkk.fi/Diss/2005/isbn9512275279/article3.pdf
>>
>> One clock per output bit. No multipliers.
>>
>> HTH, Syms.
>>

>
>



Reply With Quote
  #11 (permalink)  
Old 05-12-2006, 12:59 PM
Trainee
Guest
 
Posts: n/a
Default Re: sqrt(a^2 + b^2) in synthesizable VHDL?

Thank you



Now I have read the CORDIC FAQ at dspGuru. I read how to calculate the
magnitude of a complex number with the CORDIC. And I have tried it in Excel.
So now I'm going to implement it in VHDL.



I have heard about CORDIC before but newer sat down to read about it.



Thank you all for your help on this.





"Ray Andraka" <[email protected]> wrote in message
news:KuK8g.18376$ZW3.2280@dukeread04...
> Marko S wrote:
>> Thank you all. I will have a look at "Dijkstra's square root". I have
>> 2000 clock cycles at 40 Mhz to complete the calculation (It should be
>> enough). It is used for calculating the AM envelop after demodulating the
>> signal with a coherent detector
>>
>>
>>
>> You can se the principle of the detector at
>> http://www.cycom.co.uk/art1.html.
>>
>>
>>
>>
>>
>> "Symon" <[email protected]> wrote in message
>> news:4462fbb4$0$15793$[email protected]..
>>
>>>"Michael Schöberl" <[email protected]> wrote in message
>>>news:4462f354$[email protected]..
>>>
>>>>Marko S schrieb:
>>>>
>>>>>How do i calculate sqrt(a^2 + b^2) in synthesizable VHDL?
>>>>>The signals a and b are 32 bit signed fix point numbers
>>>>>(std_logic_vector (31 downto 0)).
>>>>
>>>>how accurate? how fast? latency?
>>>>
>>>>just for the sqrt(x) I once worked an idea to take len=ceil(log_2(x)) by
>>>>counting the length of x (leading 0s) ...
>>>>then you shift x>>(len/2) or something (+1?) ... this worked as a good
>>>>approximation and I added only one or two stages of a newton-raphson
>>>>
>>>
>>>Hi Marko,
>>>For square root, you could use modified Dijkstra's square root.
>>>
>>>http://lib.tkk.fi/Diss/2005/isbn9512275279/article3.pdf
>>>
>>>One clock per output bit. No multipliers.
>>>
>>>HTH, Syms.
>>>

>>
>>
>>

>
> You aren't really looking for square root, you are looking for vector
> magnitude. Vector magnitude can be computed without computing the square
> root. For arbitrary precision, you can use the cordic algorithm in
> vectoring mode. It basically rotates the vector to the I axis using a
> series of progressively smaller fixed angle rotations selected so that
> each elemental rotation is done with a shift and add operation. After
> rotating the vector the I axis, the magnitude is read directly from the
> non-zero (I component) of the rotated vector. If you don't need a lot of
> precision, there are table methods and linear approximations (the most
> famous is "larger plus half smaller" that will often get you a good enough
> answer with less computation. Either way, computing magnitude using a
> square root is going about it the hard way (hardware-wise anyway). For 32
> bit arguments, CORDIC is going to be your best bet.



Reply With Quote
  #12 (permalink)  
Old 05-12-2006, 06:57 PM
Slurp
Guest
 
Posts: n/a
Default Re: sqrt(a^2 + b^2) in synthesizable VHDL?


<[email protected]> wrote in message
news:[email protected] ups.com...
> If you are targetting programmable hardware (which you most possible
> are), you can get IP cores to work for you. Check out opencores.org or
> Xilinx or Altera websites to find cores that provide functions you need.
>


The Square root function is available as a free megafunction in Altera
Quartus. I have just used it as part of my new 32 bit embedded processor
design in a Stratix part.

A 32 bit square root with a 4 clock pipeline runs in excess of 40MHz in a C7
part.


Slurp


Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is PLI synthesizable? Verictor Verilog 5 03-24-2007 03:15 PM
How do I scale a 9-b signed 2's complement data by 17/sqrt(21)? Mr. Ken Verilog 0 05-31-2006 03:05 AM
synthesizable vhdl coding style sam FPGA 2 02-19-2005 02:38 AM
VHDL simple question: is 2-D array synthesizable Jimmy FPGA 6 05-26-2004 03:31 PM


All times are GMT +1. The time now is 02:33 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved