Constructing AOs from data files

You can build AOs from existing ASCII data files. Various formats are supported, for example: multiple columns, or files containing comments.

Install the data pack

The data-pack for this training session should be downloaded from the LTPDA web-site. The zip file will expand to a top-level directory. This should contain sub-directories for each topic of the training session.

The rest of the tutorial will assume that you have changed directories in MATLAB to the data-pack directory so that filenames are relative to that directory. To change the working directory of MATLAB, either use the MATLAB interface or type

  cd /path/to/my/data/pack

Create an AO from a simple ASCII file

The data-pack contains a simple two-column text file which represents a time-series sampled at 10Hz. The first column contains the time-stamps, the second column the amplitude values.

To convert this data file to an AO, use the following command:

>> pl = plist('filename', 'topic1/simpleASCII.txt', ...
              'columns', [1 2], ...
              'type', 'tsdata');
>> a = ao(pl)
M:     constructing from plist
M:     load file: simpleASCII.txt
M:     constructing from filename and/or plist
M:     constructing from data object tsdata
----------- ao 01: a -----------
       name: ''
       data: (0,1.13549060238654) (0.1,2.37202031808076) (0.2,-0.531181753855465) (0.3,1.25684477541224) (0.4,1.30895517480354) ...
             -------- tsdata [x, y] --------
                  x:  [1000 1], double
                  y:  [1000 1], double
                 dx:  [0 0], double
                 dy:  [0 0], double
             xunits:  [s]
                  fs:  10
               nsecs:  100
                  t0:  1970-01-01 00:00:00.000 UTC
       hist: ao / ao / 8c11cf35c322925062d6fb1759d7c589b696a19b
       UUID: a1757c14-e6e7-4857-b213-0707d7a282ae

From the output on the screen you can see that

  1. the sample rate of the data is 10Hz, as expected
  2. the length of the data is 100s
  3. no name of the AO has automatically been set

You can plot this data and see that it is just a randon noise time-series.

Create an AO from a multi-column ASCII file

The data-pack contains a data file which contains multiple columns of data. Here we will load only selected columns from the file and produce multiple AOs, one for each column loaded. Column 1 of the file contains the time-stamps; columns 2-6 contain sine waves at frequencies 1-5Hz.

Let's load the 2Hz and 4Hz sine waves from the file. At the same time, we'll give the AOs names, Y units, and descriptions.

sigs = ao(plist('filename', 'topic1/multicolumnASCII.txt', ...
                'type', 'tsdata', ...
                'columns', [1 3 1 5], ...
                'name', {'sin2', 'sin4'}, ...
                'yunits', {'m', 'm'}, ...
                'description', {'sine wave at 2Hz', 'sine wave at 4Hz'}))

You can plot the results and focus on the first 2 seconds of data

    sigs.iplot(plist('XRanges', [0 2]))

©LTP Team