MathsLearner
New member
- Joined
- Aug 13, 2017
- Messages
- 27
I am trying to write an algorithm for generating a sine wave using look up table (then i have to write as a program) the max frequency of the sine wave is now [math]1KHz[/math] as a first attempt. Please advise if my algorithm is correct.
Step1: I want to divide the sine wave of period [math]360deg[/math] into [math]1024[/math] samples (I could have chosen another value, but i saw lot of people assuming this value). Hence each step will be [math]\frac {360} {1024} = 0.35deg[/math] and store in an array say [math] sinarray[1024] [/math].
Step2: I will be sampling these at every [math]50uS [/math]. So each degree value will be taken at [math]50uS [/math].
Step3: Let us say i want to now generate a 500Hz signal. It means 2ms to complete 1cycle. To complete [math] 2ms [/math] using [math]50uS [/math], [math]40 [/math] values to be output [math] \frac {(2ms)} {(50uS)} [/math]. So each value corresponds to an angle of [math]\frac {360} {40} = 9Deg [/math]Step4: The index in the [math] sinarray[] [/math]is [math] \frac 9 {0.35} = 25.7 =>26 [/math], so every [math]26th[/math] value to be taken so [math]0,26,52..[/math] etc and repeat.
Step5: If i want to generate a [math]250Hz [/math] signal, then every [math]13th[/math] value to be taken.
Step1: I want to divide the sine wave of period [math]360deg[/math] into [math]1024[/math] samples (I could have chosen another value, but i saw lot of people assuming this value). Hence each step will be [math]\frac {360} {1024} = 0.35deg[/math] and store in an array say [math] sinarray[1024] [/math].
Step2: I will be sampling these at every [math]50uS [/math]. So each degree value will be taken at [math]50uS [/math].
Step3: Let us say i want to now generate a 500Hz signal. It means 2ms to complete 1cycle. To complete [math] 2ms [/math] using [math]50uS [/math], [math]40 [/math] values to be output [math] \frac {(2ms)} {(50uS)} [/math]. So each value corresponds to an angle of [math]\frac {360} {40} = 9Deg [/math]Step4: The index in the [math] sinarray[] [/math]is [math] \frac 9 {0.35} = 25.7 =>26 [/math], so every [math]26th[/math] value to be taken so [math]0,26,52..[/math] etc and repeat.
Step5: If i want to generate a [math]250Hz [/math] signal, then every [math]13th[/math] value to be taken.