# Wavelet transform order problem

I have a signal that I'm trying to study its time-frequency features by continuous wavelet transform. By choosing different wavelet order, I get some differences in the results.

data={2.9014*10^-6,2.90163*10^-6,2.90184*10^-6,2.90199*10^-6,2.90211*10^-6,2.90227*10^-6,2.90256*10^-6,2.90306*10^-6,2.90371*10^-6,2.90441*10^-6,2.90497*10^-6,2.90531*10^-6,2.9055*10^-6,2.90578*10^-6,2.90646*10^-6,2.90772*10^-6,2.90945*10^-6,2.91123*10^-6,2.91259*10^-6,2.91325*10^-6,2.91343*10^-6,2.91381*10^-6,2.91522*10^-6,2.91808*10^-6,2.92209*10^-6,2.92617*10^-6,2.92908*10^-6,2.93018*10^-6,2.93004*10^-6,2.93033*10^-6,2.93297*10^-6,2.93891*10^-6,2.94732*10^-6,2.95574*10^-6,2.9614*10^-6,2.96299*10^-6,2.96185*10^-6,2.96162*10^-6,2.96628*10^-6,2.97767*10^-6,2.99387*10^-6,3.00976*10^-6,3.01981*10^-6,3.02167*10^-6,3.01827*10^-6,3.0168*10^-6,3.02483*10^-6,3.04546*10^-6,3.07459*10^-6,3.10242*10^-6,3.11891*10^-6,3.12028*10^-6,3.11252*10^-6,3.10893*10^-6,3.12272*10^-6,3.15854*10^-6,3.20828*10^-6,3.25426*10^-6,3.27939*10^-6,3.27836*10^-6,3.26281*10^-6,3.25606*10^-6,3.27983*10^-6,3.34039*10^-6,3.4223*10^-6,3.49512*10^-6,3.53107*10^-6,3.52363*10^-6,3.49457*10^-6,3.48331*10^-6,3.52429*10^-6,3.62491*10^-6,3.75702*10^-6,3.86957*10^-6,3.91859*10^-6,3.89724*10^-6,3.84478*10^-6,3.82651*10^-6,3.89594*10^-6,4.06072*10^-6,4.27145*10^-6,4.44408*10^-6,4.50948*10^-6,4.46164*10^-6,4.369*10^-6,4.33805*10^-6,4.45164*10^-6,4.71689*10^-6,5.05039*10^-6,5.31582*10^-6,5.40427*10^-6,5.31103*10^-6,5.15072*10^-6,5.09455*10^-6,5.2712*10^-6,5.68762*10^-6,6.20894*10^-6,6.61828*10^-6,6.74349*10^-6,6.57916*10^-6,6.30884*10^-6,6.20238*10^-6,6.4596*10^-6,7.09078*10^-6,7.88788*10^-6,8.51491*10^-6,8.70166*10^-6,8.43447*10^-6,7.9931*10^-6,7.79107*10^-6,8.13561*10^-6,9.04922*10^-6,0.0000102271,0.0000111668,0.0000114527,0.0000110468,0.0000103528,9.98182*10^-6,0.0000103954,0.0000116448,0.0000133079,0.0000146643,0.0000150967,0.000014515,0.000013469,0.0000128233,0.000013247,0.0000148457,0.0000170679,0.0000189313,0.0000195583,0.0000187682,0.0000172645,0.0000162108,0.0000165364,0.0000184334,0.0000212252,0.0000236427,0.0000245012,0.0000234839,0.0000214325,0.0000198316,0.000019909,0.0000219786,0.0000252636,0.0000282157,0.0000293231,0.0000280882,0.0000254475,0.0000231909,0.0000228567,0.0000249121,0.0000285254,0.0000319176,0.0000332699,0.0000318712,0.0000286827,0.000025737,0.000024859,0.0000266879,0.0000303991,0.0000340713,0.0000356473,0.0000341925,0.0000306028,0.0000270451,0.0000255658,0.0000269767,0.0000305281,0.0000342767,0.0000360407,0.000034684,0.0000309405,0.0000269673,0.00002493,0.0000257916,0.0000289396,0.0000325431,0.0000344431,0.0000333581,0.0000297724,0.0000256719,0.0000232159,0.0000234769,0.0000260252,0.0000292689,0.0000312323,0.0000305725,0.0000274598,0.0000235556,0.0000208833,0.0000205699,0.0000223903,0.0000250907,0.0000270255,0.0000268888,0.0000245043,0.0000210875,0.000018415,0.0000176113,0.0000186525,0.0000206803,0.0000224893,0.0000229019,0.000021395,0.0000186677,0.000016177,0.0000149982,0.0000152855,0.0000165867,0.0000181916,0.0000191149,0.000018512,0.0000165548,0.0000143599,0.0000129276,0.000012555,0.000013165,0.000014534,0.0000158876,0.0000160998,0.0000148657,0.0000129981,0.0000114223,0.0000105418,0.0000105894,0.0000117571,0.0000134455,0.0000142913,0.0000136192,0.0000120292,0.0000103999,9.20804*10^-6,8.90906*10^-6,9.98279*10^-6,0.0000119153,0.0000131483,0.0000127878,0.0000113584,9.74472*10^-6,8.47082*10^-6,8.11189*10^-6,9.26401*10^-6,0.0000113633,0.0000126963,0.0000123374,0.0000109064,9.3632*10^-6,8.25912*10^-6,8.17564*10^-6,9.62188*10^-6,0.0000118203,0.000012945,0.0000122487,0.0000106348,9.21487*10^-6,8.54772*10^-6,9.09781*10^-6,0.0000110663,0.0000132919,0.0000138925,0.0000125211,0.0000105526,9.32172*10^-6,9.36753*10^-6,0.0000109027,0.0000135961,0.0000157529,0.0000155162,0.0000131626,0.0000107069,9.75865*10^-6,0.0000107928,0.0000136236,0.0000171774,0.0000191241,0.0000177518,0.0000141711,0.0000111629,0.0000106266,0.0000129044,0.0000172576,0.0000216974,0.0000232339,0.0000204642,0.0000155096,0.0000119739,0.0000120098,0.0000157303,0.0000216963,0.0000269007,0.0000277722,0.0000234185,0.0000170818,0.0000131483,0.0000139225,0.0000191729,0.0000266498,0.0000323315,0.0000322612,0.0000262685,0.0000187195,0.0000146189,0.0000162587,0.0000229503,0.0000316008,0.000037322,0.0000360748,0.0000285839,0.0000201923,0.0000162308,0.0000187689,0.0000265874,0.0000358375,0.0000410694,0.0000385343,0.0000299253,0.0000212457,0.0000177555,0.000021086,0.0000294887,0.0000385878,0.0000428113,0.0000390708,0.0000299529,0.0000216567,0.0000189327,0.0000228023,0.0000310861,0.0000392347,0.0000420573,0.0000374097,0.0000285341,0.000021288,0.000019523,0.0000235719,0.0000310124,0.0000375351,0.000038791,0.0000337031,0.0000258056,0.0000201218,0.0000193602,0.0000232043,0.0000292277,0.0000337383,0.0000335339,0.0000285325,0.000022157,0.0000182685,0.0000183955,0.0000217204,0.0000260417,0.0000285313,0.0000272103,0.0000227513,0.0000181274,0.0000159479,0.0000167255,0.0000193539,0.0000220184,0.0000228182,0.0000208507,0.0000172182,0.0000142504,0.0000134414,0.0000145815,0.0000164881,0.0000177985,0.0000174337,0.0000152762,0.0000125511,0.0000109148,0.0000110238,0.0000122648,0.0000135413,0.0000139169,0.0000129276,0.0000109173,9.01633*10^-6,8.30148*10^-6,8.89899*10^-6,0.0000100554,0.0000108503,0.0000106919,9.50391*10^-6,7.82257*10^-6,6.57486*10^-6,6.40567*10^-6,7.16874*10^-6,8.14135*10^-6,8.60627*10^-6,8.21702*10^-6,7.09626*10^-6,5.79527*10^-6,5.01389*10^-6,5.11097*10^-6,5.8423*10^-6,6.60103*10^-6,6.85917*10^-6,6.42795*10^-6,5.50012*10^-6,4.5507*10^-6,4.07673*10^-6,4.26498*10^-6,4.87088*10^-6,5.42821*10^-6,5.56594*10^-6,5.18801*10^-6,4.48472*10^-6,3.82361*10^-6,3.54108*10^-6,3.72838*10^-6,4.18349*10^-6,4.57192*10^-6,4.6435*10^-6,4.35255*10^-6,3.85484*10^-6,3.41314*10^-6,3.24569*10^-6,3.39435*10^-6,3.71047*10^-6,3.96784*10^-6,4.00462*10^-6,3.80047*10^-6,3.46885*10^-6,3.18544*10^-6,3.08611*10^-6,3.18886*10^-6,3.39344*10^-6,3.5553*10^-6,3.57424*10^-6,3.44177*10^-6,3.23332*10^-6,3.05918*10^-6,3.00022*10^-6,3.06376*10^-6,3.18717*10^-6,3.28334*10^-6,3.29322*10^-6,3.21342*10^-6,3.09013*10^-6,2.98825*10^-6,2.95355*10^-6,2.98889*10^-6,3.05797*10^-6,3.11154*10^-6,3.11673*10^-6,3.0722*10^-6,3.004*10^-6,2.94775*10^-6,2.92784*10^-6,2.94539*10^-6,2.98096*10^-6,3.00864*10^-6,3.01132*10^-6,2.98845*10^-6,2.95351*10^-6,2.92455*10^-6,2.91369*10^-6,2.92137*10^-6,2.93804*10^-6,2.95116*10^-6,2.95251*10^-6,2.94182*10^-6,2.92545*10^-6,2.91174*10^-6,2.90622*10^-6,2.90907*10^-6,2.91606*10^-6,2.92168*10^-6,2.92234*10^-6,2.9179*10^-6,2.91102*10^-6,2.90518*10^-6,2.90262*10^-6,2.90344*10^-6,2.90597*10^-6,2.90808*10^-6,2.90838*10^-6,2.90679*10^-6,2.90429*10^-6,2.90212*10^-6};

