# Cubic Spline Interpolation

void riscv_spline_f32(riscv_spline_instance_f32 *S, const float32_t *xq, float32_t *pDst, uint32_t blockSize)
void riscv_spline_init_f32(riscv_spline_instance_f32 *S, riscv_spline_type type, const float32_t *x, const float32_t *y, uint32_t n, float32_t *coeffs, float32_t *tempBuffer)
group SplineInterpolate

Spline interpolation is a method of interpolation where the interpolant is a piecewise-defined polynomial called “spline”.

Given a function f defined on the interval [a,b], a set of n nodes x(i) where a=x(1)<x(2)<…<x(n)=b and a set of n values y(i) = f(x(i)), a cubic spline interpolant S(x) is defined as:

Introduction

where

Having defined h(i) = x(i+1) - x(i)

Algorithm

It is possible to write the previous conditions in matrix form (Ax=B). In order to solve the system two boundary conidtions are needed.

• Natural spline: S1’’(x1)=2*c(1)=0 ; Sn’’(xn)=2*c(n)=0 In matrix form:

• Parabolic runout spline: S1’’(x1)=2*c(1)=S2’’(x2)=2*c(2) ; Sn-1’’(xn-1)=2*c(n-1)=Sn’’(xn)=2*c(n) In matrix form:

A is a tridiagonal matrix (a band matrix of bandwidth 3) of size N=n+1. The factorization algorithms (A=LU) can be simplified considerably because a large number of zeros appear in regular patterns. The Crout method has been used: 1) Solve LZ=B

2) Solve UX=Z

c(i) for i=1, …, n-1 are needed to compute the n-1 polynomials. b(i) and d(i) are computed as:

• b(i) = [y(i+1)-y(i)]/h(i)-h(i)*[c(i+1)+2*c(i)]/3

• d(i) = [c(i+1)-c(i)]/[3*h(i)] Moreover, a(i)=y(i).

It is possible to compute the interpolated vector for x values outside the input range (xq<x(1); xq>x(n)). The coefficients used to compute the y values for xq<x(1) are going to be the ones used for the first interval, while for xq>x(n) the coefficients used for the last interval.

Behaviour outside the given intervals

The initialization function takes as input two arrays that the user has to allocate: `coeffs` will contain the b, c, and d coefficients for the (n-1) intervals (n is the number of known points), hence its size must be 3*(n-1); `tempBuffer` is temporally used for internal computations and its size is n+n-1.

Initialization function

The x input array must be strictly sorted in ascending order and it must not contain twice the same value (x(i)<x(i+1)).

Functions

void riscv_spline_f32(riscv_spline_instance_f32 *S, const float32_t *xq, float32_t *pDst, uint32_t blockSize)

Processing function for the floating-point cubic spline interpolation.

Parameters
• S[in] points to an instance of the floating-point spline structure.

• xq[in] points to the x values of the interpolated data points.

• pDst[out] points to the block of output data.

• blockSize[in] number of samples of output data.

void riscv_spline_init_f32(riscv_spline_instance_f32 *S, riscv_spline_type type, const float32_t *x, const float32_t *y, uint32_t n, float32_t *coeffs, float32_t *tempBuffer)

Initialization function for the floating-point cubic spline interpolation.

Parameters
• S[inout] points to an instance of the floating-point spline structure.

• type[in] type of cubic spline interpolation (boundary conditions)

• x[in] points to the x values of the known data points.

• y[in] points to the y values of the known data points.

• n[in] number of known data points.

• coeffs[in] coefficients array for b, c, and d

• tempBuffer[in] buffer array for internal computations