Linear interpolation of a sine wavetable

In summary, the speaker is working on a microcontroller project involving a 256 element array and a top 8 byte angle increment value to control the frequency of a sine wave output. They want to use linear interpolation to smooth the output at low frequencies, and are considering using the derivative of the sine function to do so. Another alternative suggested is using integer math to achieve the desired result.
  • #1
bitrex
193
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
  • #2
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.
 
  • #3


I would say that your approach seems reasonable and could potentially work. Linear interpolation is a common technique used to smooth out data points, and using the derivative of the sine function to calculate the third element is a clever way to do so. However, I would recommend testing and verifying your method before implementing it in your project. You may also want to consider exploring other interpolation methods, such as cubic or spline interpolation, to see if they can provide even smoother results. Additionally, make sure to consider any potential errors or limitations that may arise from using a finite array of data points to represent a continuous function like a sine wave. Overall, your approach shows good problem-solving skills and I encourage you to continue exploring and refining your method.
 

1. What is linear interpolation of a sine wavetable?

Linear interpolation of a sine wavetable is a mathematical technique used to fill in the gaps between discrete data points in a sine wavetable. It involves connecting the points with a straight line and using the slope of the line to estimate the values in between.

2. Why is linear interpolation used for sine wavetables?

Linear interpolation is used for sine wavetables because it is a simple and efficient way to create a continuous waveform from discrete data points. It can also help improve the resolution and smoothness of the waveform.

3. How does linear interpolation affect the accuracy of a sine wavetable?

Linear interpolation can affect the accuracy of a sine wavetable by introducing some error due to the estimation of values in between the data points. However, the error is typically very small and may not be noticeable to the human ear.

4. Are there other interpolation methods for sine wavetables?

Yes, there are other interpolation methods for sine wavetables such as cubic spline interpolation and polynomial interpolation. These methods may offer better accuracy but can also be more computationally intensive.

5. Can linear interpolation be used for other types of waveforms?

Yes, linear interpolation can be used for other types of waveforms, such as square or sawtooth waves. It can also be applied to other types of data interpolation, not just for audio signals.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
5
Views
930
  • Set Theory, Logic, Probability, Statistics
Replies
30
Views
2K
  • Programming and Computer Science
Replies
1
Views
10K
Replies
3
Views
735
  • Programming and Computer Science
Replies
30
Views
4K
  • Calculus and Beyond Homework Help
Replies
8
Views
783
  • Programming and Computer Science
Replies
9
Views
2K
  • Electrical Engineering
Replies
4
Views
834
Replies
78
Views
3K
Back
Top