Constructor examples of the AO class


Copy an AO
Construct an AO by loading the AO from a file
Construct an AO from a data file
Construct an AO from spectral window
Construct an AO from a parameter list object (PLIST)

Copy an AO

The following example creates a copy of an analysis object (blue command).

>> a1 = ao([1:12]);
>> a2 = ao(1)
----------- ao: a -----------

name:  none
creator:  created by hewitson@bobmac.aei.uni-hannover.de[130.75.117.65] on MACI/7.6
description:
data:  None
hist:  ao / ao / $Id: ao.m,v 1.220 2009/02/25 18:51:24 ingo Exp
mfilename:
mdlfilename:
-----------------------------


REMARK: The following command copies only the handle of an object and doesn't create a copy of the object (as above). This means that everything that happens to the copy or original happens to the other object.

>> a1 = ao()
----------- ao 01: a1 -----------
       name:  none
description:
       data:  None
       hist:  ao / ao / $Id: ao.m,v 1.220 2009/02/25 18:51:24 ingo Exp
  mfilename:
mdlfilename:
---------------------------------
>> a2 = a1;
>> a2.setName('my new name')
----------- ao 01: my new name -----------
       name:  my new name
description:
       data:  None
       hist:  ltpda_uoh / setName / $Id: ao.m,v 1.220 2009/02/25 18:51:24 ingo Exp
  mfilename:
mdlfilename:
------------------------------------------


If we display a1 again then we see that the property 'name' was changed although we only have changed a2.

>> a1
----------- ao 01: my new name -----------
       name:  my new name
description:
       data:  None
       hist:  ltpda_uoh / setName / $Id: ao.m,v 1.220 2009/02/25 18:51:24 ingo Exp
  mfilename:
mdlfilename:
------------------------------------------

Construct an AO by loading the AO from a file

The following example creates a new analysis object by loading the analysis object from disk.

a = ao('a1.mat')
a = ao('a1.xml')

or in a PLIST

pl = plist('filename', 'a1.xml')
a  = ao(pl)

Construct an AO from a data file

The following example creates a new analysis object by loading the data in 'file.txt'. The ascii file is assumed to be an equally sampled two-column file of time and amplitude.

a = ao('file.txt') or
a = ao('file.dat')


The following example creates a new analysis object by loading the data in 'file'. The parameter list determines how the analysis object is created. The valid key/value pairs of the parameter list are:

Key Description

'type'

'tsdata','fsdata','xydata' [default: 'tsdata']

'use_fs'

If this value is set, the x-axes is computed by the fs value. [default: empty]

'columns'

[1 2 1 4] Each pair represents the x- and y-axes (each column pair creates an analysis object).

If the value 'use_fs' is set, then each column is converted to the y vector of a time-series AO. [default: [1 2] ]

'comment_char'

The comment character in the file [default: '%']

'description'

To set the description in the analysis object

'...'

Every property of the data object e.g. 'name'

% Each pair in col represents the x- and y-axes.
% 'use_fs' is not used !!!

pl = plist('filename', 'data.dat',  ...
'description', 'my ao description',    ...
'type', 'xydata',   ...
'xunits', 's', ...
'yunits', {'Volt', 'Hz'}, ...
'columns', [1 2 1 3],    ...
'comment_char', '//');

out = ao('data.dat', pl);
out = ao(pl);


Another example where the time vector is specified by the sample rate (use_fs) and each column of data is converted in to a single AO.

% 'use_fs is used. As such, each column in col creates its own AO with the specified sample rate.

pl = plist('filename', 'data.dat',...
'type', 'tsdata',     ...
'use_fs', 100,     ...
't0', {'14:00:00', '14:00:20', '14:00:30'},   ...
'columns', [1 2 3]);
out = ao('data.dat', pl);
out = ao(pl);

Construct an AO from a spectral window

The following example creates a cdata type AO containing the window values.

win = specwin('Kaiser', 100, 10);
>> a = ao(win)
----------- ao 01: Kaiser -----------
       name:  Kaiser
description:
       data: 0.7145 0.7249 0.7351 0.7452 0.7551 0.7649 0.7746 0.7840 0.7934 0.8025 ...
             -------- cdata 01 ------------
                  y:  [1x100], double
             yunits:  []
             ------------------------------
       hist:  ao / ao / $Id: fromSpecWin.m,v 1.11 2008/12/05 10:47:14 hewitson Exp -->
  mfilename:
