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 set

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']

'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 '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.
% '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 (fs) and each column of data is converted in to a single AO.

% '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',     ...
'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 sets

Constructs an analysis object from the description given in the parameter list (in order of priority).

From ASCII File
From complex ASCII File
From Values
From Function
From XY Function
From Time-series Function
From Frequency-series Function
From Window
From Waveform
From Repository
From Polynomial
From Pzmodel

From ASCII File

The following example creates an analysis object from a datafile. Click here to get more information about the parameters.


% Construct two analysis-objects with time-series data from
% time data in the first column and the data in column 2 and 3 of the file.
a = ao(plist('filename', 'data.txt', 'columns', [1 2 1 3], 'type', 'tsdata'));

% Construct two analysis-objects with the given frequency and the data in column 1 and 2.
a = ao(plist('filename', 'data.txt', 'fs', 12.1, 'columns', [1 2], 'type', 'tsdata'));

% Define a comment character for skip comments.
a = ao(plist('filename', 'data.txt', 'comment_char', '#', 'columns', [1 2 1 3], 'type', 'tsdata'));

From complex ASCII File

The following example creates an analysis object from a complex datafile. Click here to get more information about the parameters.


a = ao(plist('filename', 'data.txt', 'complex_type', 'real/imag', 'type', 'tsdata'));
a = ao(plist('filename', 'data.txt', 'complex_type', 'real/imag', 'type', 'fsdata', 'columns', [1,2,4]));

From Values

The following example creates an AO from a set of values. The data type depends on the parameters. If you use the parameter key 'vals' then you will get an analysis object with cdata. Click here for information about the value parameter set or here to get more information about the xy-value parameter set.


% cdata
a = ao(plist('vals', [1 2 3], 'N', 10));

% xydata
a = ao(plist('xvals', [1 2 3], 'yvals', [10 20 30]));

% tsdata
a = ao(plist('xvals', [1 2 3], 'yvals', [10 20 30], 'type', 'tsdata'));
a = ao(plist('fs', 1, 'yvals', [10 20 30]));

% fsdata
a = ao(plist('xvals', [1 2 3], 'yvals', [10 20 30], 'type', 'fsdata'));
a = ao(plist('fs', 1, 'yvals', [10 20 30], 'type', 'fsdata'));
a = ao(plist('fs', 1, 'yvals', [10 20 30], 'type', 'fsdata', 'xunits', 'mHz', 'yunits', 'V'));

From Function

The following example creates an AO from the description of any valid MATLAB function. The data object is of type cdata. Click here to get more information about the parameters.


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

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


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

From XY Function

Construct an AO from a function f(x) string. The data object is from type xydata. Click here to get more information about the parameters.


a = ao(plist('xyfcn', 'cos(2*pi*x) + randn(size(x))', 'x', [1:1e5]));
a = ao(plist('xyfcn', 'log(x)', 'x', [1:50,52:2:100,110:10:1000]));

From Time-series Function

Construct an AO from a function of time, t f(t). The data object is from type tsdata (time-series data). Click here to get more information about the parameters.


a = ao(plist('fs',    10, ...
             'nsecs', 10, ...
             'tsfcn', 'sin(2*pi*1.4*t) + 0.1*randn(size(t))', ...
             't0',    '1980-12-01 12:43:12'));
a = ao(plist('tsfcn', 'cos(pi*t) + randn(size(t))', ...
             'fs',    1, ...
             'nsecs', 100));
a = ao(plist('fs',    10, ...
             'nsecs', 10, ...
             'tsfcn', 'sin(2*pi*1.4*t)+0.1*randn(size(t))', ...
             't0',    time('1980-12-01 12:43:12')));

From Frequency-series Function

Construct an AO from a function of frequency, f f(f). The data object is from type fsdata (frequency-series). Click here to get more information about the parameters.


a = ao(plist('fsfcn', 'f', 'f1', 1e-5, 'f2', 1, 'yunits', 'V'));
a = ao(plist('fsfcn', 'f', 'f', [0.01:0.01:1]));
a = ao(plist('fsfcn', '1./f.^2', 'scale', 'lin', 'nf', 100));

From Window

Construct an AO from a spectral window object.
Click here for a list of supported window functions and here to get more information about the parameters.


a = ao(plist('win', specwin('Hanning', 100)))
a = ao(plist('win', specwin('Kaiser', 10, 150)))
% >> % >> ao(plist('waveform','noise','type','normal','sigma',2,'nsecs',1000,'fs',1)); % >> % >> % >> % >>

From Waveform

Construct an AO from a waveform with the following waveform types. Click here to get more information about the parameters.


% Construct random noise
a = ao(plist('waveform', 'noise', 'type', 'Normal', 'sigma', 2, 'nsecs', 1000, 'fs', 1));

% Construct uniform random noise
a = ao(plist('waveform', 'noise', 'type', 'Uniform', 'nsecs', 1000, 'fs', 1));

% Construct a sine wave
a = ao(plist('waveform', 'sine wave', 'A', 3, 'f', 1, 'phi', pi/2, 'toff', 0.1, 'nsecs', 10, 'fs', 100));

% Construct a chirp waveform
a = ao(plist('waveform', 'chirp', 'f0', 0.1, 'f1', 1, 't1', 1, 'nsecs', 5, 'fs', 1000));

% Construct a Gaussian pulse waveform
a = ao(plist('waveform', 'gaussian pulse', 'f0', 1, 'bw', 0.2, 'nsecs', 20, 'fs', 10));

% Construct a Square wave
a = ao(plist('waveform', 'square wave', 'f', 2, 'duty', 40, 'nsecs', 10, 'fs', 100));

% Construct a Sawtooth wave
a = ao(plist('waveform', 'sawtooth', 'f', 1.23, 'width', 1, 'nsecs', 10/1.23, 'fs', 50));

From Repository

Construct an AO by retrieving it from a LTPDA repository. Click here to get more information about the parameters.


% Retrieves the objects with the object ID 1..10
a = ao(plist('hostname', '123.123.123.123', 'database', 'ltpda_test', 'ID', [1:10], 'binary', true));

From Polynomial

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: [] ]

Click here to get more information about the parameters.

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

From Pzmodel

Generates an AO with a timeseries with a prescribed spectrum. Click here to get more information about the parameters.


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

fs    = 10
nsecs = 100
a = ao(plist('pzmodel', pzm, 'Nsecs', nsecs, 'Fs', fs));



©LTP Team