itrp_init

Initialization of an interpolator object

Calling sequence

itrp = itrp_init();
itrp = itrp_init(type);
itrp = itrp_init('lagrange', degree);

Parameters

type:

Interpolator type (default is cardinal spline). Can be 'linear', 'cspline' or 'lagrange'.

degree:

Degree of the polynomial for Lagrange interpolation

itrp:

Interpolator object

Description

This function will create an interpolator object, that can be used either on fixed interpolation points (then use the interpolator with the resample function) or inside a dynamic clock recovery process (use with clock_rec_init function).

Supported interpolation modes are the following:

  • Linear (type = 'linear') : Piecewise linear interpolation between each pair of known values (equivalent to Lagrange of degree 1)

  • Cardinal spline (type = 'cspline') : Piecewise third degree polynomial between each pair of known values. The polynomials computed here are Catmull-Rom cardinal splines (equivalent to Lagrange of degree 3).

  • Lagrange (type = 'lagrange') : Piecewise polynomial interpolation (the degree d is configurable) between each pair of known values. Each polynomial is computed according to the d+1 neareast known values.

For illustration purpose, below is a comparison of the different interpolators with the Runge function :

Comparison of different interpolators with the Runge function

Example

In this example, we use piecewise linear interpolation, with fixed interpolation points.
R = 10; // Interpolation ratio
itrp = itrp_init('linear');     // Creation of the interpolator
t1 = (-1:0.2:1)'; x1 = t1 .^ 2; // Before interpolation
x2 = resample(x1,R,itrp);       // After interpolation
// Plotting
plot(t1,x1,'sk');
t2 = (-1:(0.2/R):1)'; plot(t2,x2(1:length(t2)),'b-');
legend(['$t^2$','Linear interpolation']);

Linear interpolation

How to define a custom interpolator

You can also define your own interpolator object, and for it to be compatible with the other functions (resample, clock_rec_init), it should be a structure containing the following fields:

  • itrp.name: name of the interpolator (string)
  • itrp.nspl: Number of input sample needed to compute one output sample. For example, for the piecewise linear interpolator, it is 2.
  • itrp.delay: Delay, in number of input samples, introduced by the interpolator
  • itrp.fun: Interpolating function, which prototype should be: y = itrp_fun(x,mu,itrp), where x are nspl input samples, mu is the fractionnal delay, itrp the interpolator object, and y the computed output sample.