comparison m-toolbox/html_help/help/ug/ao_create_content.html @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 <!-- $Id: ao_create_content.html,v 1.9 2009/09/30 21:39:43 ingo Exp $ -->
2 <p>Analysis objects can be created in MATLAB in many ways. Apart from being created by the many
3 algorithms in the LTPDA Toolbox, AOs can also be created from initial data or descriptions
4 of data. The various <i>constructors</i>
5 are listed in the function help: <a href="matlab:doc('ao')">ao help</a>.</p>
6
7 <h3>Examples of creating AOs</h3>
8
9 <p>The following examples show some ways to create Analysis Objects.</p>
10
11 <ul>
12 <li><a href="ao_create.html#text">Creating AOs from text files</a></li>
13 <li><a href="ao_create.html#xml">Creating AOs from XML or MAT files</a></li>
14 <li><a href="ao_create.html#fcn">Creating AOs from MATLAB functions</a></li>
15 <li><a href="ao_create.html#tsfcn">Creating AOs from functions of time</a></li>
16 <li><a href="ao_create.html#window">Creating AOs from window functions</a></li>
17 <li><a href="ao_create.html#waveform">Creating AOs from waveform descriptions</a></li>
18 <li><a href="ao_create.html#pzmodel">Creating AOs from pole zero models</a></li>
19 </ul>
20
21 <hr>
22 <h4><a name="text"></a>Creating AOs from text files.</h4>
23
24 <p>Analysis Objects can be created from text files containing two columns of ASCII numbers. Files
25 ending in '.txt' or '.dat' will be handled as ASCII file inputs. The
26 first column is taken to be the time instances; the second column is taken to be the amplitude
27 samples. The created AO is of type <tt>tsdata</tt> with the sample rate set by the difference
28 between the time-stamps of the first two samples in the file. The name of the resulting AO is
29 set to the filename (without the file extension). The filename is also stored as a parameter in
30 the history parameter list. The following code shows this in action:</p>
31
32 <div class="fragment"><pre>
33 >> a = ao(<span class="string">'data.txt'</span>)
34 ----------- ao 01: data.txt_01_02 -----------
35
36 name: data.txt_01_02
37 data: (0,-1.06421341288933) (0.1,1.60345729812004) (0.2,1.23467914689078) ...
38 -------- tsdata 01 ------------
39
40 fs: 10
41 x: [100 1], double
42 y: [100 1], double
43 dx: [0 0], double
44 dy: [0 0], double
45 xunits: [s]
46 yunits: []
47 nsecs: 10
48 t0: 1970-01-01 00:00:00.000
49 -------------------------------
50
51 hist: ao / ao / SId: fromDatafile ... $-->$Id: ao ... S
52 mdlfile: empty
53 description:
54 UUID: e6ccfcb6-da49-4f4c-8c2c-3054fe5d2762
55 ---------------------------------------------
56 </pre></div>
57 <p>As with most constructor calls, an equivalent action can be achieved using an input
58 <a href="plist_intro.html">Parameter List</a>.</p>
59
60 <div class="fragment"><pre>
61 >> a = ao(plist(<span class="string">'filename'</span>, <span class="string">'data.txt'</span>))
62 </pre></div>
63
64 <hr>
65 <h4><a name="xml"></a>Creating AOs from XML or .mat files</h4>
66
67 <p>AOs can be saved as both XML and .MAT files. As such, they can also be created from these
68 files.</p>
69
70 <div class="fragment"><pre>
71 >> a = ao(<span class="string">'a.xml'</span>)
72 ----------- ao 01: a -----------
73
74 name: None
75 data: (0,-0.493009815316451) (0.1,-0.180739356415037) (0.2,0.045841105713705) ...
76 -------- tsdata 01 ------------
77
78 fs: 10
79 x: [100 1], double
80 y: [100 1], double
81 dx: [0 0], double
82 dy: [0 0], double
83 xunits: [s]
84 yunits: []
85 nsecs: 10
86 t0: 1970-01-01 00:00:01.000
87 -------------------------------
88
89 hist: ao / ao / SId: fromVals ... $-->$Id: ao ... S
90 mdlfile: empty
91 description:
92 UUID: 2fed6155-6468-4533-88f6-e4b27bc6e1aa
93 --------------------------------
94 </pre></div>
95
96 <hr>
97 <h4><a name="fcn"></a>Creating AOs from MATLAB functions</h4>
98
99 <p>AOs can be created from any valid MATLAB function which returns a vector or matrix of values.
100 For such calls, a parameter list is used as input. For example, the following code creates
101 an AO containing 1000 random numbers:</p>
102
103 <div class="fragment"><pre>
104 >> a = ao(plist(<span class="string">'fcn'</span>, <span class="string">'randn(1000,1)'</span>))
105 ----------- ao 01: a -----------
106
107 name: None
108 data: -1.28325610460477 -2.32895451628334 0.901931466951714 -1.83563868373519 0.06675 ...
109 -------- cdata 01 ------------
110 y: [1000x1], double
111 dy: [0x0], double
112 yunits: []
113 ------------------------------
114
115 hist: ao / ao / SId: fromFcn ... $-->$Id ... $
116 mdlfile: empty
117 description:
118 UUID: 0072f8d0-f804-472b-a4aa-e9ec6a8de803
119 --------------------------------
120 </pre></div>
121 <p>Here you can see that the AO is a <tt>cdata</tt> type and the name is set to be the function
122 that was input.</p>
123
124 <hr>
125 <h4><a name="tsfcn"></a>Creating AOs from functions of time</h4>
126
127 <p>AOs can be created from any valid MATLAB function which is a function of the variable
128 <tt>t</tt>. For such calls, a parameter list is used as input. For example, the following
129 code creates an AO containing sinusoidal signal at 1Hz with some additional Gaussian noise:</p>
130
131 <div class="fragment"><pre>
132 pl = plist();
133 pl = append(pl, <span class="string">'nsecs'</span>, 100);
134 pl = append(pl, <span class="string">'fs'</span>, 10);
135 pl = append(pl, <span class="string">'tsfcn'</span>, <span class="string">'sin(2*pi*1*t)+randn(size(t))'</span>);
136 a = ao(pl)
137 ----------- ao 01: a -----------
138
139 name: None
140 data: (0,1.37694916561229) (0.1,-0.820427237640771) (0.2,1.09228819960292) ...
141 -------- tsdata 01 ------------
142
143 fs: 10
144 x: [1000 1], double
145 y: [1000 1], double
146 dx: [0 0], double
147 dy: [0 0], double
148 xunits: [s]
149 yunits: []
150 nsecs: 100
151 t0: 1970-01-01 00:00:00.000
152 -------------------------------
153
154 hist: ao / ao / SId: fromTSfcn ... $-->$Id: ao ... S
155 mdlfile: empty
156 description:
157 UUID: c0f481cf-4bdd-4a91-bc78-6d34f8222313
158 --------------------------------
159 </pre></div>
160 <p>Here you can see that the AO is a <tt>tsdata</tt> type, as you would expect. Also note that you
161 need to specify the sample rate (<tt>fs</tt>) and the number of seconds of data you would like
162 to have (<tt>nsecs</tt>).</p>
163
164 <hr>
165 <h4><a name="window"></a>Creating AOs from window functions</h4>
166
167 <p>The LTPDA Toolbox contains a class for designing spectral windows
168 (see <a href="specwin.html">Spectral Windows</a>). A spectral window object can
169 also be used to create an Analysis Object as follows:</p>
170
171 <div class="fragment"><pre>
172 >> w = specwin(<span class="string">'Hanning'</span>, 1000)
173 ------ specwin/1 -------
174 type: Hanning
175 alpha: 0
176 psll: 31.5
177 rov: 50
178 nenbw: 1.5
179 w3db: 1.4382
180 flatness: -1.4236
181 ws: 500
182 ws2: 375.000000000001
183 win: [0 9.86957193144233e-06 3.94778980919441e-05 8.88238095955174e-05 0.0001579 ...
184 version: SId: specwin.m,v 1.67 2009/09/01 09:25:24 ingo Exp S
185 ------------------------
186
187 >> a = ao(w)
188 ----------- ao 01: ao(Hanning) -----------
189
190 name: ao(Hanning)
191 data: 0 9.86957193144233e-06 3.94778980919441e-05 8.88238095955174e-05 0.0001579 ...
192 -------- cdata 01 ------------
193 y: [1x1000], double
194 dy: [0x0], double
195 yunits: []
196 ------------------------------
197
198 hist: ao / ao / SId: fromSpecWin ... $-->$Id: ao ... S
199 mdlfile: empty
200 description:
201 UUID: ea1a9036-b9f5-4bdb-b3a3-211e9d697060
202 ------------------------------------------
203 </pre></div>
204 <p>
205 It is also possible to pass the information about the window as a plist to the ao constructor.
206 </p>
207 <div class="fragment"><pre>
208 >> ao(plist(<span class="string">'win'</span>, <span class="string">'Hanning'</span>, <span class="string">'length'</span>, 1000))
209 ----------- ao 01: ao(Hanning) -----------
210
211 name: ao(Hanning)
212 data: 0 9.86957193144233e-06 3.94778980919441e-05 8.88238095955174e-05 0.0001579 ...
213 -------- cdata 01 ------------
214 y: [1x1000], double
215 dy: [0x0], double
216 yunits: []
217 ------------------------------
218
219 hist: ao / ao / SId: fromSpecWin ... -->$Id: ao ... S
220 mdlfile: empty
221 description:
222 UUID: 5b81f67a-45b9-43f8-a74a-bc5161fd718f
223 ------------------------------------------
224 </pre></div>
225
226 <p>
227 The example code above creates a Hanning window object with 1000 points. The call to the AO
228 constructor then creates a <tt>cdata</tt> type AO with 1000 points. This AO can then be multiplied
229 against other AOs in order to window the data.
230 </p>
231
232 <hr>
233 <h4><a name="waveform"></a>Creating AOs from waveform descriptions</h4>
234
235 <p>
236 MATLAB contains various functions for creating different waveforms, for example,
237 <tt>square</tt>, <tt>sawtooth</tt>. Some of these functions can be called upon to create
238 Analysis Objects. The following code creates an AO with a sawtooth waveform:
239 </p>
240
241 <div class="fragment"><pre>
242 pl = plist();
243 pl = append(pl, <span class="string">'fs'</span>, 100);
244 pl = append(pl, <span class="string">'nsecs'</span>, 5);
245 pl = append(pl, <span class="string">'waveform'</span>, 'Sawtooth');
246 pl = append(pl, <span class="string">'f'</span>, 1);
247 pl = append(pl, <span class="string">'width'</span>, 0.5);
248
249 asaw = ao(pl)
250 ----------- ao 01: Sawtooth -----------
251
252 name: Sawtooth
253 data: (0,-1) (0.01,-0.96) (0.02,-0.92) (0.03,-0.88) (0.04,-0.84) ...
254 -------- tsdata 01 ------------
255
256 fs: 100
257 x: [500 1], double
258 y: [500 1], double
259 dx: [0 0], double
260 dy: [0 0], double
261 xunits: [s]
262 yunits: []
263 nsecs: 5
264 t0: 1970-01-01 00:00:00.000
265 -------------------------------
266
267 hist: ao / ao / SId: fromWaveform ... $-->$Id: ao ... S
268 mdlfile: empty
269 description:
270 UUID: cb76c866-ee3f-47e6-bb29-290074666e43
271 ---------------------------------------
272 </pre></div>
273 <p>
274 You can call the <tt>iplot</tt> function to view the resulting waveform:
275 </p>
276 <div class="fragment"><pre>
277 iplot(asaw);
278 </pre></div>
279 <img src="images/ao_create_sawtooth.png" alt="Sawtooth waveform" border="3" width="600px">
280
281 <hr>
282 <h4><a name="pzmodel"></a>Creating AOs from pole zero models</h4>
283
284 <p>
285 When generating an AO from a pole zero model, the noise generator function is called.
286 This a method to generate arbitrarily long time series with a prescribed spectral density.
287 The algorithm is based on the following paper:
288 </p>
289 <p>Franklin, Joel N.:
290 <i> Numerical simulation of stationary and non-stationary gaussian
291 random processes </i>, SIAM review, Volume {<b> 7</b>}, Issue 1, page 68--80, 1965.
292 </p>
293 <p>
294 The Document <i> Generation of Random time series with prescribed spectra </i> by Gerhard Heinzel (S2-AEI-TN-3034) <br> corrects a mistake in the aforesaid paper and describes the practical implementation.
295 The following code creates an AO with a time series having a prescribed spectral density,
296 defined by the input pole zero model:
297 </p>
298
299 <div class="fragment"><pre>
300 f1 = 5;
301 f2 = 10;
302 f3 = 1;
303 gain = 1;
304 fs = 10; <span class="comment">%sampling frequancy</span>
305 nsecs = 100; <span class="comment">%number of seconds to be generated</span>
306
307 p = [pz(f1) pz(f2)];
308 z = [pz(f3)];
309 pzm = pzmodel(gain, p, z);
310 a = ao(pzm, nsecs, fs)
311 ----------- ao 01: noisegen(None) -----------
312
313 name: noisegen(None)
314 data: (0,9.20287001568168) (0.1,-3.88425345108961) (0.2,6.31042718242658) ...
315 -------- tsdata 01 ------------
316
317 fs: 10
318 x: [1000 1], double
319 y: [1000 1], double
320 dx: [0 0], double
321 dy: [0 0], double
322 xunits: [s]
323 yunits: []
324 nsecs: 100
325 t0: 1970-01-01 00:00:00.000
326 -------------------------------
327
328 hist: ao / ao / SId: fromPzmodel ... $-->$Id: ao ... S
329 mdlfile: empty
330 description:
331 UUID: 4a89d910-8672-475f-91cd-4fcc4b52a6b4
332 ---------------------------------------------
333 </pre></div>
334 <p>
335 You can call the <tt>iplot</tt> function to view the resulting noise.
336 </p>
337 <div class="fragment"><pre>
338 iplot(a);
339 </pre></div>
340 <img src="images/ao_create_niose.png" alt="Random time series" border="3" width="600px">
341