Downsampling reduces the sampling rate of the input AOs by an integer factor, which can be very useful for example to reduce data load.
The downsample method takes the following parameters:
The decimation factor [by default is 1: no downsampling] (must be an integer)
The sample offset for where the downsampling starts counting. By default, this value is zero so it starts counting from the first sample.
First we'll create a time-series of random white noise at 10Hz. To do that, define a plist with the key/value pairs shown below, and pass these to the ao constructor. If you're using the workbench, add an ao constructor block to the canvas and select the parameter set "From Time-series Function" and set the parameters as they are in the plist below.
% create an AO of random data with fs = 10 Hz; pl = plist('name', 'None', ... 'tsfcn', 'randn(size(t))', ... 'fs', 10, ... 'yunits', 'm', ... 'nsecs', 10); x = ao(pl); % create AO
Now we will downsample this data by a factor 5 to 2Hz. We use the method ao/downsample and set the downsample factor in the plist as shown below.
pl_down = plist('factor', 5); % add the decimation factor x_down = downsample(x, pl_down); % downsample the input AO, x iplot(x, x_down) % plot original,x, and decimated,x_down, AOs
The downsample method takes an 'offset' key which controls where the counting starts. The default is to output every Nth sample starting with the first. The 'offset' key tells downsample to start the counting from a sample other than the first. The example below outputs every 4th sample starting from sample 10.
pl_downoff = plist('factor', 4,'offset',10); % add decimation factor and offset parameter x_downoff = downsample(x, pl_downoff); % downsample the input AO, x iplot(x, x_downoff) % plot original,x, and decimated,x_downoff, AOs
|Topic 2 - Pre-processing of data||Upsampling a time-series AO|