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

VERTICES

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

METHOD

The method by which to interpolate. Choose from

  • 'nearest' - nearest neighbour
  • 'linear' - linear interpolation
  • 'spline' - for spline interpolation
  • 'cubic' - for cubic interpolation

Example

Here we will interpolate a sinusoid singal 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));
  

And 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]));
  
Interpolate

To do the same activity on the workbench, we can use a pipeline like:

Interpolate

This teaches some important aspects of the use of the workbench, so it's worth stepping through its construction slowly.

To build this pipeline:

  1. Create a new empty canvas
  2. Add two MATLAB Expression Blocks:
    1. Right-click on the canvas and choose "Add Block...->MATBlock". A MATBlock is a block which can evaluate any valid MATLAB expression and pass that to further blocks via its single output.
    2. Select the block, then change its name in the block property table (located at the top left of the "Properties" tab) to 'fs'. Alternatively, the name of the block can be changed by right-clicking on the block and choosing "Set name"
    3. Double-click the block to get a pop-up dialog where you can enter the MATLAB expression. In this case just enter the value 20.
    4. Select this 'fs' block and hit ctrl-d (cmd-d on OS X) to duplicate the block.
    5. Select the new block and change its name to 'nsecs'
    6. Double-click the 'nsecs' block to change its expression. Enter the value 10.
  3. Next we need some additional blocks. Add an ao block, two ao/interp blocks, an ao/x block, and an ao/iplot block.
  4. Connect up the blocks as shown on the pipeline above.
    To add inputs (or outputs) to a block, right-click on the block and choose "Add input".
    Double-click an LTPDA Block to get a dialog box to enter a new name for the block.
    To set the color of the pipes eminating from a particular block, right-click on the block and choose "Set output pipe color" from the context menu. You can also set the color of individual pipes by right-clicking on a pipe and choosing "Set color" from the context menu.
  5. Next we need to set the various properties of each block. Follow these steps:
    1. Set the properties of the AO block to look like:
      Interpolate
      The single quotes around the TSFCN value are not strictly necessary, but it can avoid problems, for example in the case you have a variable t already defined in the MATLAB workspace.
    2. Set the properties of the first interpolate block (a_spline) to look like:
      Interpolate
      Notice that here we have used the keywords PORT_1 and PORT_2 to build the expression. These refer to the ports of that block, and are connected to the MATLAB Expression Blocks which represent the values we are interested in.
    3. The block ao/x has no properties and simply gets the full x-vector from the output of a_spline. This is then passed to the next interpolation block where we use the values as the vertices for the next interpolation step, thus ensuring that the two interpolations are done on the same grid.
    4. Set the properties of the second interpolate block (a_near) to look like:
      Interpolate
    5. Finally, for the iplot block, add three new parameters and give then key names and values like:
      Interpolate
It should now be possible to run this pipeline and see a plot very similar to the one produced above.



©LTP Team