VB SWT Example

← All NMath Code Examples

 

Imports System
Imports System.Globalization
Imports System.Threading
Imports System.Text

Imports CenterSpace.NMath.Core


Namespace CenterSpace.NMath.Examples.VisualBasic

  A .NET example in Visual Basic showing how to use the Stationary Wavelet Transform (SWT) classes.
  Module SWTExample

    Sub Main()

      This section shows to use various configuration settings. All of these settings can
      also be set via configuration file or by environment variable. More on this at: 
      http://www.centerspace.net/blog/nmath/nmath-configuration/

      For NMath to continue to work after your evaluation period, you must set your license 
      key. You will receive a license key after purchase. 
      More here:
      http://www.centerspace.net/blog/nmath/setting-the-nmath-license-key/
      NMathConfiguration.LicenseKey = "<key>"

      This will start a log file that you can use to ensure that your configuration is 
      correct. This can be especially useful
      for deployment. Please turn this off when you are convinced everything is 
      working. If you arent sure, please send the resulting log file to 
      support@centerspace.net. Please note that this directory can be relative or absolute.
      NMathConfiguration.LogLocation = "<dir>"
      
      NMath loads native, optimized libraries at runtime. There is a one-time cost to 
      doing so. To take control of when this happens, use Init(). If your program calls 
      Init() successfully, then your configuration is definitely correct.
      NMathConfiguration.Init()	  

      Console.WriteLine()

       ' SWT of a signal using the Harr wavelet.

      ' Test input signal
      Dim signal As New DoubleVector("1, 2, 3, 56, 40, 8, 2, 40, 16")

      ' Build the class 
      Dim swt As New DoubleSWT(signal.ToArray(), New DoubleWavelet(DoubleWavelet.Wavelets.Harr))

      ' Find the maximum level of decomposition for this signal And wavelet pair
      Dim maximumDecompLevel As Integer = swt.MaximumDecompLevel()

      ' Using the SWT now decompose the signal to the maximum level, all of the detail And approximations are returned in a Tuple<>
      swt.Decompose(maximumDecompLevel)

      ' The SWT approximations at level 2
      Dim approxLevel2 As Double() = swt.WaveletCoefficients(DiscreteWaveletTransform.WaveletCoefficientType.Approximation, 2)

      ' The SWT details at level 2
      Dim detailsLevel2 As Double() = swt.WaveletCoefficients(DiscreteWaveletTransform.WaveletCoefficientType.Details, 2)

      ' Reconstruct the original signal
      Dim rsignal = swt.Reconstruct()

      Console.WriteLine()
      Console.WriteLine("SWT signal decomposition and reconstruction example using the Harr wavelet.")
      Console.WriteLine(String.Format("Original Signal: {0}", Signal.ToString("#.##")))
      Console.WriteLine(String.Format("SWT Approximation level 2: {0}", New DoubleVector(approxLevel2).ToString("#.##")))
      Console.WriteLine(String.Format("SWT Details level 2: {0}", New DoubleVector(detailsLevel2).ToString("#.##")))
      Console.WriteLine(String.Format("ISWT, Reconstructed signal: {0}", New DoubleVector(rsignal).ToString("#.##")))

      Console.WriteLine()
      Console.WriteLine("Finished. Press Enter Key.")
      Console.Read()

    End Sub
  End Module
End Namespace

← All NMath Code Examples
Top