cwd = ContinuousWaveletTransform[data, GaborWavelet[6], {Automatic, 12}];
ListDensityPlot[Abs[cwd[All, "Values"]], PlotRange -> Automatic,
ClippingStyle -> Automatic, ColorFunction -> "TemperatureMap"]


I'm interested in a weak frequency component in the signal. The zoom out of above figure looks like

ListDensityPlot[Abs[cwd[All, "Values"]],
PlotRange -> {{100, 400}, {20, 28}, {Min[Abs[cwd[All, "Values"]]],
0.02 Max[Abs[cwd[All, "Values"]]]}}, ClippingStyle -> Automatic,
ColorFunction -> "TemperatureMap", AspectRatio -> 1/GoldenRatio]


. From this plot, the weak signal is not easy to see because there are "stripes" from the other strong signal. However, if we use a higher order of wavelet, for the same region, we can see clearly the weak signal

cwd2 = ContinuousWaveletTransform[data, GaborWavelet[10], {Automatic, 12}];
ListDensityPlot[Abs[cwd2[All, "Values"]],
PlotRange -> {{100, 400}, {20, 28}, {Min[Abs[cwd2[All, "Values"]]],
0.02 Max[Abs[cwd2[All, "Values"]]]}}, ClippingStyle -> Automatic,
ColorFunction -> "TemperatureMap", AspectRatio -> 1/GoldenRatio]


