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.

Sin & Cos algorithm

Status
Not open for further replies.

yasser_shoukry

Full Member level 4
Joined
May 31, 2006
Messages
233
Helped
25
Reputation
54
Reaction score
5
Trophy points
1,298
Location
Cairo - Egypt
Activity points
2,749
cos algorithm

Does any body here know an efficient algorithm for calculating Sin & Cos math operations.

Thanks in advance.
 

sin algorithm

you can take a look at cordic algorithms. Here are some helpful links:

**broken link removed**
**broken link removed**
 
sine algorithm

If u want to avoid Cordic then
you can go for table look up method
or
some aproximation equations can be implemented.
 

sin cos algorithm

samuraign said:
If u want to avoid Cordic then
you can go for table look up method
or
some aproximation equations can be implemented.

Hi!
See this... But it`s no my code, I find this some time ago...
Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity sine_cos is

  port (
    clk   : in  std_logic;
    reset : in  std_logic;
    en    : in  std_logic;
    sine  : out std_logic_vector(7 downto 0);
    cos   : out std_logic_vector(7 downto 0));

end sine_cos;
architecture behave_sine_cos of sine_cos is
signal sine_r, cos_r	: std_logic_vector(7 downto 0);
signal si, co					: std_logic_vector(7 downto 0);
begin  -- behave_sine_cos
 si <= sine_r + (cos_r(7) & cos_r(7) & cos_r(7) & cos_r(7 downto 3));
 co  <= cos_r - (si(7) & si(7) & si(7) & si(7 downto 3));

registers: process (clk, reset)
begin  -- process registers
  if reset = '0' then                   -- asynchronous reset (active low)
    sine_r <= "00000000";
    cos_r <= "01111000";
  elsif clk'event and clk = '1' then    -- rising clock edge
    if (en = '1') then
      sine_r <= si;
      cos_r <= co;
    end if;
  end if;
end process registers;

	sine <= si;
	cos <= co;
end behave_sine_cos;

Regards,
Black
 
sine algorithm code

Thanks Black , but i have a question, where is the input for this module? What is the output as in the code it computes the next output from the previous one? does this means that it begins with the sine of 0 degree and then at each clock cycle gets another sine and cosine or what ?

Thanks in advance
 

algorithm sin

Black Jack's code is an oscillator. It's not a sin(θ) or cos(θ) math function.
 

sine_cos

echo47 said:
Black Jack's code is an oscillator. It's not a sin(θ) or cos(θ) math function.

I`m sorry, this really oscillator code.
But you can use simple counter for "grab" value of sin and cos.
 

cosine infinite series algorithm

for calculating sin & cos , you can use "Taylor expansion" , then you can calculate sin & cos with only + , - , * . / , this is the way used in computers .
refer to mathematic books or ask from whom knows it ... to find what it is .
 

algorithm for sinx

Taylor series is an infinite series. So you will have to decide what precision you want and then program it... its a goood one!
 

algorithm cos(x)

sin(x) = x - (x^3)/3! + (x^5)/5! + ... +
(-1)^i*(x^(2*i+1))/(2*i+1)!

cos(x) = 1 + (x^2)/2! - (x^4)/4! + ... +
(-1)^i*(x^(2*i))/(2*i)!

sum up to i = 10 should be enough.

the following are matlab codes:
sin(x):

for i=0:10,
y = y+((-1)^i)*(x^(2*i+1))/factorial(2*i+1);
end

cos(x):

for i=0:10,
y = y + (-1)^i*(x^(2*i))/factorial(2*i);
end
 

algorithm for cos

Taylor's series helps us to find the values of the function sinΘ and cosΘ. This is an infinite series. As the no. of terms considered increases. the precision increases.

After reduction from Taylor's series,
sin(x) is given as

sin(x) = x-x^3/3! + x^5/5! - ......

It'll also be easier to remember it this way.

Sine function is an odd function
and thus the expansion series consists of only odd powers of 'x'.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top