Abrazolica


Home     Archive     Tags     About        RSS
A Recursive Formula for Sampling a Sine Wave

Suppose we want to sample \(y(t)=\sin{\omega t}\) at intervals of \(T\) so that

\[\begin{align} y_n & = y(nT) = \sin{nT\omega}\nonumber\\ n & = 0,1,2,\ldots\nonumber \end{align}\]

\(f_s = 1/T\) is the sampling frequency so that

\[T\omega=T2\pi f = 2\pi f/f_s\]

Call \(\Omega = 2\pi f/f_s\) a dimensionless frequency, so that

\[y_n = \sin{n\Omega}\]

Calculating sine functions is computationally expensive, so we don’t want to have to calculate \(\sin{n\Omega}\) for every new value of \(n\). Luckily, we don’t have to. There is a recursive formula for calculating \(y_n\) from \(y_{n-1}\) and \(y_{n-2}\). To derive this formula, start by letting

\[x_n = \cos{n\Omega}\]

Then we can define a complex sequence \(z_n\) as follows

\[\begin{align} z_n & = x_n + jy_n = e^{jn\Omega} = e^{j\Omega}e^{j(n-1)\Omega} = e^{j\Omega}z_{n-1}\nonumber\\ & = (\cos{\Omega}+j\sin{\Omega})(x_{n-1}+jy_{n-1})\nonumber\\ & = \cos{\Omega}\;x_{n-1}-\sin{\Omega}\;y_{n-1}+j(\sin{\Omega}\;x_{n-1}+\cos{\Omega}\;y_{n-1})\nonumber \end{align}\]

The real part of \(z_n\) is \[x_n = \cos{\Omega}\;x_{n-1}-\sin{\Omega}\;y_{n-1}\] and the imaginary part is \[y_n = \sin{\Omega}\;x_{n-1}+\cos{\Omega}\;y_{n-1}\]

Solve the last expression for \(x_{n-1}\) \[x_{n-1} = \frac{y_n - \cos{\Omega}\;y_{n-1}}{\sin{\Omega}}\]

Substitute this into the last expression for \(x_n\) \[x_n = \frac{\cos{\Omega}}{\sin{\Omega}}(y_n - \cos{\Omega}\;y_{n-1}) - \sin{\Omega}\;y_{n-1}\] Subtract one from the index of the last equation \[x_{n-1} = \frac{\cos{\Omega}}{\sin{\Omega}}(y_{n-1} - \cos{\Omega}\;y_{n-2}) - \sin{\Omega}\;y_{n-2}\]

Substitute this equation into the last expression for \(y_n\) and simplify to get the following recursive equation \[y_n = 2\cos{\Omega}\;y_{n-1}-y_{n-2}\]

To use this equation you just have to calculate \(\cos{\Omega}\) one time. The formula is an efficient way to generate sine wave samples.

This post as a pdf (If this link doesn't work, click on post title first)


© 2010-2025 Stefan Hollos and Richard Hollos

submit to reddit   

blog comments powered by Disqus