Mercurial > hg > ltpda
comparison m-toolbox/html_help/help/ug/ltpda_training_topic_2_5.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 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
2 "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> | |
3 | |
4 <html lang="en"> | |
5 <head> | |
6 <meta name="generator" content= | |
7 "HTML Tidy for Mac OS X (vers 1st December 2004), see www.w3.org"> | |
8 <meta http-equiv="Content-Type" content= | |
9 "text/html; charset=us-ascii"> | |
10 | |
11 <title>Remove trends from a time-series AO (LTPDA Toolbox)</title> | |
12 <link rel="stylesheet" href="docstyle.css" type="text/css"> | |
13 <meta name="generator" content="DocBook XSL Stylesheets V1.52.2"> | |
14 <meta name="description" content= | |
15 "Presents an overview of the features, system requirements, and starting the toolbox."> | |
16 </head> | |
17 | |
18 <body> | |
19 <a name="top_of_page" id="top_of_page"></a> | |
20 | |
21 <p style="font-size:1px;"> </p> | |
22 | |
23 <table class="nav" summary="Navigation aid" border="0" width= | |
24 "100%" cellpadding="0" cellspacing="0"> | |
25 <tr> | |
26 <td valign="baseline"><b>LTPDA Toolbox</b></td><td><a href="../helptoc.html">contents</a></td> | |
27 | |
28 <td valign="baseline" align="right"><a href= | |
29 "ltpda_training_topic_2_4.html"><img src="b_prev.gif" border="0" align= | |
30 "bottom" alt="Interpolation of a time-series AO"></a> <a href= | |
31 "ltpda_training_topic_2_6.html"><img src="b_next.gif" border="0" align= | |
32 "bottom" alt="Whitening noise"></a></td> | |
33 </tr> | |
34 </table> | |
35 | |
36 <h1 class="title"><a name="f3-12899" id="f3-12899"></a>Remove trends from a time-series AO</h1> | |
37 <hr> | |
38 | |
39 <p> | |
40 <p> | |
41 The <tt>ao/detrend</tt> method offers the possibility to remove polynomial trends from a data series. | |
42 </p> | |
43 <p> | |
44 The method can be configured with the following parameter: | |
45 <table cellspacing="0" class="body" cellpadding="2" border="0" width="80%"> | |
46 <colgroup> | |
47 <col width="25%"/> | |
48 <col width="75%"/> | |
49 </colgroup> | |
50 <thead> | |
51 <tr valign="top"> | |
52 <th class="categorylist">Key</th> | |
53 <th class="categorylist">Description</th> | |
54 </tr> | |
55 </thead> | |
56 <tbody> | |
57 <!-- Key 'N' --> | |
58 <tr valign="top"> | |
59 <td bgcolor="#f3f4f5"> | |
60 <p><tt>N</tt></p> | |
61 </td> | |
62 <td bgcolor="#f3f4f5"> | |
63 <p>The order of the polynomial to fit and remove. For orders below 10, a very fast C-code algorithm | |
64 is used. For higher orders, the MATLAB functions <tt>polyfit</tt> and <tt>polyval</tt> are used to | |
65 construct the polynomial which is then subtracted from the data.</p> | |
66 </td> | |
67 </tr> | |
68 </tbody> | |
69 </table> | |
70 </p> | |
71 <br> | |
72 <h2>Example 1</h2> | |
73 <p> | |
74 In this example we will construct a time-series consisting of noise plus a known quadratic trend. | |
75 We will then remove that trend using <tt>ao/detrend</tt> and compare the detrended time-series with the | |
76 original noise. | |
77 </p> | |
78 <p> | |
79 First let's create the time-series series consisting of the noise plus trend. | |
80 </p> | |
81 <div class="fragment"><pre> | |
82 <span class="comment">% Construct noise data stream</span> | |
83 fs = 10; | |
84 nsecs = 10; | |
85 pl = plist(<span class="string">'name'</span>, <span class="string">'None'</span>, <span class="string">'tsfcn'</span>, <span class="string">'5+randn(size(t))'</span>, <span class="string">'fs'</span>, fs, <span class="string">'nsecs'</span>, nsecs, <span class="string">'yunits'</span>, <span class="string">'V'</span>); | |
86 x = ao(pl); | |
87 <span class="comment">% Construct a quadratic data series</span> | |
88 pl_trend = plist(<span class="string">'tsfcn'</span>, <span class="string">'t.^2'</span>, <span class="string">'fs'</span>, fs, <span class="string">'nsecs'</span>, nsecs); | |
89 trend = ao(pl_trend); | |
90 <span class="comment">% Add them together</span> | |
91 fcn_trend = x + trend; | |
92 </pre> | |
93 </div> | |
94 <p> | |
95 <table cellspacing="0" class="note" summary="Note" cellpadding="5" border="1"> | |
96 <tr width="90%"> | |
97 <td> | |
98 The offset of 5 is added to the noise to ensure the data series | |
99 doesn't come close to zero; we want to divide by it later in the example. | |
100 </td> | |
101 </tr> | |
102 </table> | |
103 </p> | |
104 <p> | |
105 Next we will detrend the data and compare the result to the noise data <tt>x</tt> we made above. | |
106 </p> | |
107 <div class="fragment"><pre> | |
108 pl_detr = plist(<span class="string">'N'</span>,2); | |
109 detr = detrend(fcn_trend, pl_detr); | |
110 iplot(x, fcn_trend, detr, plist(<span class="string">'LineStyles'</span>, {<span class="string">''</span>, <span class="string">''</span>, <span class="string">'--'</span>})); | |
111 </pre> | |
112 </div> | |
113 <p> | |
114 <table cellspacing="0" class="note" summary="Note" cellpadding="5" border="1"> | |
115 <tr width="90%"> | |
116 <td> | |
117 In the <tt>plist</tt> we specified 'LineStyles' as empty strings. These just serve as place holders | |
118 and can be interpreted as "just to the default". If you want a data-series plotted with no line, then | |
119 specify 'none', for example, <tt>{'none', '-', '--'}</tt>. | |
120 </td> | |
121 </tr> | |
122 </table> | |
123 </p> | |
124 <br> | |
125 <img src="images/ltpda_training_1/topic2/detrend.png" alt="Detrend" border="3"> | |
126 <br> | |
127 <p> | |
128 From this plot, it is not very easy to see how well our detrending worked. Let's form | |
129 the fractional difference of the original <tt>x</tt> data and the detrended data and plot that instead. | |
130 </p> | |
131 <div class="fragment"><pre> | |
132 detr5 = detr + 5; | |
133 diff = 100.*(x-detr5)./x; | |
134 iplot(diff); | |
135 </pre> | |
136 </div> | |
137 <p> | |
138 The result is shown below. We added the value 5 to the detrended time-series | |
139 just to ensure that we don't divide by any values close to zero. | |
140 </p> | |
141 <br> | |
142 <img src="images/ltpda_training_1/topic2/detrend_diff.png" alt="Detrend" border="3"> | |
143 <br> | |
144 <p> | |
145 Try increasing the length of the data series to say, 1000 or 10000 seconds, to see how the | |
146 detrending improves. | |
147 </p> | |
148 <p> | |
149 <p>The value of the coefficient describing the subracted trend are included in the field <tt>procinfo</tt> of the <tt>ao</tt> objects. The <tt>procinfo</tt> is actually a <tt>plist</tt> object, so we can search for parameters, in this case the key is 'coeffs': | |
150 <div class="fragment"><pre> | |
151 c = find(detr.procinfo, 'coeffs'); | |
152 | |
153 <span class="comment">% Remember also, that you will loose the 'coeffs' if you make any operation on "detr"</span> | |
154 </pre></div> | |
155 </p> | |
156 Below is an example pipeline to perform the steps we did above: | |
157 </p> | |
158 <br> | |
159 <img src="images/ltpda_training_1/topic2/detrend_pipeline.png" alt="Detrend" border="3"> | |
160 <br> | |
161 <p> | |
162 This introduces a new concept to the pipelines, namely, the use of constant blocks. Constant blocks | |
163 are executed before the rest of the pipeline and the values are placed in the MATLAB workspace. This means | |
164 that all parameter lists on the pipeline can refer to these constants. For example, the pipeline above | |
165 declares two constants: 'fs' and 'nsecs'. The two <tt>ao</tt> blocks refer to these. Below is the parameter | |
166 list for the first <tt>ao</tt> block, <tt>noise</tt>. | |
167 </p> | |
168 <br> | |
169 <img src="images/ltpda_training_1/topic2/detrend_ao_plist.png" alt="Detrend" border="3"> | |
170 <br> | |
171 <p> | |
172 If you want to change the length of this simulation, then you just need to change the value | |
173 in the constant block, <tt>nsecs</tt>. | |
174 </p> | |
175 <p> | |
176 To add constant blocks to your pipeline, right-click on the canvas and select "Additional Blocks->Constant" from | |
177 the context menu. You can also add an annotation from the same context menu. The above pipeline shows one | |
178 annotation. To edit the text on an annotation, double-click it. Right-clicking on an annotation gives a context | |
179 menu that allows you to configure its appearance. | |
180 </p> | |
181 </p> | |
182 | |
183 <br> | |
184 <br> | |
185 <table class="nav" summary="Navigation aid" border="0" width= | |
186 "100%" cellpadding="0" cellspacing="0"> | |
187 <tr valign="top"> | |
188 <td align="left" width="20"><a href="ltpda_training_topic_2_4.html"><img src= | |
189 "b_prev.gif" border="0" align="bottom" alt= | |
190 "Interpolation of a time-series AO"></a> </td> | |
191 | |
192 <td align="left">Interpolation of a time-series AO</td> | |
193 | |
194 <td> </td> | |
195 | |
196 <td align="right">Whitening noise</td> | |
197 | |
198 <td align="right" width="20"><a href= | |
199 "ltpda_training_topic_2_6.html"><img src="b_next.gif" border="0" align= | |
200 "bottom" alt="Whitening noise"></a></td> | |
201 </tr> | |
202 </table><br> | |
203 | |
204 <p class="copy">©LTP Team</p> | |
205 </body> | |
206 </html> |