Forum Discussion

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

sine wave generation

can anyone please give me idea about how to generate sine wave in vhdl.....please

10 Replies

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

    I think many people will recommend a look up table approach, while others will recommend the Cordic based method. My recommendation is to implement a cordic in rotation mode, and simply feed it a constant X value, and set Y to zero, and make the angle correspond to a frequency that you wish the fundamental output to be. Then you will get both sine and cosine, with no lookup table, and small resource usage. James

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

    hi james, first thank you very much for giving reply. actually i already tried with cordic rotation method,,,but i didn't get it may be i think i'm not going with correct path in coding, so that i'm looking towards lookup table method.., i'm very glad to you if you provide me some info on cordic algorithm.

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

    lookup goertlez's algorithm.

    Basically:

    sin(a+b) = sin(a)cos(b) - cos(a)sin(b)

    sin(a-b) = sin(a)cos(b) + cos(a)sin(b)

    so:

    sin(a+b) = 2sin(a)cos(b) - sin(a-b)

    and you can generate the terms in sequence with a multiply and an add
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi guys

    I'm working on an audio synthesizer.

    I used a "case" using exel (for calculate function).

    you can use matlab too.

    vhdl code exemple:

    case nTHETA is --Table (wave)

    WHEN 1 => SINE_TMP := 32799 ;

    WHEN 2 => SINE_TMP := 32832 ;

    WHEN 3 => SINE_TMP := 32865 ;

    WHEN 4 => SINE_TMP := 32898 ;

    ...

    WHEN 6280 => SINE_TMP := 32662 ;

    WHEN 6281 => SINE_TMP := 32695 ;

    WHEN 6282 => SINE_TMP := 32728 ;

    WHEN 6283 => SINE_TMP := 32760 ;

    WHEN others => SINE_TMP := 0 ;

    end case;
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    instead of a laborious case statement, why not use a constant that is set up via a function using the cos/sin function from the math_real library?

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

    --- Quote Start ---

    instead of a laborious case statement, why not use a constant that is set up via a function using the cos/sin function from the math_real library?

    --- Quote End ---

    simply because they knew that library

    thank you!

    i will check now
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    thank you very much friends for your great suggestions and for good discussion.....