LTPDA Toolbox | ![]() ![]() |
Analysis objects can be created in MATLAB in many ways. Apart from being created by the many algorithms in the LTPDA Toolbox, AOs can also be created from initial data or descriptions of data. The various constructors are listed in the function help: ao help.
The following examples show some ways to create Analysis Objects.
Analysis Objects can be created from text files containing two columns of ASCII numbers. Files ending in '.txt' or '.dat' will be handled as ASCII file inputs. The first column is taken to be the time instances; the second column is taken to be the amplitude samples. The created AO is of type tsdata with the sample rate set by the difference between the time-stamps of the first two samples in the file. The name of the resulting AO is set to the filename (without the file extension). The filename is also stored as a parameter in the history parameter list. The following code shows this in action:
>> a = ao('data1.txt')
+ creating AO from text file data1.txt
----------- ao: a -----------
tag: -00001
name: data1
provenance: created by unknown@bob.local[192.168.2.100] on MACI/7.4 (R2007a)/0.2a (R2007a) at 2007-06-23 19:46:05
comment:
data: tsdata / data1
hist: history / ao / $Id: ao.m,v 1.28 2007/06/08 11:44:24 hewitson Exp $
mfile:
-----------------------------
As with most constructor calls, an equivalent action can be achieved using an input Parameter List.
>> a = ao(plist(param('filename', 'data1.txt')))
AOs can be saved as both XML and .MAT files. As such, they can also be created from these files.
>> a = ao('a.xml')
-- reading provenance
-- reading history
-- reading plist
-- reading param
-- reading history
-- reading plist
-- reading param
-- reading param
-- reading data
-- reading real data samples
* read 10000 Y samples
----------- ao: a -----------
tag: -00001
name: save(data1,a.xml)
provenance: created by unknown@bob.local[192.168.2.100] on MACI/7.4 (R2007a)/0.2a (R2007a) at 2007-06-23 20:00:21
comment:
data: tsdata / data1
hist: history / ao / $Id: ao.m,v 1.28 2007/06/08 11:44:24 hewitson Exp $
mfile:
-----------------------------
AOs can be created from any valid MATLAB function which returns a vector or matrix of values. For such calls, a parameter list is used as input. For example, the following code creates an AO containing 1000 random numbers:
>> a = ao(plist(param('fcn', 'randn(1000,1)'))) ----------- ao: a ----------- tag: -00001 name: randn(1000,1) provenance: created by unknown@bob.local[192.168.2.100] on MACI/7.4 (R2007a)/0.2a (R2007a) at 2007-06-23 20:04:52 comment: data: cdata / randn(1000,1) hist: history / ao / $Id: ao.m,v 1.28 2007/06/08 11:44:24 hewitson Exp $ mfile: -----------------------------
Here you can see that the AO is a cdata type and the name is set to be the function that was input.
AOs can be created from any valid MATLAB function which is a function of the variable t. For such calls, a parameter list is used as input. For example, the following code creates an AO containing sinusoidal signal at 1Hz with some additional Gaussian noise:
pl = plist(); pl = append(pl, param('nsecs', 100)); pl = append(pl, param('fs', 10)); pl = append(pl, param('tsfcn', 'sin(2*pi*1*t)+randn(size(t))')); a = ao(pl) ----------- ao: a ----------- tag: -00001 name: TSfcn provenance: created by unknown@bob.local[192.168.2.100] on MACI/7.4 (R2007a)/0.2a (R2007a) at 2007-06-24 06:47:19 comment: data: tsdata / sin(2*pi*1*t)+randn(size(t)) hist: history / ao / $Id: ao.m,v 1.28 2007/06/08 11:44:24 hewitson Exp $ mfile: -----------------------------
Here you can see that the AO is a tsdata type, as you would expect. Also note that you need to specify the sample rate (fs) and the number of seconds of data you would like to have (nsecs).
The LTPDA Toolbox contains a class for designing spectral windows (see Spectral Windows). A spectral window object can also be used to create an Analysis Object as follows:
>> w = specwin('Hanning', 1000)
-------- Hanning ------------
created:
alpha: 0
psll: 31.5
rov: 50
nenbw: 1.5
w3db: 1.4382
flatness: -1.4236
ws: 500
ws2: 375
win: 1000
-----------------------------
>> a = ao(w)
----------- ao: a -----------
tag: -00001
name: Hanning
provenance: created by unknown@bob.local[192.168.2.100] on MACI/7.4 (R2007a)/0.2a (R2007a) at 2007-06-24 10:27:18
comment:
data: cdata / Hanning
hist: history / ao / $Id: ao.m,v 1.28 2007/06/08 11:44:24 hewitson Exp $
mfile:
-----------------------------
The example code above creates a Hanning window object with 1000 points. The call to the AO constructor then creates a cdata type AO with 1000 points. This AO can then be multiplied against other AOs in order to window the data.
MATLAB contains various functions for creating different waveforms, for example, square, sawtooth. Some of these functions can be called upon to create Analysis Objects. The following code creates an AO with a sawtooth waveform:
pl = plist(); pl = append(pl, param('fs', 100)); pl = append(pl, param('nsecs', 5)); pl = append(pl, param('waveform', 'Sawtooth')); pl = append(pl, param('f', 1)); pl = append(pl, param('width', 0.5)); asaw = ao(pl) ----------- ao: asaw ----------- tag: -00001 name: Sawtooth provenance: created by unknown@bob.local[192.168.2.100] on MACI/7.4 (R2007a)/0.2a (R2007a) at 2007-06-24 10:37:51 comment: data: tsdata / sawtooth(2*pi*1*t,0.5) hist: history / ao / $Id: ao.m,v 1.28 2007/06/08 11:44:24 hewitson Exp $ mfile: --------------------------------
You can call the plot function to view the resulting waveform:
figure, plot(asaw);
![]() |
Introducing Analysis Objects | Saving Analysis Objects | ![]() |
©LTP Team