Interpolation of a time-series AO

The ao class has a method for interpolating data using different forms of interpolation. This method is called ao/interp.

To configure ao/interp, use the following parameters:

Key Description


A new set of vertices (relative to the data reference time t0) on which to resample.


The method by which to interpolate. Choose from

  • 'nearest' - nearest neighbour
  • 'linear' - linear interpolation
  • 'spline' - for piecewise cubic spline interpolation
  • 'pchip' - for shape-preserving piecewise cubic interpolation
  • 'v5cubic' - same as 'pchip'
  • 'cubic' - for the cubic interpolation from MATLAB 5


Here we will interpolate a sinusoidal signal on to a new time-grid. The result will be to increase the sample rate by a factor 2.

First we create a time-series ao:

    pl = plist('Name', 'None', 'tsfcn', 'sin(2*pi*1.733*t)', 'fs', 20, 'nsecs', 10, 'yunits', 'V');
    x  = ao(pl);

Then we create the new time-grid we want to resample on to.

   tt   = linspace(0, x.nsecs - 1/x.fs, 2*(x.len));

Please notice the 'dot' notation we used to call a couple methods to access properties of this tsdata (time-series) AO:

will provide a double with the duration of the timeseries, in seconds.
will provide a double with the sampling rate of the timeseries, in Hz.

Finally, we can apply our new time-grid to the data using interp. We test two of the available interpolation methods:

    pl_spline  = plist('vertices', tt);
    pl_nearest = plist('vertices', tt, 'method', 'nearest');
    x_spline   = interp(x, pl_spline);
    x_nearest  = interp(x, pl_nearest);
    iplot(x, x_spline, x_nearest, plist('Markers', {'o', '+', 'x'}, ...
    'LineColors', {'k', 'r', 'g'}, ...
    'XRanges', [0 1]));

Notice the settings in the plist we used for the plotting, that allow changing the marker of the plotted lines, as well as the settings for adjusting the colors of the line themselves.

©LTP Team