<?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>wavelets Archives - CenterSpace</title>
	<atom:link href="https://www.centerspace.net/tag/wavelets/feed" rel="self" type="application/rss+xml" />
	<link>https://www.centerspace.net/tag/wavelets</link>
	<description>.NET numerical class libraries</description>
	<lastBuildDate>Mon, 11 Jun 2018 20:20:47 +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>Filtering with Wavelet Transforms</title>
		<link>https://www.centerspace.net/wavelet-transforms</link>
					<comments>https://www.centerspace.net/wavelet-transforms#respond</comments>
		
		<dc:creator><![CDATA[Paul Shirkey]]></dc:creator>
		<pubDate>Fri, 18 Dec 2015 17:00:25 +0000</pubDate>
				<category><![CDATA[NMath Tutorial]]></category>
		<category><![CDATA[DWT]]></category>
		<category><![CDATA[ECG filtering]]></category>
		<category><![CDATA[filtering]]></category>
		<category><![CDATA[filtering with wavelets]]></category>
		<category><![CDATA[mass spec filtering]]></category>
		<category><![CDATA[wavelet filtering]]></category>
		<category><![CDATA[wavelets]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=5713</guid>

					<description><![CDATA[<p><img class="excerpt" src="https://www.centerspace.net/wp-content/uploads/2015/10/ec13.jpg" alt="ECG waveform" width="350" class="size-full wp-image-5819" /><br />
Wavelet transforms have found engineering applications in computer vision, pattern recognition, signal filtering and perhaps most widely in signal and image compression.  In 2000 the ISO JPEG committee proposed a new<br />
JPEG2000 image compression standard that is based on the wavelet transform using two Daubechies wavelets.  This standard made the relatively new image decomposition algorithm ubiquitous on desktop around the world. </p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/wavelet-transforms">Filtering with Wavelet Transforms</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Discrete time wavelet transforms have found engineering applications in computer vision, pattern recognition, signal filtering and perhaps most widely in signal and image compression.  In 2000 the ISO JPEG committee proposed a new JPEG2000 image compression standard that is based on the wavelet transform using two Daubechies wavelets.  This standard made the relatively new image decomposition algorithm ubiquitous on desktops around the world.  </p>
<p>In signal processing, wavelets have been widely investigated for use in filtering bio-electric signals, among many other applications.  Bio-electric signals are good candidates for multi-resolution wavelet filtering over standard Fourier analysis due to their non-stationary character.  In this article we&#8217;ll discuss the filtering of electrocardiograms or ECGs and demonstrate with code examples how to filter an ECG waveform using <strong>NMath</strong>&#8216;s new wavelet classes; keeping in mind that the techniques and code shown here apply to a wide class of time series measurements.  If wavelets and their applications to filtering are unfamiliar to the reader, read a gentle and brief introduction to the subject in <em>Wavelets for Kids: A Tutorial Introduction</em> <a href="#5">[5]</a>.</p>
<h2> Filtering a Time Series with Wavelets</h2>
<p><a href="http://www.physionet.org/">PhysioNet </a>provides free access to a large collections of recorded physiologic signals, including many ECG&#8217;s.  The ECG signal we will filter here, named <em>aami-ec13</em> on PhysioNet, is shown below.<br />
<figure id="attachment_5721" aria-describedby="caption-attachment-5721" style="width: 600px" class="wp-caption alignnone"><a href="https://www.centerspace.net/blog/wp-content/uploads/2015/03/ScreenClip.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2015/03/ScreenClip.png" alt="ECG Signal" width="600" class="size-full wp-image-5721" srcset="https://www.centerspace.net/wp-content/uploads/2015/03/ScreenClip.png 1090w, https://www.centerspace.net/wp-content/uploads/2015/03/ScreenClip-300x59.png 300w, https://www.centerspace.net/wp-content/uploads/2015/03/ScreenClip-1024x202.png 1024w" sizes="(max-width: 1090px) 100vw, 1090px" /></a><figcaption id="caption-attachment-5721" class="wp-caption-text">ECG Signal</figcaption></figure></p>
<p>Our goal will be to remove the high frequency noise while preserving the character of the wave form, including the high frequency transitions at the signal peaks.  Fourier based filter methods are ill suited for filtering this type of signal due to both it&#8217;s non-stationarity, as mentioned, but also the need to preserve the peak locations (phase) and shape.</p>
<h3> A Wavelet Filter </h3>
<p>As with Fourier analysis there are three basic steps to filtering signals using wavelets.</p>
<ol>
<li> <em>Decompose </em>the signal using the DWT.
<li> Filter the signal in the wavelet space using <em>thresholding</em>.
<li> Invert the filtered signal to <em>reconstruct </em>the original, now filtered signal, using the inverse DWT.
</ol>
<p>Briefly, the filtering of signals using wavelets is based on the idea that as the DWT decomposes the signal into <em>details </em>and <em>approximation </em> parts, at some scale the details contain mostly the insignificant noise and can be removed or zeroed out using thresholding without affecting the signal.  This idea is discussed in more detail in the introductory paper [5].  To implement this DWT filtering scheme there are two basic filter design parameters: the wavelet type and a threshold.  Typically the shape and form of the signal to be filtered is qualitatively matched to the general shape of the wavelet.  In this example we will use the Daubechies forth order wavelet.   </p>
<table>
<tr>
<td><figure id="attachment_5827" aria-describedby="caption-attachment-5827" style="width: 220px" class="wp-caption alignnone"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2015/10/Image.png" alt="ECG Signal closeup" width="200" class="alignnone size-full wp-image-5852" srcset="https://www.centerspace.net/wp-content/uploads/2015/10/Image.png 706w, https://www.centerspace.net/wp-content/uploads/2015/10/Image-300x226.png 300w" sizes="(max-width: 706px) 100vw, 706px" /><figcaption id="caption-attachment-5827" class="wp-caption-text">ECG Waveform</figcaption></figure></td>
<td><figure id="attachment_5827" aria-describedby="caption-attachment-5827" style="width: 220px" class="wp-caption alignnone"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2015/10/DB4.png" alt="Daubechies 4 wavelet" width="200" class="size-full wp-image-5827" srcset="https://www.centerspace.net/wp-content/uploads/2015/10/DB4.png 560w, https://www.centerspace.net/wp-content/uploads/2015/10/DB4-300x214.png 300w" sizes="(max-width: 560px) 100vw, 560px" /><figcaption id="caption-attachment-5827" class="wp-caption-text">Daubechies 4 wavelet</figcaption></figure></td>
</tr>
</table>
<p>The general shape of this wavelet roughly matches, at various scales, the morphology of the ECG signal.  Currently <strong>NMath </strong>supports the following wavelet families: Harr, Daubechies, Symlet, Best Localized, and Coiflet, 27 in all.  Additionally, any custom wavelet of your invention can be created by passing in the wavelet&#8217;s low &#038; high pass decimation filter values.  The wavelet class then imposes the wavelet&#8217;s symmetry properties to compute the reconstruction filters.</p>
<pre lang="csharp">
   // Build a Coiflet wavelet.
   var wavelet = new FloatWavelet( Wavelet.Wavelets.C4 );

   // Build a custom reverse bi-orthogonal wavelet.
   var wavelet = new DoubleWavelet( new double[] {0.0, 0.0, 0.7071068, 0.7071068, 0.0, 0.0}, new double[] {0.0883883, 0.0883883, -0.7071068, 0.7071068, -0.0883883, -0.0883883} );
</pre>
<p>The <code>FloatDWT</code> class provides four different thresholding strategies: Universal, UniversalMAD, Sure, and Hybrid (a.k.a SureShrink).  We&#8217;ll use the Universal threshold strategy here.  This is a good starting point but this strategy can over smooth the signal.  Typically some empirical experimentation is done here to find the best threshold for the data (see [1], also see [4] for a good overview of common thresholding strategies.)</p>
<h3> Wavelet Filtering Code</h3>
<p>The three steps outlined above are easily coded using two classes in the <b>NMath</b> library: the <code>FloatDWT</code> class and the <code>FloatWavelet</code> class.  As always in <b>NMath</b>, the library offers both a float precision and a double precision version of each of these classes.  Let&#8217;s look at a code snippet that implements a DWT based filter with <b>NMath</b>.</p>
<pre lang="csharp">
   // Choose wavelet, the Daubechies 4 wavelet
   var wavelet = new FloatWavelet( Wavelet.Wavelets.D4 );

   // Build DWT object using our wavelet & data
   var dwt = new FloatDWT( data, wavelet );

   // Decompose signal with DWT to level 5
   dwt.Decompose( 5 );

   // Find Universal threshold & threshold all detail levels
   double lambdaU = dwt.ComputeThreshold( FloatDWT.ThresholdMethod.Universal, 1 );
   dwt.ThresholdAllLevels( FloatDWT.ThresholdPolicy.Soft, new double[] { lambdaU, 
       lambdaU, lambdaU, lambdaU, lambdaU } );

   // Rebuild the filtered signal.
   float[] reconstructedData = dwt.Reconstruct();
</pre>
<p>The first two lines of code build the wavelet object and the DWT object using both the input data signal and the abbreviated Daubechies wavelet name <code>Wavelet.Wavelets.D4</code>.  The third line of code executes the wavelet decomposition at five consecutive scales.  Both the signal&#8217;s <em>details</em> and <em>approximations</em> are stored in the DWT object at each step in the decomposition.  Next, the <code>Universal</code> threshold is computed and the wavelet details are thresholded using the same threshold with a <code>Soft</code> policy (see [1], pg. 63).  Lastly, the now filtered signal is reconstructed.</p>
<p>Below, the chart on the left shows the unfiltered ECG signal and the chart on the right shows the wavelet filtered ECG signal.  It&#8217;s clear that this filter very effectively removed the noise while preserving the signal.</p>
<table>
<tr>
<td>
<figure id="attachment_5888" aria-describedby="caption-attachment-5888" style="width: 350px" class="wp-caption alignnone"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2015/10/Image2.png" alt="Raw ECG Signal" width="350" class="size-full wp-image-5888" srcset="https://www.centerspace.net/wp-content/uploads/2015/10/Image2.png 506w, https://www.centerspace.net/wp-content/uploads/2015/10/Image2-300x180.png 300w" sizes="(max-width: 506px) 100vw, 506px" /><figcaption id="caption-attachment-5888" class="wp-caption-text">Raw ECG Signal</figcaption></figure>
</td>
<td>
<figure id="attachment_5887" aria-describedby="caption-attachment-5887" style="width: 350px" class="wp-caption alignnone"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2015/10/Image1.png" alt="Filtered ECG Signal" width="350"  class="size-full wp-image-5887" srcset="https://www.centerspace.net/wp-content/uploads/2015/10/Image1.png 506w, https://www.centerspace.net/wp-content/uploads/2015/10/Image1-300x180.png 300w" sizes="(max-width: 506px) 100vw, 506px" /><figcaption id="caption-attachment-5887" class="wp-caption-text">Filtered ECG Signal</figcaption></figure></td>
</table>
<p>These two charts below show a detail from the chart above from indices 500 to 1000.  Note how well the signal shape, phase, and amplitude has been preserved in this non-stationary wavelet-filtered signal.</p>
<table>
<tr>
<td>
<figure id="attachment_5890" aria-describedby="caption-attachment-5890" style="width: 350px" class="wp-caption alignnone"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2015/10/Image4.png" alt="Detail Raw ECG Signal" width="350"  class="size-full wp-image-5890" srcset="https://www.centerspace.net/wp-content/uploads/2015/10/Image4.png 506w, https://www.centerspace.net/wp-content/uploads/2015/10/Image4-300x180.png 300w" sizes="(max-width: 506px) 100vw, 506px" /><figcaption id="caption-attachment-5890" class="wp-caption-text">Detail Raw ECG Signal</figcaption></figure>
</td>
<td>
<figure id="attachment_5889" aria-describedby="caption-attachment-5889" style="width: 350px" class="wp-caption alignnone"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2015/10/Image3.png" alt="Detail Filtered ECG Signal" width="350"  class="size-full wp-image-5889" srcset="https://www.centerspace.net/wp-content/uploads/2015/10/Image3.png 506w, https://www.centerspace.net/wp-content/uploads/2015/10/Image3-300x180.png 300w" sizes="(max-width: 506px) 100vw, 506px" /><figcaption id="caption-attachment-5889" class="wp-caption-text">Detail Filtered ECG Signal</figcaption></figure>
</td>
</table>
<p>It is this ability to preserve phase, form, and amplitude in DWT based filters all while having a O(n log n) runtime that Fourier-based filters enjoy that has made wavelets such an important part of signal processing today.  The complete code for this example along with a link to the ECG data is provided below.</p>
<p>Paul</p>
<h3> References </h3>
<div id="1">[1] Guomin Luo and Daming Zhang (2012). <em>Wavelet Denoising</em>, Advances in Wavelet Theory and Their Applications in Engineering, Physics and Technology, Dr. Dumitru Baleanu (Ed.), ISBN: 978-953-51-0494-0, InTech, pp. 59-80.  Available from: <a href="http://www.intechopen.com/books/advances-in-wavelet-theory-and-their-applicationsin-engineering-physics-and-technology/wavelet-denoising">http://www.intechopen.com/books/advances-in-wavelet-theory-and-their-applicationsin-engineering-physics-and-technology/wavelet-denoising</a> </div>
<div id="2">[2] Burhan Ergen (2012). <em>Signal and Image Denoising Using Wavelet Transform</em>, Advances in Wavelet Theory and Their Applications in Engineering, Physics and Technology, Dr. Dumitru Baleanu (Ed.), ISBN: 978-953-51-0494-0, InTech, DOI: 10.5772/36434.  Available from: <a href="http://www.intechopen.com/books/advances-in-wavelet-theory-and-their-applications-in-engineering-physics-and-technology/wavelet-signal-and-image-denoising">http://www.intechopen.com/books/advances-in-wavelet-theory-and-their-applications-in-engineering-physics-and-technology/wavelet-signal-and-image-denoising</a> </div>
<div id="3">[3] Rami Cohen: <em>Signal Denoising Using Wavelets</em>, Project Report, 2012.  Available from: <a href="https://pdfs.semanticscholar.org/3dfd/6b2bd3d6ad3c6eca50747e686d5ad88b4fc1.pdf">https://pdfs.semanticscholar.org/3dfd/6b2bd3d6ad3c6eca50747e686d5ad88b4fc1.pdf</a> </div>
<div id="4">[4] M. C. E. Rosas-Orea, M. Hernandez-Diaz, V. Alarcon-Aquino, and L. G. Guerrero-Ojeda, <em>A Comparative Simulation Study of Wavelet Based Denoising Algorithms</em>, Proceedings of the 15th International Conference on Electronics, Communications and Computers (CONIELECOMP 2005), 2005 © IEEE </div>
<div id="5">[5] Brani Vidakovic and Peter Mueller, <em>Wavelets for Kids: A Tutorial Introduction</em>, Duke University, 1991.  Available from: <a target="_blank" href="http://gtwavelet.bme.gatech.edu/wp/kidsA.pdf">http://gtwavelet.bme.gatech.edu/wp/kidsA.pdf</a> </div>
<h3> Test Data </h3>
<p>To copy the data file provided by <a href="http://www.physionet.org/">PhysioNet</a> for this example click: <a href="https://www.centerspace.net/blog/wp-content/uploads/2015/10/ECG_AAMIEC13.data_.txt">ECG_AAMIEC13.data</a><br />
This ECG data was taken from the ANSI EC13 test data set <a href="http://www.physionet.org/physiobank/database/aami-ec13/">waveforms</a>.</p>
<h3> Complete Test Code </h3>
<pre lang="csharp">

    public void BlogECGExample()
    {
      // Define your own dataDir
      var dataDir = "................";

      // Load ECG wave from physionet.org data file.
      string filename = Path.Combine( dataDir, "ECG_AAMIEC13.data.txt" );
      string line;
      int cnt = 0;
      FloatVector ecgMeasurement = new FloatVector( 3000 );
      var fileStrm = new System.IO.StreamReader( filename );
      fileStrm.ReadLine(); fileStrm.ReadLine();
      while ( ( line = fileStrm.ReadLine() ) != null && cnt < 3000 )
      {
        ecgMeasurement[cnt] = Single.Parse( line.Split( ',' )[1] );
        cnt++;
      }

      // Choose wavelet
      var wavelet = new FloatWavelet( Wavelet.Wavelets.D4 );

      // Build DWT object
      var dwt = new FloatDWT( ecgMeasurement.DataBlock.Data, wavelet );

      // Decompose signal with DWT to level 5
      dwt.Decompose( 5 );

      // Find Universal threshold &#038; threshold all detail levels with lambdaU
      double lambdaU = dwt.ComputeThreshold( FloatDWT.ThresholdMethod.Universal, 1 );
      dwt.ThresholdAllLevels( FloatDWT.ThresholdPolicy.Soft, new double[] { lambdaU, lambdaU, lambdaU, lambdaU, lambdaU } );

      // Rebuild the signal to level 1 - the original (filtered) signal.
      float[] reconstructedData = dwt.Reconstruct();

      // Display DWT results.
      BlogECGExampleBuildCharts( dwt, ecgMeasurement, reconstructedData );

    }

    public void BlogECGExampleBuildCharts( FloatDWT dwt, FloatVector ECGMeasurement, float[] ReconstructedData )
    {

      // Plot out approximations at various levels of decomposition.
      var approxAllLevels = new FloatVector();
      for ( int n = 5; n > 0; n-- )
      {
        var approx = new FloatVector( dwt.WaveletCoefficients( DiscreteWaveletTransform.WaveletCoefficientType.Approximation, n ) );
        approxAllLevels.Append( new FloatVector( approx ) );
      }

      var detailsAllLevels = new FloatVector();
      for ( int n = 5; n > 0; n-- )
      {
        var approx = new FloatVector( dwt.WaveletCoefficients( DiscreteWaveletTransform.WaveletCoefficientType.Details, n ) );
        detailsAllLevels.Append( new FloatVector( approx ) );
      }

      // Create and display charts.
      Chart chart0 = NMathChart.ToChart( detailsAllLevels );
      chart0.Titles.Add( "Concatenated DWT Details to Level 5" );
      chart0.ChartAreas[0].AxisY.Title = "DWT Details";
      chart0.Height = 270;
      NMathChart.Show( chart0 );

      Chart chart1 = NMathChart.ToChart( approxAllLevels );
      chart1.Titles.Add("Concatenated DWT Approximations to Level 5");
      chart1.ChartAreas[0].AxisY.Title = "DWT Approximations";
      chart1.Height = 270;
      NMathChart.Show( chart1 );

      Chart chart2 = NMathChart.ToChart( (new FloatVector( ReconstructedData ))[new Slice(500,500)] );
      chart2.Titles[0].Text = "Thresholded & Reconstructed ECG Signal";
      chart2.ChartAreas[0].AxisY.Title = "mV";
      chart2.Height= 270;
      NMathChart.Show( chart2 );

      Chart chart3 = NMathChart.ToChart( (new FloatVector( ECGMeasurement ))[new Slice(500,500)] );
      chart3.Titles[0].Text = "Raw ECG Signal";
      chart3.ChartAreas[0].AxisY.Title = "mV";
      chart3.Height = 270;
      NMathChart.Show( chart3 );

    }
</pre>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/wavelet-transforms">Filtering with Wavelet Transforms</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/wavelet-transforms/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">5713</post-id>	</item>
	</channel>
</rss>
