Interpolation of a randomly sampled signal.

Namespace: dsp::filter

Prototype

Vector<T> interp(const Vecf &x, const Vector<T> &y, const Vecf &x2, InterpOption mode=LINEAR)

Parameters

xVector with input sampling positions (must be a growing sequence).
yVector of known values at the specified sampling positions.
x2Vector with desired sampling points (must be a growing sequence).
modeType of desired interpolation (lineair or natural splines).

Description

This function will resample a signal, for which we know the values only at some time points, not necessarily equidistant. Given a set of \(N\) points \((x_k,f(y_k))\), it computes a set of values \(f(x'_k)\), the \(x'_k\) being equidistant between \(x_0\) and \(x_{N-1}\).

Example

  soit x  = Vecf::valeurs({0, 1, 2, 5, 6, 10}),
       y  = Vecf::valeurs({1, 2, -1, -4, -1, 1}),
       x2 = linspace(0, 10, 100),
       yi = interp(x, y, x2),
       yj = interp(x, y, x2, InterpOption::CSPLINE);

  Figures f;
  f.subplot().plot(x, y, "ob", "Points connus");
  f.gcf().plot(x2, yi, "g-", "Interpolation");
  f.gcf().titre("Interpolation linéaire");
  f.subplot().plot(x, y, "ob", "Points connus");
  f.gcf().plot(x2, yj, "g-", "Interpolation");
  f.gcf().titre("Interpolation par splines naturelles");
  f.afficher();