I’m working on a microcontroller DDS project in C and am having some trouble figuring out how to compute a linear interpolation to smooth the output values. The program as it stands now
uses the top 8 bits of a 24 bit accumulator as an index to an array of 8 bit output values. I need to come up with a function that will take the middle and lower byte of the accumulator and generate a value in between the “previous” and “next” value in the array. This would be straightforward enough on fast hardware, but since I’m using a microcontroller I really need to avoid doing any floating point operations or divisions!
With those restrictions, I’m not certain of a way to go about getting an 8 bit interpolated value from my two 8 bit input numbers and the lower 2 byes of the accumulator, which represents the “distance” between the two input values. Thanks in advance for any advice!
CLARIFICATION
DDS = Direct Digital Synthesis
in DDS a waveform is generated from a lookup table using a phase accumulator. The phase accumulator usually contains an integer component and a fractional component. The integer component is used as an index into the lookup table. In simple DDS implementations the fractional part is ignored, but for higher quality output the fractional component is used to interpolate (usually just linear interpolation) between adjacent lookup table values. For the above question we are looking at how to efficiently perform this linear interpolation between two lookup table values for a given fraction, f, where 0 <= f < 1.
Assuming you have a table of waveform values (either one quadrant or four quadrants, it doesn’t matter) then one possible optimisation is to store the delta values betwen successive table values. I.e. if you have e.g.
N = 256and a waveform tableLUT[N]then you also have a table of delta values,LUT_delta[N]. The relationship between the two precomputed tables isLUT_delta[i] = LUT[i+1] - LUT[i]. So instead of looking up two consecutive table values,LUT[i]andLUT[i+1], subtracting these to get the delta, then doing the interpolation, you just look up the first table value,LUT[i], and the delta,LUT_delta[i]and then calculate the interpolated value. This requires the same number of table lookups, but fewer math operations. You should be able to do the interpolation with a single multiply-accumulate instruction if you’re using a DSP, otherwise it’s a multiply + scale + add on a general purpose CPU. Also if you interleave theLUTandLUT_deltavalues you may be able to look upLUT[i]andLUT_delta[i]with a single read and then unpack the two values.Pseudo-code: