Last time, I asked how I can use the command DiscreteWaveletPacketTransform[data, filter, 0] for spike detection and I got answers mostly based on an automatically defined threshold. In my case it is crucial to first define a threshold to distinguish between the real and spurious data, so built-in functions are not my favorites.
I developed my own version of code but as I use a filter like Haar, there would be no difference between a spike on point 19 or 20, as this filter works inherently with pairs of numbers. Once again, in Mathematica version 7 using the above command I had no problem! I read the links given already but no use. That would be great if someone can enhance my code such that it can differentiate between two consecutive spikes.
data = Table[Sin[x] + Random[], {x, 1, 10, 0.1}]
data[[20]] = 100; data[[40]] = 100;

dwt = DiscreteWaveletTransform[data, HaarWavelet[], 1];
Sigma = Mean[ Abs[dwt[[1, 2]] - Mean[dwt[[1, 2]]]]]/0.6745;
Lambda = N[Sqrt[2 Log[Length[dwt[[1, 2]]]]]];
thresh = Lambda*Sigma;
shr[c_, wind_] := If[Abs[#] >= thresh, 1, 0] & /@ c;
dwtS = WaveletMapIndexed[shr, dwt]
ListLinePlot[InverseWaveletTransform[dwtS, HaarWavelet[]]]
