Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

How can i use CORDIC ?

Hello i am trying to use the cordic core { http://opencores.org/project,cordic }

with no sucess.

Say i have a complex number of 4 + 5i.

I have inserted 1000 as the Xi input and 1001 as the Yi input

But the r2p_corproc is returning me wrong R and A values. It should be

r = 6.4031 angle = 0.8961 {matlab}

but instead i get

r= 103

a= 146811

My test bench is :

SIGNAL real_i : signed(15 downto 0) := "00000000"& "00000100" ;
SIGNAL imag_i : signed(15 downto 0) := "00000000"& "00000101" ;
SIGNAL ena_r_i : std_logic := '1';
SIGNAL rst_negado : std_logic := '1';
SIGNAL result_ang_o : unsigned(19 downto 0);
SIGNAL result_mag_o :  signed(19 downto 0) ;
SIGNAL test_clk: std_logic := '0';
-- component instatiation
component rl131 is
	port(
		clk_i    : in std_logic;
        rst_i_n  : in std_logic;
		ena_i    : in std_logic;
		Real_i	: in signed(15 downto 0);
		Imag_i   : in signed(15 downto 0);
		Rout_o	: out unsigned(19 downto 0);
		Aout_o	: out signed(19 downto 0)
	);
	end component;
BEGIN
 dut : rl131
	port map(
	 clk_i => test_clk,
	 ena_i => ena_r_i,
	 rst_i_n => rst_negado,
	 Real_i => real_i, 
	 Imag_i => imag_i, 
	 Rout_o => result_ang_o, 
	 Aout_o => result_mag_o);
  
test_clk <= not test_clk after clkperiod/2;

15 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks nails. true, 7 out of 16 is 7/16 = .4375

    The angle seems wrong completely
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    lol, aparado. you posted while I was trying to figure out the angle portion....I lied....I tried to analyze it. :)

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    >> magnitude of 103 (67 in hex) means 6.7

    Additional info: 6.7 in fixed decimal (16.4) representation is the real value of 6.4375. In binary representation 103 = 1100111 or 0000000000000110.0111 in fixed decimal (16.4).

    Taking the last 4 digits as the fractional part gives:

    0 * (0.5) + 1 * (0.25) + 1 * (0.125) + 1 * (0.0625) = .4375, so you have a fixed point representation of 6.4375 which is slightly over matlab's result of 6.4031. A 6.6 fixed decimal (16.4) value is a real value of 6.375 which is slightly under, but closer to the actual result from matlab.

    I think the cordic routine isn't expected to get the last fractional digit perfect, so it appears that may be working for your r value.

    I haven't tried to analyze the angle portion, nor do I know how at this point in time.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi kas thanks for the help but it is 6.4375 and not 6.7 :P

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    the outputs are 20 bits, 16 bits integer and 4 bits fraction so:

    magnitude of 103 (67 in hex) means 6.7

    and Angle of 146811 (23d7b) i.e 23d7.b degrees = 9175 and this wraps 25 times to 175 degrees.

    your figure of .8961 is in rads I believe so becomes .8961 * 180/pi = 51 degrees.

    So at least magnitude seems working.

    The angle may not actually have been meant to be wrapped up, it then does not need 16 bits for integer part (range is 0 to 360) i.e. only 9 bits may represent it and the rest 11 bits as fraction hence A = 146811/2^11 = 72 degrees which I think is a bit better than 175 !!!

    The documentation is poor or the code does not work I am afraid.