# DMelt:DSP/4 Wavelets

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Member

# Wavelets

Wavelets are mathematical functions that decompose data into different frequency components and then study each component with a resolution matched to its scale. A good introduction to wavelets is given Wavelet article. Below we show how to use wavelets using the "jsci" package which is incorporated into the the core of the DataMelt package.

In this example we will create a 1D vector of Gaussian numbers and transform using Fast Wavelet Transform (daubechies 2). We convert the input array into a histogram for visualization. Then we extract coefficients and convert the signal back. Then we compare the original data with the converted ones.

from jhplot  import *
from java.util import Random
from java.awt  import Color

c1 = HPlot("Canvas",600,400)
c1.setNameX("X")
c1.setNameY("Y")
c1.visible(1)
c1.setAutoRange()

p1 = P0D("Input data")
rand = Random()
for i in range(100):
x=10*rand.nextGaussian()
print p1.toString()

h1=p1.getH1D(50,-10,10)
c1.draw(h1)

#########  do wavelets
from jsci.maths import *
from jsci.maths.wavelet import *
from jsci.maths.wavelet.daubechies2 import *

ondelette = Daubechies2()
signal =Signal(p1.getArray())

signal.setFilter(ondelette) # transform
level = 1 # for some level int
sCoef = signal.fwt(level) # get coefficients from Fast Wavelet Transform
p2=P0D("Coefs0",sCoef.getCoefs()[0])
p3=P0D("Coefs1",sCoef.getCoefs()[1])
signalBack=P0D("Signal back", sCoef.rebuildSignal(ondelette).evaluate(0))

h3=signalBack.getH1D(50,-10,10) #  get the signal back
h3.setColor(Color.red)
c1.draw(h3)

You will see 2 identical histograms. Please refer the package jsci.maths.wavelet.