Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > help needed in sine generation of vhdl code.

Reply
Thread Tools

help needed in sine generation of vhdl code.

 
 
senthil
Guest
Posts: n/a
 
      02-12-2004
hello friends,

for the fft and ifft part of dsp, w.r to twiddle factor, we need the
cosine and sine terms. for that i do my sine code w.r to sine series
formulae.

sin(x) = x - x3/3(fact) + x5/5(fact) _ ...

i took only 3 terms.

and my coding was given below


term : =1
sum := 1

for n in 1 to 3 loop

term := (-term)*input **2/real((2n*(2n+1)));
sum := sum + term;
end loop

output <= input * sum;

i found one problem , ie., if i give input = 3.534, i got an output =
-0.596
that is wrong answer.
but actual value from the calculator, is sin(3.534) = -0.3818..

what is the problem behind that.
give some guidance.

tool : modelsim 5.5 SE vhdl.
 
Reply With Quote
 
 
 
 
David Brown
Guest
Posts: n/a
 
      02-12-2004

"senthil" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> hello friends,
>
> for the fft and ifft part of dsp, w.r to twiddle factor, we need the
> cosine and sine terms. for that i do my sine code w.r to sine series
> formulae.
>
> sin(x) = x - x3/3(fact) + x5/5(fact) _ ...
>
> i took only 3 terms.
>


That formula for calculating sin is fine for doing theoretical maths, but it
is not good as a calculation method, since it converges very slowly. In
particular, it gets worse the further you go from 0 - to converge sin(3.534)
to four decimal places (to the correct value of -0.3824, not the one you
gave below) takes 8 terms.

If you move your input closer to 0, such as by using sin x == sin (pi - x),
and try calculating sin(-0.3924), you get four decimal places after 3 terms.

Where you go from here depends on what you actually want to do with the
sines - if you are only looking for simulation and don't care about speed,
then just pick a big enough number of terms. If you need high accuracy and
can use floating point, then look for tchebychev (sp?) polynomials. Typical
synthesisable solutions use lookup tables.


> and my coding was given below
>
>
> term : =1
> sum := 1
>
> for n in 1 to 3 loop
>
> term := (-term)*input **2/real((2n*(2n+1)));
> sum := sum + term;
> end loop
>
> output <= input * sum;
>
> i found one problem , ie., if i give input = 3.534, i got an output =
> -0.596
> that is wrong answer.
> but actual value from the calculator, is sin(3.534) = -0.3818..
>
> what is the problem behind that.
> give some guidance.
>
> tool : modelsim 5.5 SE vhdl.



 
Reply With Quote
 
 
 
 
Egbert Molenkamp
Guest
Posts: n/a
 
      02-12-2004
Maybe you can use the IEEE package math_real.
This package contains often used constants (math_e, math_pi, ..) and
functions (sqrt, exp, log, log2, sin, arccos, sinh, ..).
(not synthesisable)

ModelSim has this package.

Here an example

library ieee;
use ieee.std_logic_1164.all;
use ieee.math_real.all;
entity math is
end math;

architecture demo of math is
signal s, c, this_should_be_one : real := 0.0;
begin
stimulirocess
constant delta : real := 10.0E-4;
variable x : real := 0.0;
begin
x:=0.0;
while x < 4.0*MATH_PI loop
s <= sin(x);
c <= cos(x);
wait for 1 ns;
x:=x+delta;
end loop;
report "finished";
wait;
end process;

this_should_be_one <= s**2 + c**2;
end demo;


And if you use the macro file beneath you get a nice waveform.

vsim math
onerror {resume}
quietly WaveActivateNextPane {} 0
add wave -noupdate -format Analog-Step -offset -1.0 -scale 40.0 /math/s
add wave -noupdate -format Analog-Step -offset -0.58 -scale 40.0 /math/c
add wave -noupdate -format Analog-Step -offset -0.14 -scale 40.0
/math/this_should_be_one
run -all

Egbert Molenkamp

"senthil" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> hello friends,
>
> for the fft and ifft part of dsp, w.r to twiddle factor, we need the
> cosine and sine terms. for that i do my sine code w.r to sine series
> formulae.
>
> sin(x) = x - x3/3(fact) + x5/5(fact) _ ...
>
> i took only 3 terms.
>
> and my coding was given below
>
>
> term : =1
> sum := 1
>
> for n in 1 to 3 loop
>
> term := (-term)*input **2/real((2n*(2n+1)));
> sum := sum + term;
> end loop
>
> output <= input * sum;
>
> i found one problem , ie., if i give input = 3.534, i got an output =
> -0.596
> that is wrong answer.
> but actual value from the calculator, is sin(3.534) = -0.3818..
>
> what is the problem behind that.
> give some guidance.
>
> tool : modelsim 5.5 SE vhdl.



 
Reply With Quote
 
vipinlal vipinlal is offline
Member
Join Date: Feb 2010
Posts: 39
 
      03-17-2010
you can find a sine wave generator program here..
vhdlguru.blogspot.com/2010/03/simple-sine-wave-generator-in-vhdl.html
hope this solves the problem.
 
Reply With Quote
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 348
 
      03-17-2010
I believe your looking for code which should be synthesized for hardware.
Your able to use Excel as well.
jjmk.dk/MMMI/Lessons/11_Curveforms/SinusVer2/sinusgenerator_version_2.htm
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sine and cosine wave generation FPGA VHDL 8 01-14-2008 09:11 PM
VHDL-2002 vs VHDL-93 vs VHDL-87? afd VHDL 1 03-23-2007 09:33 AM
sine wave generation mcenley@gmail.com C++ 8 04-12-2006 03:54 PM
mixing sampled sine waves viswanath VHDL 1 05-12-2004 06:02 AM
HTML Generation (Next Generation CGI) John W. Long Ruby 4 11-24-2003 04:24 AM



Advertisments