<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>data smoothing Archives - CenterSpace</title>
	<atom:link href="https://www.centerspace.net/tag/data-smoothing/feed" rel="self" type="application/rss+xml" />
	<link>https://www.centerspace.net/tag/data-smoothing</link>
	<description>.NET numerical class libraries</description>
	<lastBuildDate>Tue, 07 Feb 2023 21:52:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>
<site xmlns="com-wordpress:feed-additions:1">104092929</site>	<item>
		<title>Smoothing Cubic Splines</title>
		<link>https://www.centerspace.net/smoothing-cubic-splines</link>
					<comments>https://www.centerspace.net/smoothing-cubic-splines#respond</comments>
		
		<dc:creator><![CDATA[Paul Shirkey]]></dc:creator>
		<pubDate>Tue, 15 Oct 2013 21:17:12 +0000</pubDate>
				<category><![CDATA[NMath]]></category>
		<category><![CDATA[c# cubic spline]]></category>
		<category><![CDATA[c# smooth cubic spline]]></category>
		<category><![CDATA[c# smoothing spline]]></category>
		<category><![CDATA[cubic smoothing spline]]></category>
		<category><![CDATA[cubic spline]]></category>
		<category><![CDATA[data fitting]]></category>
		<category><![CDATA[data smoothing]]></category>
		<category><![CDATA[natural cubic spline]]></category>
		<category><![CDATA[smooth cubic spline]]></category>
		<category><![CDATA[smoothing cubic spline]]></category>
		<category><![CDATA[vb cubic spline]]></category>
		<category><![CDATA[vb data fitting]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=4712</guid>

					<description><![CDATA[<p>Smooth cubic splines embody a curve fitting technique which blends the ideas of <em>cubic splines</em> and <em>curvature minimization</em> to create an effective data modeling tool for noisy data.  Traditional cubic splines represent the tabulated data as a piece-wise continuous curve which passes through each value in the data table.  If we need to fit a spline to some non-uniformly sampled noisy data, the results can be rather unsatisfying because every data point is visited by the spline...</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/smoothing-cubic-splines">Smoothing Cubic Splines</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Cubic smoothing splines embody a curve fitting technique which blends the ideas of <em>cubic splines</em> and <em>curvature minimization</em> to create an effective data modeling tool for noisy data. Traditional interpolating cubic splines represent the tabulated data as a piece-wise continuous curve which passes through each value in the data table. The curve spanning each data interval is represented by a cubic polynomial, with the requirement that the endpoints of adjacent cubic polynomials match in location and in their first and second derivatives. If we need to fit a spline to some non-uniformly sampled noisy data, the results can be rather unsatisfying because every data point is visited by the spline (see chart below).</p>
<figure id="attachment_4717" aria-describedby="caption-attachment-4717" style="width: 400px" class="wp-caption alignnone"><a href="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip1.png"><img decoding="async" class="size-full wp-image-4717" src="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip1.png" alt="Cubic Spline with Noisy Data" width="400" srcset="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip1.png 509w, https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip1-150x150.png 150w, https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip1-300x298.png 300w" sizes="(max-width: 509px) 100vw, 509px" /></a><figcaption id="caption-attachment-4717" class="wp-caption-text">Cubic spline fit to noisy data</figcaption></figure>
<p>If a smoothed cubic spline is fitted to the same noisy dataset, the general sense of the data is captured without the spline mimicking the noise.</p>
<figure id="attachment_4719" aria-describedby="caption-attachment-4719" style="width: 400px" class="wp-caption alignnone"><a href="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip2.png"><img decoding="async" class="size-full wp-image-4719" src="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip2.png" alt="Smoothing Cubic Spline" width="400" srcset="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip2.png 509w, https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip2-150x150.png 150w, https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip2-300x298.png 300w" sizes="(max-width: 509px) 100vw, 509px" /></a><figcaption id="caption-attachment-4719" class="wp-caption-text">Smoothed cubic spline with p = 0.98</figcaption></figure>
<h2>Understanding Smoothing Cubic Splines</h2>
<p>Both cubic splines and cubic smoothing splines are constrained to have contiguous first and second derivatives, however only (interpolating) cubic splines are required to pass though all data points. Freed of these <code>N</code> data-point constraints, new additional constraints are now needed to have a fully determined solution. In the case of cubic smoothing splines we have the following two functional constraints: one which minimizes the squared error between the data and spline, and a second which minimizes the curvature.</p>
<p>To minimize the squared error we minimize the following function, where the <code>yi</code>&#8216;s are the data&#8217;s ordinates, and the <code>g(x)</code>&#8216;s are cubic polynomials.</p>
<p><center></p>
<figure id="attachment_4751" aria-describedby="caption-attachment-4751" style="width: 123px" class="wp-caption alignnone"><a href="https://www.centerspace.net/wp-content/uploads/2013/10/CodeCogsEqn4.gif"><img decoding="async" loading="lazy" class="alignnone size-full wp-image-4763" src="https://www.centerspace.net/wp-content/uploads/2013/10/CodeCogsEqn4.gif" alt="Smoothing cubic spline squared error" width="123" height="53" /></a><figcaption id="caption-attachment-4751" class="wp-caption-text">Squared error</figcaption></figure>
<p></center></p>
<p>To minimize the curvature we minimize:</p>
<p><center></p>
<figure id="attachment_4751" aria-describedby="caption-attachment-4751" style="width: 106px" class="wp-caption alignnone"><a href="https://www.centerspace.net/wp-content/uploads/2013/10/CodeCogsEqn3.gif"><img decoding="async" loading="lazy" class="alignnone size-full wp-image-4751" src="https://www.centerspace.net/wp-content/uploads/2013/10/CodeCogsEqn3.gif" alt="Curvature" width="106" height="41" /></a><figcaption id="caption-attachment-4751" class="wp-caption-text">Curvature</figcaption></figure>
<p></center></p>
<p>Since we are not concerned with the convexity or concavity of the curvature, only the amount of curvature, we square the curvature eliminating the sign.</p>
<p>For most data sets, these two constraint functions act in opposition to one another. The first constraint pushes the spline as close as possible to the data points while the second attempts to keep the spline as free of curvature as possible. In the final formulation, these two countervailing constraints are joining by a weighting parameter, <code>p</code>, which balances these two opposing constraints and results in a smoothing cubic spline.</p>
<p><center></p>
<figure id="attachment_4747" aria-describedby="caption-attachment-4747" style="width: 493px" class="wp-caption alignnone"><a href="https://www.centerspace.net/wp-content/uploads/2013/10/CodeCogsEqn5.gif"><img decoding="async" loading="lazy" class="alignnone size-full wp-image-4766" src="https://www.centerspace.net/wp-content/uploads/2013/10/CodeCogsEqn5.gif" alt="Smooth cubic spline constraints" width="493" height="53" /></a><figcaption id="caption-attachment-4747" class="wp-caption-text">Cubic Smoothing Spline Constraints</figcaption></figure>
<p></center></p>
<p>The two degenerate cases are worth pondering. If <code>p = 1</code> the curvature constraint is nullified and the smoothing cubic spline then passes through all data points resulting in an interpolation spline. In other words, with <code>p = 1</code> we have reverted back to a natural cubic spline solution. If <code>p = 0</code> only the curvature of the spline is minimized. Therefore we are minimizing the mean squared error over linear functions resulting in a linear (straight-line) least squares fit. A few smoothing cubic splines are shown below demonstrating the effect of various choices of <code>p</code>.</p>
<h2>Smoothing Cubic Splines C# code example.</h2>
<p>The NMath library currently supports two spline classes for natural and clamped splines. The class <code>SmoothCubicSpline</code> is not currently released but will be available in the spring 2014 release of NMath 6.0. If you have a need for this class before our next release, please contact us.</p>
<table border="1" cellspacing="0" cellpadding="5">
<colgroup>
<col style="width: 35%;" span="1" /></colgroup>
<colgroup>
<col style="width: 65%;" span="1" /></colgroup>
<tbody>
<tr bgcolor="#dddddd">
<th>
<div class="CellHeading">NMath Class Name</div>
</th>
<th>
<div class="CellHeading">Description</div>
</th>
</tr>
<tr>
<td>
<div class="CellBody"><a href="https://www.centerspace.net/doc/NMath/ref/html/T_CenterSpace_NMath_Core_NaturalCubicSpline.htm"><code>NaturalCubicSpline</code></a></div>
</td>
<td>
<div class="CellBody">Natural cubic spline</div>
</td>
</tr>
<tr>
<td>
<div class="CellBody"><a href="https://www.centerspace.net/doc/NMath/ref/html/T_CenterSpace_NMath_Core_ClampedCubicSpline.htm"><code>ClampedCubicSpline</code></a></div>
</td>
<td>
<div class="CellBody">Clamped cubic spline</div>
</td>
</tr>
<tr>
<td>
<div class="CellBody"><a href="https://www.centerspace.net/doc/NMath/ref/html/T_CenterSpace_NMath_Core_SmoothCubicSpline.htm"><code>SmoothCubicSpline</code></a></div>
</td>
<td>
<div class="CellBody">Smoothing cubic spline</div>
</td>
</tr>
</tbody>
</table>
<p>The following example code creates a noisy sinusoid signal then generates a smoothing cubic spline fit and finally charts the results.</p>
<pre lang="csharp">   // Build a noisy signal to fit with the smooth cubic spline.
   var numPoints = 64;
   x = new DoubleVector( numPoints, 0, 2.0 * Math.PI / ( numPoints - 1.0 ) );
   yNoisy = new DoubleVector( numPoints );
   RandGenUniform rng = new RandGenUniform( 0x162 );
   for ( int i = 0; i &lt; x.Length; i++ )
   {
     yNoisy[i] = ( 2.3 * Math.Cos( 3.0 * x[i] ) + 
                   1.2 * Math.Sin( 4.5 * x[i] ) + 
                   Math.Cos( 1.92 * x[i] ) ) + rng.Next();
   }

   // Compute the cubic smoothing spline.
   double p = 0.75;
   SmoothCubicSpline spline = new SmoothCubicSpline( x, yNoisy, p );

   // Chart the noisy signal and smoothing spline.
   var numInterpolatedValues = 512;
   var chart = NMathChart.ToChart( spline, numInterpolatedValues );
   chart.Titles.Add( String.Format( "Smoothed Cubic Spline with P = {0}", p.ToString() ) );
   chart.Series[0].Name = "Noisy Data";
   chart.Series[1].Name = "Spline";

   NMathChart.Show( chart );
</pre>
<p>The above code was used to generate the following four charts which compare cubic spline fits of the same dataset with different weighting factors. The four weighting factors used were <code>p = 0.05, 0.5, 0.75, 0.98</code>.</p>
<table>
<tbody>
<tr>
<td><a href="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip3.png"><img decoding="async" class="alignnone size-full wp-image-4832" src="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip3.png" alt="Smoothing cubic spline" width="300" srcset="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip3.png 509w, https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip3-150x150.png 150w, https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip3-300x298.png 300w" sizes="(max-width: 509px) 100vw, 509px" /></a></td>
<td><a href="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip4.png"><img decoding="async" class="alignnone size-full wp-image-4835" src="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip4.png" alt="Smoothing cubic spline" width="300" srcset="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip4.png 509w, https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip4-150x150.png 150w, https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip4-300x298.png 300w" sizes="(max-width: 509px) 100vw, 509px" /></a></td>
</tr>
<tr>
<td><a href="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip5.png"><img decoding="async" class="alignnone size-full wp-image-4837" src="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip5.png" alt="Smoothing cubic spline" width="300" srcset="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip5.png 509w, https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip5-150x150.png 150w, https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip5-300x298.png 300w" sizes="(max-width: 509px) 100vw, 509px" /></a></td>
<td><a href="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip6.png"><img decoding="async" class="alignnone size-full wp-image-4838" src="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip6.png" alt="Smoothing cubic spline" width="300" srcset="https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip6.png 509w, https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip6-150x150.png 150w, https://www.centerspace.net/wp-content/uploads/2013/10/ScreenClip6-300x298.png 300w" sizes="(max-width: 509px) 100vw, 509px" /></a></td>
</tr>
</tbody>
</table>
<p>It&#8217;s worth noting that if you need to filter uniformly sampled data Savitzky-Golay filters work similarly to a cubic smoothing spline by fitting piecewise continuous polynomials to the data. To more learn about Savitzky-Golay filtering have a look at our <a href="/savitzky-golay-smoothing/">blog</a> article.</p>
<p>-Happy Computing,</p>
<p>Paul Shirkey</p>
<p><em> References </em><br />
P. Craven and G. Wahba, &#8220;Smoothing Noisy Data with Spline Functions&#8221;, Numerische Mathematik, vol. 31, pp. 377-403, 1979.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/smoothing-cubic-splines">Smoothing Cubic Splines</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/smoothing-cubic-splines/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4712</post-id>	</item>
		<item>
		<title>Nevron Partnership</title>
		<link>https://www.centerspace.net/nevron-partnership</link>
					<comments>https://www.centerspace.net/nevron-partnership#respond</comments>
		
		<dc:creator><![CDATA[Paul Shirkey]]></dc:creator>
		<pubDate>Wed, 31 Mar 2010 16:00:57 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Corporate]]></category>
		<category><![CDATA[charting with NMath]]></category>
		<category><![CDATA[data smoothing]]></category>
		<category><![CDATA[data visualization]]></category>
		<category><![CDATA[linear regression]]></category>
		<category><![CDATA[math charts]]></category>
		<category><![CDATA[Nevron Partnership]]></category>
		<category><![CDATA[polyfit]]></category>
		<category><![CDATA[process control charts]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=1903</guid>

					<description><![CDATA[<p><img src="https://www.centerspace.net/blog/wp-content/uploads/2010/03/Nevron_ex1_polyfit-300x216.png" alt="" title="Fitting a polynomial to some sample data."  class="excerpt" />  All of us at CenterSpace software are proud to announce a partnership with <a href="http://www.nevron.com">Nevron</a>, leaders in data visualization.   Nevron builds .NET components which enable developers to quickly build clean, enterprise quality, user interfaces incorporating well rendered maps, gauges, diagrams, or charts.  Check out our <a href="https://www.centerspace.net/partners/nevron" >partnership page</a> for more information and free examples.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/nevron-partnership">Nevron Partnership</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>All of us at CenterSpace software are proud to announce a partnership with <a href="https://www.nevron.com">Nevron</a>, leaders in data visualization.  <img decoding="async" loading="lazy" src="https://www.centerspace.net/blog/wp-content/uploads/2010/03/NevronChartArt.jpg" alt="Nevron Chart Visualizations" title="NevronChartArt" width="308" height="239" class="alignright size-full wp-image-1905" srcset="https://www.centerspace.net/wp-content/uploads/2010/03/NevronChartArt.jpg 308w, https://www.centerspace.net/wp-content/uploads/2010/03/NevronChartArt-300x232.jpg 300w" sizes="(max-width: 308px) 100vw, 308px" /> Nevron builds .NET components which enable developers to quickly build clean, enterprise quality, user interfaces incorporating well rendered maps, gauges, diagrams, or charts.  Nevron has built it&#8217;s visualization framework with the developer in mind and has created components that are powerful, yet quick to pick up and work with.  </p>
<h3> Free Project Examples </h3>
<p>As part of of this partnership our software engineers are working together to develop a series of example applications to help our customers quickly become productive using our tool set.  Our first example demonstrates how to use the Nevron .NET chart component with some of NMath Stat&#8217;s fundamental capabilities: regression and prediction, polynomial curve fitting, and data smoothing.  <a href="https://www.centerspace.net/blog/wp-content/uploads/2010/03/Nevron_ex1_polyfit.png"><img decoding="async" loading="lazy" src="https://www.centerspace.net/blog/wp-content/uploads/2010/03/Nevron_ex1_polyfit-300x216.png" alt="" title="Fitting a polynomial to some sample data." width="300" height="216" class="alignleft size-medium wp-image-1907" srcset="https://www.centerspace.net/wp-content/uploads/2010/03/Nevron_ex1_polyfit-300x216.png 300w, https://www.centerspace.net/wp-content/uploads/2010/03/Nevron_ex1_polyfit.png 788w" sizes="(max-width: 300px) 100vw, 300px" /></a> To build and run this example, you&#8217;ll need to download this VS8 project, along with evaluation copies of the CenterSpace NMath Suite and the Nevron .NET Chart package. All of this is freely available from our <a href="/nevron-partnership/">partnership page</a>.</p>
<p>As I mentioned this is the first in a series of examples that we will be jointly developing.  Our next example application is in the planning stages, and will cover the building of common charts in statistical process control.  Statistical process control is employed across many industries ranging from manufacturing to medicine and has been an area of interest by customers of both companies.  We&#8217;ll post up a blog article about the example once it&#8217;s finished and you&#8217;ll see a tweet about it if you are <a href="https://twitter.com/CenterSpaceSoft">following us</a>.  </p>
<p>If you have an idea for an example using Nevon&#8217;s and CenterSpace&#8217;s tools together, which would help speed along your own project, leave a comment or drop us an email.   We just may cook it up!</p>
<h3> Discount Bundle </h3>
<p>As part of our partnership with Nevron, we are able to offer a substantial discount on package licenses.  If you are interested, please email our <a href="mailto:sales@centerspace.net">sales</a> staff and request the Nevron partnership discount.</p>
<p>Thanks for reading,</p>
<p><em>-The CenterSpace Team</em><br />
<br />
<b> Resources </b></p>
<ul>
<li>CenterSpace partnership information <a href="/nevron-partnership/">partnership page</a>.
<li>Nevron technology partnership information <a href="https://www.nevron.com/company-partners-technology-partners.aspx">page</a>.
<li>Nevron&#8217;s .NET Chart <a href="https://www.nevron.com/products-dot-net-chart-overview.aspx"> home page</a>.
</ul>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/nevron-partnership">Nevron Partnership</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/nevron-partnership/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1903</post-id>	</item>
		<item>
		<title>Savitzky-Golay Smoothing in C#</title>
		<link>https://www.centerspace.net/savitzky-golay-smoothing</link>
					<comments>https://www.centerspace.net/savitzky-golay-smoothing#comments</comments>
		
		<dc:creator><![CDATA[Paul Shirkey]]></dc:creator>
		<pubDate>Mon, 09 Nov 2009 19:45:58 +0000</pubDate>
				<category><![CDATA[Statistics]]></category>
		<category><![CDATA[data smoothing]]></category>
		<category><![CDATA[data smoothing in c#]]></category>
		<category><![CDATA[experimental data smoothing]]></category>
		<category><![CDATA[Savitzky-Golay]]></category>
		<category><![CDATA[Savitzky-Golay .NET]]></category>
		<category><![CDATA[Savitzky-Golay coefficients]]></category>
		<category><![CDATA[Savitzky-Golay in C#]]></category>
		<category><![CDATA[Savitzky-Golay in VB]]></category>
		<category><![CDATA[Savitzky-Golay smoothing]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=547</guid>

					<description><![CDATA[<p>Savitzky-Golay smoothing effectively removes local signal noise while preserving the shape of the signal. Commonly, it&#8217;s used as a preprocessing step with experimental data, especially spectrometry data because of it&#8217;s effectiveness at removing random variation while minimally degrading the signal&#8217;s information content. Savitzky-Golay boils down to a fast (multi-core scaling) correlation operation, and therefore can [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/savitzky-golay-smoothing">Savitzky-Golay Smoothing in C#</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Savitzky-Golay smoothing effectively removes local signal noise while preserving the shape of the signal.  Commonly, it&#8217;s used as a preprocessing step with experimental data, especially spectrometry data because of it&#8217;s effectiveness at removing random variation while minimally degrading the signal&#8217;s information content.  Savitzky-Golay boils down to a fast (multi-core scaling) correlation operation, and therefore can be used in a real-time environment or on large data sets efficiently.  If higher order information is needed from the signal, Savitzky-Golay can also provide high quality smoothed derivatives of a noisy signal.</p>
<h3>Algorithm</h3>
<p>Savitzky-Golay locally smooths a signal by fitting a polynomial, in a least squares sense, to a sliding window of data.  The degree of the polynomial and the length of the sliding window are the filter&#8217;s two tuning parameters.  If <code>n</code> is the degree of the polynomial that we are fitting, and <code>k</code> is the width of the sliding window, then<br />
<center><br />
<img decoding="async" title="n &lt; k - 1" src="http://latex.codecogs.com/gif.latex?n &lt; k - 1" alt="" /><br />
</center><br />
is needed for smoothing behavior (we must avoid an over-determined system).  Typically <code>n</code> is 3 or 4, and <code>k</code> depends on the size in samples of the noisy features to be suppressed in your data set.  </p>
<p>For the case of <code>n=0</code> the Savitzy-Golay filter degenerates to a moving average filter &#8211; which is good for removing white noise, but is poor for preserving peak shape (higher order moments).  For <code>n=1,</code> the filter does a linear least-squares fit of the windowed data to a line.  If <code>n=k-1,</code> the polynomial exactly fits data point in the window, and so no filtering takes place.</p>
<p>Once the polynomial is fit, then (typically) the center data-point in this window is replaced by value of the polynomial at that location.  The window then slides to the right one sample and the process is repeated.</p>
<p>Savizky-Golay delivers the unexpected surprise that <em> the polynomial fitting coefficients are constant </em> for a given <code>n</code> and <code>k.</code>  This means that once we fix <code>n</code> and <code>k</code> for our filter, the Savizky-Golay polynomial fitting coefficients are computed once during setup and then used across the entire data set.  This is why Savizky-Golay is a high performance correlation filter.</p>
<h3>Comparison Example</h3>
<p>The following three images show some real experimental data and a comparison of two filtering algorithms.  The first image shows the raw data, the second image shows the effect of an averaging filter, and the last image demonstrates a Savitzky-Golay smoothing filter of length five.</p>
<figure id="attachment_604" aria-describedby="caption-attachment-604" style="width: 400px" class="wp-caption aligncenter"><img decoding="async" loading="lazy" class="aligncenter size-full wp-image-604" title="current_raw_data" src="https://www.centerspace.net/blog/wp-content/uploads/2009/11/current_raw_data.jpg" alt="Unsmoothed Data" width="400" height="316" /><figcaption id="caption-attachment-604" class="wp-caption-text">Raw Data</figcaption></figure>
<figure id="attachment_603" aria-describedby="caption-attachment-603" style="width: 400px" class="wp-caption aligncenter"><img decoding="async" loading="lazy" class="size-full wp-image-603" title="current_averaging_filter" src="https://www.centerspace.net/blog/wp-content/uploads/2009/11/current_averaging_filter.jpg" alt="Averaging Filter, Length 5" width="400" height="316" /><figcaption id="caption-attachment-603" class="wp-caption-text">Averaging Filter, Length 5</figcaption></figure>
<figure id="attachment_605" aria-describedby="caption-attachment-605" style="width: 400px" class="wp-caption aligncenter"><img decoding="async" loading="lazy" class="size-full wp-image-605" title="current_savitzky-golay5" src="https://www.centerspace.net/blog/wp-content/uploads/2009/11/current_savitzky-golay5.jpg" alt="Savitzky-Golay Smoothing, Length = 5" width="400" height="316" /><figcaption id="caption-attachment-605" class="wp-caption-text">Savitzky-Golay Smoothing, Length 5</figcaption></figure>
<p>The averaging filter introduces a large error into the location of the orange peak whereas Savitzky-Golay removes the noise while maintaining the peak location.  Computationally, they require identical effort.</p>
<h3>Savitzky-Golay Smoothing in C#</h3>
<p>The Savitzky-Golay smoothing filter is implemented in the NMath-Stats package as a generalized correlation filter.  Any filter coefficients can be used with this moving window filter, Savitzky-Golay coefficients are just one possibility.  The moving window filter also does not require the filtering to take place in the center of the sliding window; so when specifying the window, two parameters are required: number to the left, and number to the right of the filtered data point.</p>
<p>Here are the key software components.</p>
<p><code></p>
<ul>
<li> MovingWindowFilter.<br />
SavitzkyGolayCoefficients(nLeft, nRight, PolyDeg)</li>
<li> MovingWindowFilter(nLeft, nRight, Coefficients[])</li>
<li> MovingWindowFilter.Filter(data, boundary options)</li>
</ul>
<p></code><br />
The first is a static function for generating the Savizky-Golay coefficients, the second is the filtering class that takes the generated coefficients in the constructor.  The third is the method that does the Savitzky-Golay filtering by running a cross-correlation between the data the the saved coefficients.</p>
<p>Below is a complete code example to copy and experiment with your own data sets.  Only three lines of code are needed to build the filter and actually do the filtering.  The remaining code builds a synthetic noisy signal to filter and displays the results.</p>
<pre lang="csharp">
int nLeft = 2;
int nRight = 2;
int n = 3;

// Generate the coefficients.
DoubleVector c =
MovingWindowFilter.SavitzkyGolayCoefficients( nLeft, nRight, n );

// Build the filter of width: nLeft + nRight + 1
MovingWindowFilter filter =
  new MovingWindowFilter( nLeft, nRight, c );
Console.WriteLine( "Filter coeffs = " + filter.Coefficients );

// Generate a signal
DoubleVector x = new DoubleVector( 100, -5, .1 );
DoubleVector y = new DoubleVector( x.Length );
for ( int i = 0; i &lt; x.Length; i++ )
{
  double a = x[i];
  y[i] = 0.03*Math.Pow(a, 3) + 0.2*Math.Pow(a, 2) -.22*a + 0.5;
}
Console.WriteLine( "Smoothed signal = " + y );

RandGenUniform rng = new RandGenUniform(-1, 1, 0x124 );
for ( int i = 0; i &lt; y.Length; i++ )
{
  y[i] += rng.NextDouble();
}
Console.WriteLine( "x = " + x );
Console.WriteLine( "Noisy signal = " + y );

// Do the filtering.
DoubleVector z =
filter.Filter(y, MovingWindowFilter.BoundaryOption.PadWithZeros);
Console.WriteLine( "Signal filtered = " + z );

</pre>
<p><em>-Paul </em></p>
<h3>Addendum &#8211; Savitzky-Golay Coefficients</h3>
<p>If you want to quickly try out Savitzky-Golay smoothing without computing the coefficients, or just compare coefficients, here are some coefficients for a sliding window of length five.  They also provide some insight into the relationship between the coefficients and the behavior of the filter.</p>
<pre class="code">
Filter length = 5, nLeft = 2, nRight = 2.
Polynomial of order 0,
[ 0.2 0.2 0.2 0.2 0.2 ]  (averaging filter)
Polynomial of order 1,
[ 0.2 0.2 0.2 0.2 0.2 ]
Polynomial of order 2,
[ -0.0857142 0.3428571 0.4857142 0.3428571 -0.0857142 ]
Polynomial of order 3,
[ -0.0857142 0.3428571 0.4857142 0.3428571 -0.0857142 ]
Polynomial of order 4 and higher,
[ 0 0 1 0 0 ]  (as expected, no filtering here!)
</pre>
<table border="0">
<tbody></tbody>
</table>
<h3>Another Smoothing Example on Real Data</h3>
<p>This is another example of Savitzky-Golay smoothing on some experimental data.  If more smoothing was desired, a longer filtering window could have been used.</p>
<figure id="attachment_602" aria-describedby="caption-attachment-602" style="width: 367px" class="wp-caption alignnone"><img decoding="async" loading="lazy" class="size-full wp-image-602" title="blue_rawdata_savitzky_golay5" src="https://www.centerspace.net/blog/wp-content/uploads/2009/11/blue_rawdata_savitzky_golay5.jpg" alt="Savitzky-Golay Smoothing Example, Length = 5." width="367" height="778" /><figcaption id="caption-attachment-602" class="wp-caption-text">Savitzky-Golay Smoothing, Length = 5.</figcaption></figure>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/savitzky-golay-smoothing">Savitzky-Golay Smoothing in C#</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/savitzky-golay-smoothing/feed</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">547</post-id>	</item>
	</channel>
</rss>
