In the previous posts [1,2] about approximations, I quickly discarded the Taylor series believing their approximation error characteristics were not ideal. However, this was based on using the Taylor derived polynomial for the entire domain . In the ‘better sin(x)‘ post, the domain was divided in four parts and the symmetry of sin(x) was exploited to reduce the approximation error. This trick is, of course, also possible with Taylor-based polynomial.
I tried it with the following results..
Taylor series of
The Taylor series of developed around is:
which, given terms, can be compactly written as:
A very useful property of this particular series is that the sign of each term is the opposite of the one that comes before it. In addition, the next term is always smaller than the previous one. This means that if we truncate the series at a certain term, the total approximation error is always smaller or equal to the first term we left out. So, we can choose the number of terms to include based on the desired approximation error!
The approximation error of our Taylor series is largest at the largest value of we’re going to use. By diving the domain by four, the largest value of we’ll encounter is . Knowing this, we can make a table of the approximation error versus the number of terms included in our polynomial:
|Terms, N||P(x) order||max. error|
Clearly, the maximum approximation error drops rapidly as the order of the polynomial is increased.
The third-order Taylor polynomial versus the ‘better sin(x)’ version.
Which approximation is better, the one from the previous post or a 3rd order Taylor approximation?
The third harmonic can be found at -35.0 dBc, which is 11.9 dB worse. The signal-to-noise ratio (SNR) of the Taylor-based version is 33.2 dB, which is 11.7 dB worse. Summarizing, you’re better off with the ‘better sin(x)’ approximation version.
Ninth-order Taylor performance
If you want a high-purity sine oscillator and have cycles to spare, but don’t want the memory footprint of a table-lookup oscillator, you can use a 9th-order Taylor approximation.
The SNR is around 121.2 dB when all calculations are implemented using floating-point arithmetic.
The Taylor series are well suited for approximating , especially when the domain is kept small. The precision of the approximation is easily determined and can be increased simply by adding additional terms. A 9th order polynomial is capable of reaching professional audio quality, in terms of SNR.