# Wavelet transform of data with sliders

I saw a beautiful application of wavelets applied to a randomly created data series of about 500 data points. It used the Haar wavelet and had two sliders. The first slider allowed the user to view a smooth transition from the most coarse Haar approximation to the most refined. The second allowed the user to progressively detrend the data. Both can be used together. The application did not show the code. It is clear to me that manipulate was used to creat the sliders, but that's all I can get from it as a new user of Mathematica. I'm not sure how to create these sliders for this application (i.e., how to access the individual waveforms that when added together reconstruct the data). I have used manipulate with sliders successfully for other applications, such as for approximating a price series with a log periodic cosine function.

• And the question is ... Jan 1, 2015 at 12:42
• Maybe browse some of the results of this: ?*Wavelet* and try to ask a specific question. Jan 1, 2015 at 13:46
• Point us to the demonstration (online?) and we'll try to generate code that would produce it. Jan 1, 2015 at 17:55
• David, here is the source of my question:youtube.com/watch?v=PUUSMXdBdTQ&spfreload=10 Jan 2, 2015 at 14:05
• Sjoerd, I did a fair amount of research as you mention. I thought I could just add a parameter inside the brackets of HaarWavelet(),and add a range of values, say .001 to .99, using manipulate, but I really don't no how to "get inside" the HaarWavelet function to do this. I didn't find that the documentation for wavelets aided me with this, though I copied, pasted, and attempted to modify code from Wolfram demonstrations. I've also made an effort to understand the underlying math of the Haar wavelet in particular. Jan 2, 2015 at 14:17

I won't catch the fish for you rather than teach you how to do it.

Generate a random data set:

data = LowpassFilter[Accumulate@Re@Fourier[Table[RandomReal[{-.5, .5}]
Sinh[Exp[RandomReal[{-.5, .5}]^2]], {2^10}]], .4];


and transform it

dwd = DiscreteWaveletTransform[data, HaarWavelet[]]
swd = StationaryWaveletTransform[data, HaarWavelet[]]


We will compare two different ways to detrend the set

ListLinePlot[data - .93 (Last[swd[Automatic, "Values"]])[[1]]]


The coefficient .93 is sometimes used when correcting the background drift in analytical chemistry, but feel free to experiment.

And now the other one

ListLinePlot@InverseWaveletTransform[WaveletMapIndexed[#1 0.0 &, dwd, {___, 0}]]


You mentioned that you need to see the different approximations (levels) of the transform.

Manipulate[ListLinePlot[dwd[{HaarApproximation}, "Values"]],
{HaarApproximation, First /@ dwd[{___, 0}]}]


• +1 for answering a question which has not yet been asked :-) Jan 1, 2015 at 19:23
• @chris Appreciate it :) Jan 1, 2015 at 19:36
• Sektor, many thanks for your impressive response! I can see that I have a lot to learn in Mathematica syntax. See the URL above where I got the inspiration to try this. You can see how the video is using sliders. I tried to contact the author to see if he would give me his code but had no luck contacting him (no email address). I tried cutting and pasting from several Wolfram demonstrations with no success. My understanding from stock trading is that the detrending means giving the data a mean of zero. Jan 2, 2015 at 14:11
• No worries, I love working with wavelets :) Don't be afraid of the learning curve it is really not that horrible :D To get a mean closer to 0 you can just do this data - Mean[data]. Of course when working with wavelets you can be more precise when you de-trend. Jan 2, 2015 at 14:51