mdlfilename:
-------------------------------------

Construct an AO from a parameter list (plist)

Constructs an analysis object from the description given in the parameter list.

Use the key word 'fcn'
Use the key word 'vals'
Use the key word 'xvals' AND 'yvals'
Use the key word 'tsfcn'
Use the key word 'fsfcn'
Use the key word 'xyfcn'
Use the key word 'win'
Use the key word 'waveform'
Use the key word 'hostname'
Use the key word 'polyval'
Use the key word 'pzmodel'

Use the key word 'fcn'

The following example creates an AO from the description of any valid MATLAB function. The data object is of type cdata.

pl = plist('fcn', 'randn(100,1)');
a1 = ao(pl);

You can pass additional parameters to the fcn as extra parameters in the parameter list:

pl = plist('fcn', 'a*b', 'a', 2, 'b', 1:20);
a1 = ao(pl);

Use the key word 'vals'

The following example creates an AO from a set of values.

vals = [1 2 3; 4 5 6; 7 8 9];
pl = plist('vals', vals);
a1 = ao(vals)
a2 = ao(pl)

Use the key word 'xvals' and 'yvals'

Construct an AO from a set of values. The data type depends on the parameters.

You have to specify the parameters:

Key Description

'xvals'

a set of x values.

'yvals'

a set of y values.

You can also specify optional parameters

Key Description

'dtype'

type of the data object [default: tsdata]

'fs'

sampling frequency. Only used if 'dtype' is a time-series object [default: []]

x = 1:1000;
y = randn(1000,1);
pl1 = plist('xvals', x, 'yvals', y, 'dtype', 'tsdata');
pl2 = plist('xvals', x, 'yvals', y, 'dtype', 'fsdata');
pl3 = plist('xvals', x, 'yvals', y, 'dtype', 'xydata');
a1 = ao(pl1) % Create an AO with time-series data
a2 = ao(pl2) % Create an AO with frequency-series data
a3 = ao(pl3) % Create an AO with x-y data

Use the key word 'tsfcn'

Construct an AO from a function of time, t. The data object is of type tsdata (time-series data).

Key Description

'tsfcn'

a function of time

You can also specify optional parameters

Key Description

'fs'

sampling frequency [default: 1 Hz]

'nsecs'

length in seconds [default: 10 s]

't0'

Start time which is associated with the time-series

[default: '1970-01-01 00:00:00.000']

Example:
pl = plist('fs', 10, 'nsecs', 10, ...
           'tsfcn',  'sin(2*pi*1.4*t) + 0.1*randn(size(t))', ...
           't0', '1980-12-01 12:43:12');
a1 = ao(pl)

Use the key word 'fsfcn'

Construct an AO from a function of frequency, f. The data object is of type fsdata (frequency-series).

Key Description

'fsfcn'

a function of frequency

You can also specify optional parameters:

Key Description

'f1'

the initial frequency [default: 1e-9]

'f2'

the final frequency [default: 5]

'nf'

the number of frequency samples [default: 1000]

'scale'

'log' or 'lin' frequency spacing [default: 'log']

or provide a frequency vector:

Key Description

'f'

a vector of frequencies on which to evaluate the function

pl1 = plist('fsfcn', '1./f.^2', 'scale', 'lin', 'nf', 100);
pl2 = plist('fsfcn', '1./f.^2', 'f', logspace(0,3, 1000));
a1 = ao(pl1)
a2 = ao(pl2)

Use the key word 'xyfcn'

Construct an AO from a function f(x) string. The data object is of type xydata.

You have to specify the parameters:

Key Description

'xyfcn'

specify a function of 'x'

'x'

the x values

pl = plist('X', [1:50,52:2:100,110:10:1000], 'xyfcn', 'log(x)');
a1 = ao(pl)
----------- ao 01: a1 -----------
       name:  none
description:
       data: (1,0) (2,0.6931) (3,1.0986) (4,1.3862) (5,1.6094) ...
             -------- xydata 01 ------------
                  x:  [1 165], double
                  y:  [1 165], double
             xunits:  []
             yunits:  []
             -------------------------------
       hist:  ao / ao / $Id: fromXYFcn.m,v 1.3 2009/02/10 20:02:51 ingo Exp -->
  mfilename:
