Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Question about the CORDIC algorithm multiplication

Status
Not open for further replies.

dd1029us

Newbie level 1
Newbie level 1
Joined
May 1, 2014
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
16
Hello all. I am working on a project involving an FPGA board to perform some basic calculations using the CORDIC algorithm, written in VHDL. CORDIC allows you to calculate certain functions using just add, subtract and bit-shift. I know how to use CORDIC to find sine and cosine. However, I'm trying to implement multiplication and don't seem to be getting the right results. I'll just lay out the basic iterative CORDIC algorithm as follows:

x(k+1) = x(k) - m*d(k)*y(k)*2^-k
y(k+1) = y(k) + d(k)*x(k)*2^-k
z(k+1) = z(k) - d(k)*e(k)

(d(k) = +1 or -1 depending on y(k) or z(k))

m 0,+1,-1 (0 for linear operations such as multiplication)
e(k) is a pre-stored constant.

For multiplication, we have the following procedure:

y(n+1) = x(0)*z(0),
e(k) = 2^-k,
d(k) = sign(z(k)),
y(0) = 0

Basically, you keep iterating until you get an accurate answer. The following is a Matlab script to test this procedure:

Code:
clear;

% CORDIC Multiplication Example

n=20; % Number of Iterations

x0=4;
y0=0;
z0=5;
d0=sign(z0);

x=x0;
y=y0+d0*x0*(2^(-0));
z=z0-d0*(2^(-0));

x0=x;
y0=y;
z0=z;

if z0>=0
   dk=1;
else
   dk=-1;
end;

for k=1:n-1
    x=x0;
    y=y0+dk*x0*(2^(-k));
    z=z0-dk*(2^(-k));
    if z>=0
        dk=1;
    else
        dk=-1;
    end;
    x0=x;
    y0=y;
    z0=z;
end;

display(x);
display(y);
display(z);

Matlab gives me the following output:
x =
4
y =
8.0000
z =
3.0000

All it seems to do is double the value of x, giving me 8 instead of 20. There must be some factor that needs to be multiplied; I'm not sure. I saw another thread similar to mine, but nobody gave a sufficient answer. I've looked all over the internet, and am unable to find any answer. There seems to be a small range within which x and z can exist to Any help would be appreciated. Thank you.
 

Have you found a solution yet? I don't have time today, but may be able to have a look at your code over the weekend.

Have you tried this: [link] and the references therein?
 
Last edited:

I found some code for a CORDIC multiplication here: [link]. I have converted it to Matlab and put some bit-shifting in to control the input value range.

It seems to work fine, so hopefully this will be of some use to you.
Code:
close all; clear all; clc;

% CORDIC Multiplication Example

% Numbers to multiply
x = 4
y = 5

% Number of bits
B = 16;

% Right-shift numbers so they lie between -1 and 1
shift_bits = 0;
while abs(x) > 1
    x = x/2;
    shift_bits = shift_bits + 1;
end
while abs(y) > 1
    y = y/2;
    shift_bits = shift_bits + 1;
end

% CORDIC multiplication
z = 0;
for i = 1:B
    if (x > 0)
        x = x - 2^(-i);
        z = z + y*2^(-i);
    else  
        x = x + 2^(-i);
        z = z - y*2^(-i);
    end
end

% Left-shift to undo the right-shifting
for i = 1:shift_bits
    z = z*2;
end

% Print result
disp(['z = ', num2str(z)]);
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top