5
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Commented Mar 9, 2012 at 14:24

2 Answers 2

9
$\begingroup$

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:

http://reference.wolfram.com/mathematica/Compatibility/tutorial/WaveletExplorer.html

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];
Manipulate[
 tmp = WaveletThreshold[
   WaveletBestBasis[dwd, {"Threshold", bestBasisThreshold}], {"Hard", 
    waveletThreshold}];
 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.

$\endgroup$
1
  • $\begingroup$ Thank you Vitaliy but actually the stress in my question was on zero decomposition level, as seen DiscreteWaveletPacketTransform [data, filter, 0] $\endgroup$
    – K-1
    Commented Apr 24, 2012 at 4:35
5
$\begingroup$

Perhaps this helps:

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

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

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

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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