Linear interpolation of a sine wavetable

Click For Summary
SUMMARY

The discussion focuses on implementing linear interpolation for a sine wavetable using a 256-element array of 1-byte values in a microcontroller project. The method involves utilizing a 16-bit angle increment to control output frequency, with the formula for interpolation defined as F(x) = F(x_1) + (x - x_1) * (F(x_2) - F(x_1)) / (x_2 - x_1). The proposed solution includes using the cosine function to derive the necessary values for interpolation, ensuring integer math is maintained for efficiency. An alternative approach suggests expanding the table to represent a quadrant for increased resolution.

PREREQUISITES
  • Understanding of linear interpolation techniques
  • Familiarity with sine and cosine functions
  • Knowledge of 16-bit integer arithmetic
  • Experience with microcontroller programming
NEXT STEPS
  • Research linear interpolation algorithms in embedded systems
  • Study the implementation of sine and cosine functions in microcontrollers
  • Explore optimization techniques for integer arithmetic in embedded applications
  • Investigate the design of wavetable synthesis for audio applications
USEFUL FOR

Microcontroller developers, audio engineers, and anyone involved in digital signal processing who seeks to enhance the smoothness of sine wave outputs through interpolation techniques.

bitrex
Messages
190
Reaction score
0
Hi everyone. I'm doing a microcontroller project where I'm using a 256 element array of 1 byte values to output a sine wave at varying frequencies. I'm using the top 8 bytes of a 16 bit "angle increment" value that's incremented by varying amounts as an index to the array of values, to control the frequency of the output.

At low frequencies, however, there are too few data points to make a smooth output. I'd like to do linear interpolation of the sine wave data points to get a smoother output. The formula for the value of a function F(X) at a point between two known values F(X1) and F(X2) is:

[tex]F(x) = F(x_1) + (x - x_1) * \frac{F(x_2) - F(x_1)}{x_2 - x_1}[/tex]

The first element of this equation, [tex]F(x_1)[/tex], is easy, it's just the value stored in the array at the top 8 bits of the current 16 bit angle increment. The second element is just the bottom 8 bits of the current angle increment. The third element, however, is more computationally intensive. However, since the third part of the function is just the first derivative of the sine function at the current point, and the derivative of the sine function is cosine, I was thinking I could just grab a value from the sine table that's pi/2 radians ahead of the current value and use that. Does that seem like it would work?
 
Technology news on Phys.org
Assuming you want to keep everything in integers and you keep your angle as a 16 bit integer - I.E. 0-65535. To get the linear interpreted value you would do,

Lookup Angle/256 in table - val1
Lookup next value -val2
Calculate val1+((val2-val1)*(Angle and 255))/256)

This is in fact your function above but done using integer maths.

Alternatively, if you only require a little more resolution, make your 256 byte table represent a quadrant. This would give your angle a range from 0-1023.

Mike.
 

Similar threads

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