Charles Henry czhenry at gmail.com
Fri Jun 27 07:39:18 CEST 2008

```On Thu, Jun 26, 2008 at 11:18 AM, Mathieu Bouchard <matju at artengine.ca> wrote:
> I fucked up here. To get a C2 curve you may need to solve an equation system
> covering the whole table (!). Anyhow, a C1 system is fine enough for most
> uses, and it would be already much better than pd's.
>
> The thing is that you can only match the 2nd derivatives if you let the 1st
> derivatives just match but freely float. Then there will be one curve going
> through all points of the whole table supposing that the 2nd derivative is
> zero at the beginning and end of the table. Clearly this is a wholly
> different game because you need to compute a 2nd table to remember what the
> 1st derivatives are supposed to be and then you can't change anything in the
> 1st table without recomputing the 2nd table from scratch, or something.

I get what you're saying now.  I had to read it a couple times through
to see :)  You're referring to piecewise cubic polynomials, right?  We
would wind up with an overdetermined system of equations if we didn't
float the 1st *and* 2nd derivatives, which would come out as a linear
algebra problem of the size of the table.

but I think it gets even worse.  There could be a non-zero null space
to the problem.  There are infinite solutions to interpolate a table
full of zeros, with these conditions.  What a mess :)

>> or we could set x,x and x'=(x-x[-1])/2 and x'=(x-x)/2
>> again, 4 constraints, cubic polynomial, etc...
>
> Seems reasonable. What I want has to have constraints on x' and x'.
> Those would be a possibility. The problem is that it uses a gap of 2 samples
> instead of one, so it uses a "blurry" derivative, but the alternative is to
> have to pick between forward-difference and backwards-difference. The
> "blurry" derivative happens to be the average of the 1-sample
> forward-difference and backward-difference.

By expanding it out to more points, we could use a more accurate
calculation of the derivative.  There's always a frequency dependent
effect on the accuracy of 1st derivative approximations.

For example, backwards difference:
x' ~= x[n] - x[n-1]

X'[z] = X[z] ( 1 - z^-1)

Which has spectrum,  X'[w]=1-e^(-j*w)
|X'[w]|^2=(1-cos(w))^2+sin(w)^2,  phase (X'[w])=arctan(  sin(w)/(1-cos(w))  )

our ideal system has X'[w]=j*w

Central divided difference
x'  ~= (x[n+1] - x[n-1])/2

X'[z] = X[z] ( z  - z^-1)/2

Which has spectrum,  X'[w]=(e^(j*w)-e^(-j*w))/2

X'[w]=j*sin(w)

It still has trouble with the high frequencies.  So there might be
some value in expanding the number of points to include better
approximations.

>> and x''=x-2*x+x[-1] and x''=x-2*x+x
>> 6 constraints, 5th degree polynomial
>
> I think that the replacement for tabread4~ should be another cubic, so that
> it takes almost the same time to compute it. What I said about C2 was based
> on a mistaken reading of webpages trying to refresh myself on splines. I
> should've been more careful.

Yeah, a cubic polynomial makes the most sense for small changes.  I
haven't ever heard of people interpolating 4 points with a 5th degree
polynomial.... but I think I could make it work....

> The "blurry" derivative above seems to be fine... I'd have to try it, but I
> should be working on other things now. I suppose that Cyrille already has
> everything figured out anyway. I just feel like talking about math
> sometimes... ;)

It's all good by me :)

Chuck

```