Continuity between Polynomial Fits

66 Views Asked by At

I'm currently working on a polynomial regression project and I've hit a wall. I'm trying to fit time-series data where I wish to "scroll" a window across the data and fit a polynomial to the data within that window. My goal is to achieve at least $C^3$ continuity between the polynomials for each window (because I need information from the second and third derivatives of the polynomials).

I start by fitting data points $[d_0:d_{N-1}]$ with a polynomial, $p_0$, obtained from standard regression. I then move the window over by $1$ and fit data points $[d_1:d_{N}]$ with a polynomial, $p_1$. However, because I want continuity between $p_0$ and $p_1$ I cannot simply using standard polynomial regression to obtain $p_1$.

So I tried putting together a system of equations $n+1$ to solve for the coefficients of $p_1$, where $n$ is the degree of the $p_1$:

First an equation to incorporate the newest data that entered the window:

$p_1(x_N) = y_N$

where $y_N$ is the $N^{th}$ data point. My data is somewhat noisy, so instead of $y_N$ I actually use a smoothed analogue of $y_N$ (either a moving average or a polynomial obtained from standard regression accessed at $x_N$).

Then for the remaining equations I enforce continuity at the interface between $p_1$ and $p_0$, $x_{N-1}$:

$p_1(x_{N-1}) = p_0(x_{N-1})$

$p_1^{(1)}(x_{N-1}) = p_0^{(1)}(x_{N-1})$

$:$

$p_1^{(n-1)}(x_{N-1}) = p_0^{(n-1)}(x_{N-1})$

This gives a system of $n+1$ equations that can be solved to obtain the coefficients of $p_1$ such that $p_1$ has $C^{n-1}$ continuity with $p_0$.

I'm able to build the matrix for the system of equations and solve for the vector of $p_1$ coefficients. However, when I do so the resulting $p_1$ doesn't even yield $C^0$ continuity. I've thoroughly checked my code and the matrix equation it builds for errors but there are not any. I tried altering the system of equations to only enforce $C^3$ continuity but that didn't work either.

Does anyone have any insight as to why this doesn't work? Better yet does anyone know how to achieve my goal of at least $C^3$ continuity with this "scrolling" spline-like polynomial?

Thank you for the help!