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

Click For Summary
SUMMARY

This discussion focuses on generating a sine wave using integer arithmetic within a grid defined by NxN, where N is a power of two. The user references the waveguide-form oscillator from Pete Symons' book 'Digital Wave Generation' and presents a set of difference equations derived from the cosine function. The equations are designed to work with integer values, but the user encounters issues with the output exceeding expected ranges. The conversation highlights the Digital Differential Analyzer (DDA) as a relevant algorithm, noting its capability to function with both floating-point and integer arithmetic.

PREREQUISITES
  • Understanding of difference equations and their applications in signal processing.
  • Familiarity with the Digital Differential Analyzer (DDA) algorithm.
  • Knowledge of trigonometric functions, specifically sine and cosine.
  • Basic principles of digital signal generation and grid-based representations.
NEXT STEPS
  • Research the implementation of the Digital Differential Analyzer (DDA) using integer arithmetic.
  • Explore the mathematical foundations of difference equations in signal processing.
  • Study the Bresenham algorithm for circle drawing and its integer-based approach.
  • Investigate the implications of using integer versus floating-point arithmetic in digital signal generation.
USEFUL FOR

Engineers, mathematicians, and developers involved in digital signal processing, particularly those interested in generating waveforms using integer arithmetic and exploring algorithms like DDA.

intervoxel
Messages
192
Reaction score
1
TL;DR
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 k=cos(\omega T).

This formula works perfectly when using floating point numbers.

In the case of the NxN grid, we have \omega T=2\pi/N, and the amplitude is N/2.
For N>>1, we have k=N/2-1.
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 N=128 and y_1=N/2, y_2=0, we get for the first iteration the values \hat{y_1}=63 and \hat{y_2}=127 (it was expected a low value!). That is, y_2>N/2.

What went wrong? Thank you for any help.
 
Mathematics news on Phys.org
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.
 
Thank you for answering. DDA uses floats not pure integers.
 
mfb said:
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:
lim_{N\to\infty} \frac{N}{2}sin(2\pi/N)=\pi
sin^2\theta+cos^2\theta=1
\overline{k}=\sqrt{\frac{N^2}{4}-\pi^2}
for N>>1 we have
\sqrt{\frac{N^2}{4}-\pi^2}\approx \frac{N}{2}-1
 
intervoxel said:
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.
 
  • Like
Likes intervoxel
You are right, a DDA variation called Bresenheim algorithm for circles works with integers. Thank you.
 

Similar threads

Replies
1
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 36 ·
2
Replies
36
Views
8K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
1K