• ### 4-Point Polynomial Interpolation.. care to explain?

Hi there
I am familiar with audio engineering etc but somewhat new to pd.
I am in the process of building a sample-playback engine for sound effects.
Can someone enlighten me as to the meaning of 4-point polynomial interpolation as it is used in [tabread4~]?
A link with the info would be appreciated if it is written somewhere.

Dan

• Posts 5 | Views 8368
• With tabread4~ what's happening is that a sliding window of 4 samples is moving forwards and the instantaneous output is a function of those four values. It's done to smooth the curve of the data when the sampling points might not be accurate (because of say quantisation errors), and also to provide access to values in between the real stored values. This happens when you want to read the sample of looping oscillator back at a frequency that isn't an integer factor of the original sample rate - common for most oscillators. Imagine you had a table of just 2 samples. 2 point linear interpolation would say - if value 0 is 10 and value 1 is 20 then the value that *would* be at index 0.5 (if it existed) is 15 (the simple average) That's interpolation. Theres many takes on it, which fall under the numerical methods field of "curve fitting" you might find better examples searching on that term. Polynomials are cool because they are infinitely differentiable, you can pick any in between value and it will fit smoothly into the curve with the others and won't suddenly freak out to infinity or zero.

Basically -

Linear, we just take two points and assume a line runs between them to find an inbetween value.

Polynomial (2nd order) We use an equivillence like Legrange (turns a sequence to sum of products) which are coefficients of a polynomial (eg S = 1x + 3y + 16z^2)
That gives us a curve that can fit to three points.

There's cubic (spline) and other interpolation functions you can use. Basically the higher the order of powers the more smoothness and accuracy you will get, but you will need to process more samples for each table read .

http://www.efunda.com/math/num_interpolation/num_interpolation.cfm

Use the Source.

• Wow, thanks

they taught us about linear interpolation (w/regards to oversampling) in school, this is good some familiar ground to springboard from.
This application of the polynomial basically allows a very smooth curve using few points? It sounds like the four points are measured from sample-values at any given point in time, just to be clear is this correct?
does it measure between 2 samples and generate 4 points? or are there 4 sample values that provide the points for the polynomial curve?

Now why does the help file for [tabread4~] add 4 samples to "ensure the usefulness of the 4 point polynomial"?

I am really sorry for burdening you ob1, but you sound like you know what you're talking about!

Dan

• Yep, all four points are used, the points are 4 adjacent sequential, like x, x+1, X+2, x+3

The extra 3 samples in an array for [tabread4~] are there to make this work for
the last value in the table. I don't understand this, because the most useful interpolation afaics is "wraping", ie x0+L+1 = x0, x0+L+2 = x1... for a table length L

Some Pd objects actually get sniffy about being passed a table with the wrong number of elements and won't read from it.

see,

http://crca.ucsd.edu/~msp/techniques/v0.08/book-html/node28.html

Use the Source.

• This looks like the relevant code,

for (i = 0; i < n; i++)
{
float findex = *in++;
int index = findex;
float frac, a, b, c, d, cminusb;
static int count;
if (index < 1)
index = 1, frac = 0;
else if (index > maxindex)
index = maxindex, frac = 1;
else frac = findex - index;
fp = buf + index;
a = fp[-1];
b = fp[0];
c = fp[1];
d = fp[2];
/* if (!i && !(count++ & 1023))
post("fp = %lx, shit = %lx, b = %f", fp, buf->b_shit, ; */
cminusb = c-b;
*out++ = b + frac * (
cminusb - 0.1666667f * (1.-frac) * (
(d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
)
);
}

that last line is the one, and it's using the previous, current and next two points as a, b, c d. Is that right? Claude?

Use the Source.

Posts 5 | Views 8368
Internal error.

Oops! Looks like something went wrong!