Question:

1. Why there are strong "stripes" in the low order wavelet case? Are those "stripes" a "true" feature of my signal or it's an artificial effect from the wavelet transform?

2. In general, what are the guide lines to choose the order of the wavelet?

-
If you don't receive good answers here you may consider posting it in dsp.stackexchange.com –  belisarius Nov 20 '13 at 21:18

For the continuous wavelet transform there will be problems near the edge of the time series, as the wavelet starts to run off the end. To minimize these problems, the time series can be padded with zeroes. This reduces the wavelet power near the edges, but it avoids wrap-around effects.

Which leads us to the option Padding used in ContinuousWaveletTransform.

cwd = ContinuousWaveletTransform[data, GaborWavelet[6], {Automatic, 12}, Padding -> None]


Produces

cwd = ContinuousWaveletTransform[data, GaborWavelet[6], {Automatic, 12}, Padding -> "Fixed"]


Produces

From those observations I have to conclude that these features are actually present in your signal and not a side effect from the wavelet transformation. They are strong, because the wavelet family you are using, namely GaborWavelet, has a parameter called base frequency which you set to 12 Hz. Changing that value one can clearly see that there's a trade-off between localisation and intensity. So, you are essentially changing the resolution.

To answer your next question I will provide an example. Suppose we have the following signal:

