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

• A
• intervoxel
In summary, the conversation discusses the development of a solution for recursively generating a quadrature signal that fits into a grid NxN, where N is a large power of two. The formula used for this solution involves the cosine of the angular frequency multiplied by time. However, when using pure integers, the modified constant k=N/2-1 may cause the numbers to become too large. The digital differential analyzer (DDA) algorithm is suggested as an alternative, which can be implemented using either floating-point or integer arithmetic.
intervoxel
TL;DR 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 $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.

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.

intervoxel
You are right, a DDA variation called Bresenheim algorithm for circles works with integers. Thank you.

## What is a sine wave?

A sine wave is a mathematical curve that represents a smooth repetitive oscillation. It is a fundamental waveform found in many natural phenomena, such as sound and light waves.

## Why would someone want to generate a sine wave using integers only?

Generating a sine wave using integers only can be useful for certain applications that require precise and efficient calculations. It can also be used for educational purposes to demonstrate the properties of sine waves.

## How can a sine wave be generated using integers only?

A sine wave can be generated using integers only by using a mathematical formula, such as the Taylor series or the CORDIC algorithm. These methods involve using a series of calculations and approximations to generate the curve.

## What are the limitations of generating a sine wave using integers only?

One limitation is that the resulting sine wave may not be as smooth or accurate as one generated using real numbers. Additionally, the calculations involved may be more complex and time-consuming. It may also be difficult to generate a sine wave with a specific frequency or amplitude using integers only.

## Are there any real-world applications for generating a sine wave using integers only?

Yes, there are some practical applications for generating a sine wave using integers only. This method is commonly used in digital signal processing, audio and video encoding, and in some electronic devices that require precise and efficient calculations.

• General Math
Replies
1
Views
1K
• Introductory Physics Homework Help
Replies
8
Views
694
• General Math
Replies
7
Views
2K
• General Math
Replies
1
Views
2K
• General Math
Replies
1
Views
3K
• Classical Physics
Replies
12
Views
1K
• General Math
Replies
36
Views
6K
• Calculus
Replies
3
Views
1K
• Linear and Abstract Algebra
Replies
14
Views
1K
• Special and General Relativity
Replies
16
Views
1K