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.
1 Answer
$\begingroup$
$\endgroup$
4
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}]}]
-
$\begingroup$ +1 for answering a question which has not yet been asked :-) $\endgroup$– chrisCommented Jan 1, 2015 at 19:23
-
-
$\begingroup$ 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. $\endgroup$– jrabbitCommented Jan 2, 2015 at 14:11
-
$\begingroup$ 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 thisdata - Mean[data]
. Of course when working with wavelets you can be more precise when you de-trend. $\endgroup$– SektorCommented Jan 2, 2015 at 14:51
?*Wavelet*
and try to ask a specific question. $\endgroup$