Generating sines and decaying sines
In this article, I will describe a simple algorithm that can be used to generate sine waves and decaying sine waves of a fixed frequency without computing any trigonometric functions. This algorithm is ideal for microcontrollers, where computing sines and cosines may be inefficient and storing tables of values may be impractical. The algorithm also involves no floating-point arithmetic. Theory The goal of this algorithm is to produce a series of values \(s_i=\sin\left(2\pi\frac{if}{f_s}\right)\), where \(f\) is the desired frequency of the sine wave, \(f_s\) is the sampling frequency, and \(i\ge 0\) is an integer. If this series of values is fed into a DAC at \(f_s\) samples per second, then the output of the DAC would be a sine wave with a frequency of \(f\). Recall that \(e^{j\theta}=\cos\theta + j\sin\theta\), where \(j\) is the imaginary unit. Thus, if we can compute the value of \(e^{2\pi j\frac{if}{f_s}}\), we would have not only \(s_i=\sin\left(2\pi\frac{if}{f_s}\righ