Table of Content
Search clouds
Licenses
Author's resources
A wavelet is a wave-like oscillation with an amplitude that begins at zero, increases, and then decreases back to zero. It can typically be visualized as a "brief oscillation" like one might see recorded by a seismograph or heart monitor. Generally, wavelets are purposefully crafted to have specific properties that make them useful for signal processing.
A good introduction to wavelets is given here. Below we show how to use wavelets using the “jsci” package which is incorporated into the the core of the SCaVis 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.
1: # Signal Processing | P | 1.7 | S.Chekanov | Fast Wavelet Transform (FWT) of input data 2: 3: from jhplot import * 4: from java.util import Random 5: from java.awt import Color 6: 7: c1 = HPlot("Canvas",600,400) 8: c1.setNameX("X") 9: c1.setNameY("Y") 10: c1.visible(1) 11: c1.setAutoRange() 12: 13: p1 = P0D("Input data") 14: rand = Random(); 15: for i in range(100): 16: x=10*rand.nextGaussian() 17: p1.add(x) 18: print p1.toString() 19: 20: h1=p1.getH1D(50,-10,10) 21: c1.draw(h1) 22: 23: ######### do wavelets 24: from jsci.maths import * 25: from jsci.maths.wavelet import * 26: from jsci.maths.wavelet.daubechies2 import * 27: 28: ondelette = Daubechies2() 29: signal =Signal(p1.getArray()) 30: 31: signal.setFilter(ondelette) # transform 32: level = 1 # for some level int 33: sCoef = signal.fwt(level) # get coefficients from Fast Wavelet Transform 34: p2=P0D("Coefs0",sCoef.getCoefs()[0]) 35: p3=P0D("Coefs1",sCoef.getCoefs()[1]) 36: signalBack=P0D("Signal back", sCoef.rebuildSignal(ondelette).evaluate(0)) 37: 38: h3=signalBack.getH1D(50,-10,10) # get the signal back 39: h3.setColor(Color.red) 40: c1.draw(h3)
You will see 2 identical histograms. Please refer the package jsci.maths.wavelet.