Mercurial > hg > ltpda
view m-toolbox/html_help/help/ug/ltpda_training_topic_2_5.html @ 40:977eb37f31cb database-connection-manager
User friendlier errors from utils.mysql.connect
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 18:04:03 +0100 |
parents | f0afece42f48 |
children |
line wrap: on
line source
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html lang="en"> <head> <meta name="generator" content= "HTML Tidy for Mac OS X (vers 1st December 2004), see www.w3.org"> <meta http-equiv="Content-Type" content= "text/html; charset=us-ascii"> <title>Remove trends from a time-series AO (LTPDA Toolbox)</title> <link rel="stylesheet" href="docstyle.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.52.2"> <meta name="description" content= "Presents an overview of the features, system requirements, and starting the toolbox."> </head> <body> <a name="top_of_page" id="top_of_page"></a> <p style="font-size:1px;"> </p> <table class="nav" summary="Navigation aid" border="0" width= "100%" cellpadding="0" cellspacing="0"> <tr> <td valign="baseline"><b>LTPDA Toolbox</b></td><td><a href="../helptoc.html">contents</a></td> <td valign="baseline" align="right"><a href= "ltpda_training_topic_2_4.html"><img src="b_prev.gif" border="0" align= "bottom" alt="Interpolation of a time-series AO"></a> <a href= "ltpda_training_topic_2_6.html"><img src="b_next.gif" border="0" align= "bottom" alt="Whitening noise"></a></td> </tr> </table> <h1 class="title"><a name="f3-12899" id="f3-12899"></a>Remove trends from a time-series AO</h1> <hr> <p> <p> The <tt>ao/detrend</tt> method offers the possibility to remove polynomial trends from a data series. </p> <p> The method can be configured with the following parameter: <table cellspacing="0" class="body" cellpadding="2" border="0" width="80%"> <colgroup> <col width="25%"/> <col width="75%"/> </colgroup> <thead> <tr valign="top"> <th class="categorylist">Key</th> <th class="categorylist">Description</th> </tr> </thead> <tbody> <!-- Key 'N' --> <tr valign="top"> <td bgcolor="#f3f4f5"> <p><tt>N</tt></p> </td> <td bgcolor="#f3f4f5"> <p>The order of the polynomial to fit and remove. For orders below 10, a very fast C-code algorithm is used. For higher orders, the MATLAB functions <tt>polyfit</tt> and <tt>polyval</tt> are used to construct the polynomial which is then subtracted from the data.</p> </td> </tr> </tbody> </table> </p> <br> <h2>Example 1</h2> <p> In this example we will construct a time-series consisting of noise plus a known quadratic trend. We will then remove that trend using <tt>ao/detrend</tt> and compare the detrended time-series with the original noise. </p> <p> First let's create the time-series series consisting of the noise plus trend. </p> <div class="fragment"><pre> <span class="comment">% Construct noise data stream</span> fs = 10; nsecs = 10; 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>); x = ao(pl); <span class="comment">% Construct a quadratic data series</span> 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); trend = ao(pl_trend); <span class="comment">% Add them together</span> fcn_trend = x + trend; </pre> </div> <p> <table cellspacing="0" class="note" summary="Note" cellpadding="5" border="1"> <tr width="90%"> <td> The offset of 5 is added to the noise to ensure the data series doesn't come close to zero; we want to divide by it later in the example. </td> </tr> </table> </p> <p> Next we will detrend the data and compare the result to the noise data <tt>x</tt> we made above. </p> <div class="fragment"><pre> pl_detr = plist(<span class="string">'N'</span>,2); detr = detrend(fcn_trend, pl_detr); iplot(x, fcn_trend, detr, plist(<span class="string">'LineStyles'</span>, {<span class="string">''</span>, <span class="string">''</span>, <span class="string">'--'</span>})); </pre> </div> <p> <table cellspacing="0" class="note" summary="Note" cellpadding="5" border="1"> <tr width="90%"> <td> In the <tt>plist</tt> we specified 'LineStyles' as empty strings. These just serve as place holders and can be interpreted as "just to the default". If you want a data-series plotted with no line, then specify 'none', for example, <tt>{'none', '-', '--'}</tt>. </td> </tr> </table> </p> <br> <img src="images/ltpda_training_1/topic2/detrend.png" alt="Detrend" border="3"> <br> <p> From this plot, it is not very easy to see how well our detrending worked. Let's form the fractional difference of the original <tt>x</tt> data and the detrended data and plot that instead. </p> <div class="fragment"><pre> detr5 = detr + 5; diff = 100.*(x-detr5)./x; iplot(diff); </pre> </div> <p> The result is shown below. We added the value 5 to the detrended time-series just to ensure that we don't divide by any values close to zero. </p> <br> <img src="images/ltpda_training_1/topic2/detrend_diff.png" alt="Detrend" border="3"> <br> <p> Try increasing the length of the data series to say, 1000 or 10000 seconds, to see how the detrending improves. </p> <p> <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': <div class="fragment"><pre> c = find(detr.procinfo, 'coeffs'); <span class="comment">% Remember also, that you will loose the 'coeffs' if you make any operation on "detr"</span> </pre></div> </p> Below is an example pipeline to perform the steps we did above: </p> <br> <img src="images/ltpda_training_1/topic2/detrend_pipeline.png" alt="Detrend" border="3"> <br> <p> This introduces a new concept to the pipelines, namely, the use of constant blocks. Constant blocks are executed before the rest of the pipeline and the values are placed in the MATLAB workspace. This means that all parameter lists on the pipeline can refer to these constants. For example, the pipeline above declares two constants: 'fs' and 'nsecs'. The two <tt>ao</tt> blocks refer to these. Below is the parameter list for the first <tt>ao</tt> block, <tt>noise</tt>. </p> <br> <img src="images/ltpda_training_1/topic2/detrend_ao_plist.png" alt="Detrend" border="3"> <br> <p> If you want to change the length of this simulation, then you just need to change the value in the constant block, <tt>nsecs</tt>. </p> <p> To add constant blocks to your pipeline, right-click on the canvas and select "Additional Blocks->Constant" from the context menu. You can also add an annotation from the same context menu. The above pipeline shows one annotation. To edit the text on an annotation, double-click it. Right-clicking on an annotation gives a context menu that allows you to configure its appearance. </p> </p> <br> <br> <table class="nav" summary="Navigation aid" border="0" width= "100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td align="left" width="20"><a href="ltpda_training_topic_2_4.html"><img src= "b_prev.gif" border="0" align="bottom" alt= "Interpolation of a time-series AO"></a> </td> <td align="left">Interpolation of a time-series AO</td> <td> </td> <td align="right">Whitening noise</td> <td align="right" width="20"><a href= "ltpda_training_topic_2_6.html"><img src="b_next.gif" border="0" align= "bottom" alt="Whitening noise"></a></td> </tr> </table><br> <p class="copy">©LTP Team</p> </body> </html>