Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For finding location of spikes in a time series I used to transform the data into wavelet space using

DiscreteWaveletPacketTransform [ data, filter, 0] 

and then shrink the basis using the universal threshold in Mathematica version 7 and now every single command, corresponding to wavelets, is changed in version 8.

Is there anybody who can tell me how can I do in version 8 again? I guess I need to use WaveletBestBasis command, but how?

share|improve this question

migrated from Mar 9 '12 at 12:45

This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.

From the docs it seems this function was not available in version 7. If you were using the Wavelet Explorer add-on in version 7, this guide should help in finding the equivalent commands. – Szabolcs Mar 9 '12 at 14:24

After consulting a friend of mine P.M. I can tell you this. First of all as @Szabolcs @ruebenko already mentions - in order to get a comparison with Wavelet explorer (v7) to v8, you can go to the following link in the documentation center which shows how the syntax has changed:

For the problem at hand, if you want location of the spike, perhaps using continuous wavelet transform might give the result easily. Here is an example:

data = N@Table[Sin[4 \[Pi] t] + 2 Exp[-10^5 (1/3 - t)^2], {t, 0, 1, 0.001}];
cwd = ContinuousWaveletTransform[data, PaulWavelet[5], {8, 8}];
ws = WaveletScalogram[cwd, ColorFunction -> "AvocadoColors"];
posData = Abs[{3, 1} /. cwd[{3, 1}]];
positionOfSpike = Position[posData, Max[posData]];
Print["Spike is at  " <> ToString[positionOfSpike[[1, 1]]]]
Row[{ws, ListLinePlot[posData, PlotRange -> All]}]

enter image description here

However, for multiple spikes, he may have to make careful use of a local FindMaximum. Another useful thing is this:

data = N@Table[
    Sin[4 \[Pi] t] + 2 Exp[-10^5 (1/3 - t)^2], {t, 0, 1, 0.001}];
dwd = DiscreteWaveletPacketTransform[data, Automatic, 5];
 tmp = WaveletThreshold[
   WaveletBestBasis[dwd, {"Threshold", bestBasisThreshold}], {"Hard", 
 recon = InverseWaveletTransform[tmp];
 GraphicsRow[{ListLinePlot[recon, PlotLabel -> "Reconstruction"], 
   ListLinePlot[data - recon, PlotLabel -> "Error"]}, 
  ImageSize -> 500], {bestBasisThreshold, 0.001, 0.99, 
  Appearance -> "Labeled"}, {waveletThreshold, 0.001, 0.99, 
  Appearance -> "Labeled"}]

enter image description here

The manipulate above shows the interplay between wavelet best basis and wavelet threshold. For more information, we would recommend going to the documentation page:

WaveletBestBasis > Applications > Compressions.

and go through the examples.

share|improve this answer
Thank you Vitaliy but actually the stress in my question was on zero decomposition level, as seen DiscreteWaveletPacketTransform [data, filter, 0] – K-1 Apr 24 '12 at 4:35

Perhaps this helps:

(* data *)
data = Table[Sin[4 \[Pi] t] + RandomReal[0.1], {t, 0., 1, 1/2^9}];
data[[200]] = 1.5;

(* fourier based *)
dft = Fourier[data];
fdft = Chop[dft, 0.2];
ftdata = InverseFourier[fdft];

(* wavelet based *)
dwt = DiscreteWaveletTransform[data, DaubechiesWavelet[4]];
fdwt = WaveletThreshold[dwt];
wtdata = InverseWaveletTransform[fdwt];

Also, have a look at the upgrading tutorial: Compatibility/tutorial/WaveletExplorer

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.