dat = Table[Sin[40 π x] Exp[-100 π (x - .2)^2] + (Sin[40 π x] +
2 Cos[160 π x]) Exp[-50 π (x - .5)^2] + 2 Sin[160 π x] Exp[-100 π (x - .8)^2],
{x, 0, 1, 1/2047}];

plot = ListLinePlot[dat, PlotRange -> All, PlotStyle -> Red]


We will use base frequency of 5 Hz to analyse the signal. As we can see the signal consists of three portions with respective frequencies of 20 Hz and 80 Hz. Here we can observe the magnitudes of that signal in a scalogram using 8 octaves and 16 voices per octave. NB! Using GaborWavelet[10] is not a mistake ! See the definition of GaborWavelet

Show[{WaveletScalogram[ContinuousWaveletTransform[dat, GaborWavelet[10], {8, 16}],
ColorFunction -> "AtlanticColors"], plot}]


We see that that scalogram consists of just four interesting spots aligned directly below the three most prominent portions of the signal. These four spots are centered on the two reciprocal-scale values of 2^2 and 2^4, which are in the same ratio as the two frequencies 20 and 80. (Notice also that the base frequency is 5 and that 20 = 5 · 2^2, 80 = 5 · 2^4.) It is interesting to compare this scalogram with a spectrogram of the test signal. The spectrogram has all of its significant values crowded together at the lower frequencies; the scalogram is a zooming in on this lower range of frequencies, from 5 Hz to 1280 Hz along an octave-based scale.

GraphicsColumn[{Spectrogram[dat, ColorFunction -> "Rainbow"],
ListLinePlot[dat, PlotRange -> All,
ColorFunction -> "BlueGreenYellow"]}, PlotRange -> Automatic]


The reason that the ContinuousWaveleTransform is so clean and simple is because of the proper choice of base frequency. The test signal consists of terms that are identical in form to the real and imaginary parts of the GaborWavelet. Therefore, when a scale value produces a function having a form similar to one of the terms in our test signal, then the correlation in the ContinuousWaveleTransform will have some high-magnitude values.

-
I hope this answers your question :D –  Sektor Nov 21 '13 at 22:54
Thanks, that helps a lot. What do you mean by "GaborWavelet[10] is not a mistake"? If I use GaborWavelet[5] or GaborWavelet[12] I can also see those four blobs. –  xslittlegrass Nov 21 '13 at 23:26
But not the finer details :) Means that in the definition present in the Mathematica documentation there's a term 2 which is omitted, so by using GaborWavelet[10] you setting the base frequency = 5 :) –  Sektor Nov 21 '13 at 23:28
So as I understand, your point is that the "stripes" are there in the signal, using a higher order wavelet removes them because the time resolution is lower in higher order wavelet. Is that correct? –  xslittlegrass Nov 21 '13 at 23:32
Yes, they are there and no, not exactly, as that depends on the signal :D But to some extend - correct, because you again try to match or overlap the signal with the wavelet function :) And by using a different frequency you get a clearer picture. –  Sektor Nov 21 '13 at 23:36