mdlfilename:
---------------------------------

Use the key word 'win'

Construct an AO from a spectral window object.
List of available window functions

pl1 = plist('win', specwin('Hanning', 100))
pl2 = plist('win', specwin('Kaiser', 10, 150));
a1 = ao(pl1)
a2 = ao(pl2)

Use the key word 'waveform'

Construct an AO from a waveform with the following waveform types

Key Description

'sine wave'

'A' - Amplitude of the wave

'f' - Frequency of the wave

'phi' - Phase of the wave

'noise'

'type' - can be 'Normal' or 'Uniform','sigma' - specify the standard deviation

'chirp'

'f0', 'f1', 't1' (help chirp)

'Gaussian pulse'

'f0', 'bw' (help gauspuls)

'Square wave'

'f', 'duty' (help square)

'Sawtooth'

'f', 'width' (help sawtooth)

You can also specify additional parameters:

Key Description

'fs'

sampling frequency [default: 10 Hz]

'nsecs'

length in seconds [default: 10 s]

't0'

time-stamp of the first data sample [default time(0)]

[default waveform: 'sine wave', A: 1, f: 1.23, phi: 0, fs: 10, nsecs: 10, t0: time(0) ].

% Construct a sine wave
pl   = plist('nsecs', 10, 'fs', 1000);
pl_w = pl.append('waveform', 'sine wave', 'phi', 30, 'f', 1.23);
out_sin = ao(pl_w)
% Construct random noise
pl_w = pl.append('waveform', 'noise', 'type', 'Normal');
out_noise1 = ao(pl_w)
% Construct uniform random noise
pl_w = append(pl, 'waveform', 'noise', 'type', 'Uniform');
out_noise2 = ao(pl_w)
% Construct a chirp waveform
pl_w = append(pl, 'waveform', 'chirp', 'f0', 1, 'f1', 50, 't1', 100);
out_chirp = ao(pl_w)
% Construct a Gaussian pulse waveform
pl_w = append(pl, 'waveform','Gaussian pulse', 'f0', 10, 'bw', 100);
out_gaus = ao(pl_w)
% Construct a Square wave
pl_w =append(pl,'waveform', 'Square wave', 'f', 1, 'duty', 50);
out_square = ao(pl_w)
% Construct a Sawtooth wave
pl_w = append(pl, 'waveform', 'Sawtooth', 'width', .5, 'f', 1);
out_saw = ao(pl_w)

Use the key word 'hostname'

Construct an AO by retrieving it from a LTPDA repository.

The relevant parameters are:

Key Description

'hostname'

the repository hostname. [default: 'localhost']

'database'

The database name [default: 'ltpda']

'id'

A vector of object IDs. [default: []]

'cid'

Retrieve all AO objects from a particular collection

'binary'

Set to 'yes' to retrieve from stored binary representation (not always available). [default: yes]

pl = plist('hostname', '130.75.117.67', 'database', 'ltpda_test', 'id', 1)
a1 = ao(pl)

Use the key word 'polyval'

Construct an AO from a set of polynomial coefficients. The relevant parameters are:

Key Description

'polyval'

A set of polynomial coefficients. [default: [] ]

Additional parameters:

Key Description

'nsecs'

Number of seconds [default: 10]

'fs'

Sample rate[default: 10 s]

or

Key Description

't'

vector of time vertices. The value can also be an AO, in which case the X vector is used. [default: [] ]

pl = plist('polyval', [1 2 3], 'Nsecs', 10, 'fs', 10);
a1 = ao(pl)

Use the key word 'pzmodel'

Generates an AO with a timeseries with a prescribed spectrum.

The relevant parameters are:

Key Description

'pzmodel'

a pole/zero model which builds the time-series AO

'nsecs'

number of seconds to be generated [default: 0]

'fs'

sampling frequency [default: 0]

You can also specify optional parameters:

Key Description

'xunits'

unit of the x-axis [default: 's']

'yunits'

unit of the y-axis [default: '']

p   = [pz(1,2) pz(10)]
z   = [pz(4)]
pzm = pzmodel(1, p, z)

fs    = 10
nsecs = 100
pl = plist('pzmodel', pzm, 'Nsecs', nsecs, 'Fs', fs)
a1 = ao(pl)




©LTP Team