A How can you generate a sine wave using integers only?

  • Thread starter intervoxel
  • Start date
190
1
Summary
A recursive generator of a quadrature signal which fits exactly in a NxN grid, where N is a large power of two.
I need to recursively generate a quadrature signal which fits exactly into a grid NxN, where N is a large power of two.
After unsuccessful research, I decided to develop my own solution, starting from the waveguide-form oscillator taken from Pete Symons' book 'Digital wave generation, p. 100'.

\begin{gather}
\begin{bmatrix}\hat{ y_1}\\\hat{y_2}\end{bmatrix}
=
\begin{bmatrix}
k &k-1\\
k+1&k
\end{bmatrix}
\begin{bmatrix} y_1\\y_2\end{bmatrix}
\end{gather}
where [itex]k=cos(\omega T)[/itex].

This formula works perfectly when using floating point numbers.

In the case of the NxN grid, we have [itex]\omega T=2\pi/N[/itex], and the amplitude is [itex]N/2[/itex].
For [itex]N>>1[/itex], we have [itex]k=N/2-1[/itex].
The difference equations then become
\begin{gather}
\hat{ y_1}=\frac{2((N/2-1)y_1 - y_2)}{N}
\end{gather}
and
\begin{gather}
\hat{ y_2}=\frac{2((N-1)y_1 + (N/2-1)y_2))}{N}
\end{gather}
If we initialize [itex]N=128[/itex] and [itex]y_1=N/2[/itex], [itex]y_2=0[/itex], we get for the first iteration the values [itex]\hat{y_1}=63[/itex] and [itex]\hat{y_2}=127[/itex] (it was expected a low value!). That is, [itex]y_2>N/2[/itex].

What went wrong? Thank you for any help.
 
33,236
8,950
I don't know where k=N/2 - 1 comes from, but with k getting larger your numbers will get too large as well. This is true for floating point numbers as well.
 
190
1
Thank you for answering. DDA uses floats not pure integers.
 
190
1
I don't know where k=N/2 - 1 comes from, but with k getting larger your numbers will get too large as well. This is true for floating point numbers as well.
Of course the modified k grows, it is an integer constant.
The rationale for the modified expression for k is:
[tex]lim_{N\to\infty} \frac{N}{2}sin(2\pi/N)=\pi[/tex]
[tex]sin^2\theta+cos^2\theta=1[/tex]
[tex]\overline{k}=\sqrt{\frac{N^2}{4}-\pi^2}[/tex]
for [itex]N>>1[/itex] we have
[tex]\sqrt{\frac{N^2}{4}-\pi^2}\approx \frac{N}{2}-1[/tex]
 

Svein

Science Advisor
Insights Author
1,951
599
Thank you for answering. DDA uses floats not pure integers.
From the Wikipedia article: "The DDA method can be implemented using floating-point or integer arithmetic. " I know that it is so, because a research institute I once worked for implemented a version using only digital logic chips back in the late 60's.
 
190
1
You are right, a DDA variation called Bresenheim algorithm for circles works with integers. Thank you.
 

Want to reply to this thread?

"How can you generate a sine wave using integers only?" You must log in or register to reply here.

Related Threads for: How can you generate a sine wave using integers only?

Replies
19
Views
4K
Replies
31
Views
5K
  • Posted
Replies
7
Views
2K
Replies
6
Views
435
  • Posted
Replies
6
Views
4K
  • Posted
Replies
2
Views
2K

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving

Hot Threads

Top