Message Boards Message Boards

Why is the number of wavelet coefficients more than expected?

Hello,

I'm processing vowel sounds using Mathematica. I have preprocessed some audio input and have computed the Log Abs Fourier transform of a 256-sample portion of a vowel. Then I have removed all the negative frequencies from the spectrum, thereby leaving 128 samples. All of the Fourier operations work exactly as I would expect. However, when I go to wavelet smooth this spectrum, I get more wavelet coefficients than expected. For example, using 4 Refinements on the 128 remaining samples of the spectrum, there should be 64 wavelet coefficients corresponding to {1}. However there are more (74?). Also, the number of coefficients corresponding to {0,0,0,0} should be 8, but instead I count 26. Yet, when I throw out all but the coefficients for the scaling functions, the reconstruction seems about right, as you can see from the final plot. I've played with different numbers of refinement levels and different wavelet families, and I still see the discrepancy.

I think I've read everything that Wolfram says about the wavelet transform and the many other wavelet tools, and I see no mention of these excess coefficients. What am I overlooking?

I will be grateful for any pointers to appropriate documentation or other helpful information.

Thank you very much.

-Dave Johnson

POSTED BY: Dave Johnson
9 Replies

The LiftingWaveletTransform seems to do the trick. It is a drop-in replacement for the DiscreteWaveletTransform in my application, and it has the "correct" number of wavelet transform coefficients. It seems to work fine with the InverseWaveletTransform. There is still much that I don't understand about the Mathematica wavelet tools, but you have pointed me in a good direction.

Thanks for all your help.

-Dave Johnson

POSTED BY: Dave Johnson

As far as i know not all wavelets are length preserving

In[15]:= test = RandomReal[{0, -10}, 128];

In[16]:= dwd = DiscreteWaveletTransform[test, Automatic, 4];
dwd["Wavelet"]
dwd["Dimensions"]

Out[17]= HaarWavelet[]

Out[18]= {{0} -> {64}, {1} -> {64}, {0, 0} -> {32}, {0, 
   1} -> {32}, {0, 0, 0} -> {16}, {0, 0, 1} -> {16}, {0, 0, 0, 
   0} -> {8}, {0, 0, 0, 1} -> {8}}

In[19]:= dwd = DiscreteWaveletTransform[test, MeyerWavelet[], 4];
dwd["Wavelet"]
dwd["Dimensions"]

Out[20]= MeyerWavelet[3, 10]

Out[21]= {{0} -> {74}, {1} -> {74}, {0, 0} -> {47}, {0, 
   1} -> {47}, {0, 0, 0} -> {33}, {0, 0, 1} -> {33}, {0, 0, 0, 
   0} -> {26}, {0, 0, 0, 1} -> {26}}

In[22]:= dwd = DiscreteWaveletTransform[test, MeyerWavelet[3, 1], 4];
dwd["Wavelet"]
dwd["Dimensions"]

Out[23]= MeyerWavelet[3, 1]

Out[24]= {{0} -> {65}, {1} -> {65}, {0, 0} -> {33}, {0, 
   1} -> {33}, {0, 0, 0} -> {17}, {0, 0, 1} -> {17}, {0, 0, 0, 
   0} -> {9}, {0, 0, 0, 1} -> {9}}

In[28]:= dwd = DiscreteWaveletTransform[test, CoifletWavelet[], 4];
dwd["Wavelet"]
dwd["Dimensions"]

Out[29]= CoifletWavelet[2]

Out[30]= {{0} -> {69}, {1} -> {69}, {0, 0} -> {40}, {0, 
   1} -> {40}, {0, 0, 0} -> {25}, {0, 0, 1} -> {25}, {0, 0, 0, 
   0} -> {18}, {0, 0, 0, 1} -> {18}}

If I remember correctly this is due to that most wavelets assume infinite signals and use padding to prevent edge effects. Most wavelets therefore also need to be defined outside your signal range.

EDIT:

Mathematica also has StationaryWaveletTransform that is similar to DiscreteWaveletTransform without the subsampling

In[49]:= dwd = StationaryWaveletTransform[test, MeyerWavelet[], 4];
dwd["Wavelet"]
dwd["Dimensions"]

Out[50]= MeyerWavelet[3, 10]

Out[51]= {{0} -> {128}, {1} -> {128}, {0, 0} -> {128}, {0, 
   1} -> {128}, {0, 0, 0} -> {128}, {0, 0, 1} -> {128}, {0, 0, 0, 
   0} -> {128}, {0, 0, 0, 1} -> {128}}
POSTED BY: Martijn Froeling

Martijn,

Thank you, that is very helpful. Is there a version of the discrete wavelet transform in Mathematica that does the down-sampling but does not do the padding? I would regard this as a more "traditional" discrete wavelet transform. I could write my own, but it would be better to use a built-in from Mathematica. Forgive me, but I can't find anything like that in the documentation. Also, is there documentation on how to choose the wavelet transform coefficients to recover the "traditional" coefficients, in other words, if I wanted to ignore padding?

Thanks!

-Dave Johnson

POSTED BY: Dave Johnson

LiftingWaveletTransform i think but that does not support MeyerWavelet. With DiscreteWaveletTransform only the HaarWavelet gives the 2^r dimensions.

In[280]:= test = RandomReal[{0, -10}, 128];

dwd = DiscreteWaveletTransform[test, #[], 
     4] & /@ {BattleLemarieWavelet, BiorthogonalSplineWavelet, 
    CoifletWavelet, DaubechiesWavelet, HaarWavelet, MeyerWavelet, 
    ReverseBiorthogonalSplineWavelet, ShannonWavelet, SymletWavelet};
#["Wavelet"] -> #["Dimensions"] & /@ dwd

Out[282]= {BattleLemarieWavelet[3, 
   10] -> {{0} -> {74}, {1} -> {74}, {0, 0} -> {47}, {0, 
     1} -> {47}, {0, 0, 0} -> {33}, {0, 0, 1} -> {33}, {0, 0, 0, 
     0} -> {26}, {0, 0, 0, 1} -> {26}}, 
 BiorthogonalSplineWavelet[4, 
   2] -> {{0} -> {67}, {1} -> {67}, {0, 0} -> {37}, {0, 
     1} -> {37}, {0, 0, 0} -> {22}, {0, 0, 1} -> {22}, {0, 0, 0, 
     0} -> {14}, {0, 0, 0, 1} -> {14}}, 
 CoifletWavelet[
   2] -> {{0} -> {69}, {1} -> {69}, {0, 0} -> {40}, {0, 
     1} -> {40}, {0, 0, 0} -> {25}, {0, 0, 1} -> {25}, {0, 0, 0, 
     0} -> {18}, {0, 0, 0, 1} -> {18}}, 
 DaubechiesWavelet[
   2] -> {{0} -> {65}, {1} -> {65}, {0, 0} -> {34}, {0, 
     1} -> {34}, {0, 0, 0} -> {18}, {0, 0, 1} -> {18}, {0, 0, 0, 
     0} -> {10}, {0, 0, 0, 1} -> {10}}, 
 HaarWavelet[] -> {{0} -> {64}, {1} -> {64}, {0, 0} -> {32}, {0, 
     1} -> {32}, {0, 0, 0} -> {16}, {0, 0, 1} -> {16}, {0, 0, 0, 
     0} -> {8}, {0, 0, 0, 1} -> {8}}, 
 MeyerWavelet[3, 
   10] -> {{0} -> {74}, {1} -> {74}, {0, 0} -> {47}, {0, 
     1} -> {47}, {0, 0, 0} -> {33}, {0, 0, 1} -> {33}, {0, 0, 0, 
     0} -> {26}, {0, 0, 0, 1} -> {26}}, 
 ReverseBiorthogonalSplineWavelet[4, 
   2] -> {{0} -> {67}, {1} -> {67}, {0, 0} -> {37}, {0, 
     1} -> {37}, {0, 0, 0} -> {22}, {0, 0, 1} -> {22}, {0, 0, 0, 
     0} -> {14}, {0, 0, 0, 1} -> {14}}, 
 ShannonWavelet[
   10] -> {{0} -> {74}, {1} -> {74}, {0, 0} -> {47}, {0, 
     1} -> {47}, {0, 0, 0} -> {33}, {0, 0, 1} -> {33}, {0, 0, 0, 
     0} -> {26}, {0, 0, 0, 1} -> {26}}, 
 SymletWavelet[
   4] -> {{0} -> {67}, {1} -> {67}, {0, 0} -> {37}, {0, 
     1} -> {37}, {0, 0, 0} -> {22}, {0, 0, 1} -> {22}, {0, 0, 0, 
     0} -> {14}, {0, 0, 0, 1} -> {14}}}

In[278]:= 
dwd = LiftingWaveletTransform[test, #[], 
     4] & /@ {BiorthogonalSplineWavelet, CDFWavelet, CoifletWavelet, 
    DaubechiesWavelet, HaarWavelet, ReverseBiorthogonalSplineWavelet, 
    SymletWavelet};
#["Wavelet"] -> #["Dimensions"] & /@ dwd

Out[279]= {BiorthogonalSplineWavelet[4, 
   2] -> {{0} -> {64}, {1} -> {64}, {0, 0} -> {32}, {0, 
     1} -> {32}, {0, 0, 0} -> {16}, {0, 0, 1} -> {16}, {0, 0, 0, 
     0} -> {8}, {0, 0, 0, 1} -> {8}}, 
 CDFWavelet[
   "9/7"] -> {{0} -> {64}, {1} -> {64}, {0, 0} -> {32}, {0, 
     1} -> {32}, {0, 0, 0} -> {16}, {0, 0, 1} -> {16}, {0, 0, 0, 
     0} -> {8}, {0, 0, 0, 1} -> {8}}, 
 CoifletWavelet[
   2] -> {{0} -> {64}, {1} -> {64}, {0, 0} -> {32}, {0, 
     1} -> {32}, {0, 0, 0} -> {16}, {0, 0, 1} -> {16}, {0, 0, 0, 
     0} -> {8}, {0, 0, 0, 1} -> {8}}, 
 DaubechiesWavelet[
   2] -> {{0} -> {64}, {1} -> {64}, {0, 0} -> {32}, {0, 
     1} -> {32}, {0, 0, 0} -> {16}, {0, 0, 1} -> {16}, {0, 0, 0, 
     0} -> {8}, {0, 0, 0, 1} -> {8}}, 
 HaarWavelet[] -> {{0} -> {64}, {1} -> {64}, {0, 0} -> {32}, {0, 
     1} -> {32}, {0, 0, 0} -> {16}, {0, 0, 1} -> {16}, {0, 0, 0, 
     0} -> {8}, {0, 0, 0, 1} -> {8}}, 
 ReverseBiorthogonalSplineWavelet[4, 
   2] -> {{0} -> {64}, {1} -> {64}, {0, 0} -> {32}, {0, 
     1} -> {32}, {0, 0, 0} -> {16}, {0, 0, 1} -> {16}, {0, 0, 0, 
     0} -> {8}, {0, 0, 0, 1} -> {8}}, 
 SymletWavelet[
   4] -> {{0} -> {64}, {1} -> {64}, {0, 0} -> {32}, {0, 
     1} -> {32}, {0, 0, 0} -> {16}, {0, 0, 1} -> {16}, {0, 0, 0, 
     0} -> {8}, {0, 0, 0, 1} -> {8}}}
POSTED BY: Martijn Froeling

Since I have not received any replies or answers to my question in the more than two weeks since I posted it here, I would like to gently ask if I have done or written anything in my question that would prevent or dissuade someone from answering. Or do I need to wait longer for the right person to read my question and reply. I am new to this forum, and so I would appreciate any assistance that might help me get an answer.

Thank you very much.

-Dave Johnson

POSTED BY: Dave Johnson

Dave, Your question is fine. It might simply be the case that nobody reading this forum has an answer.

I can say categorically that I for one do not. It's not that I never considered the question, I just never quite understood this coefficient count myself. It came up when I was struggling with a Wolfram Function Repository function LaurentExtendedGCD. This would appear to be unrelated to wavelets but actually similar functionality is used under the hood in some wavelet lifting schemes. If you check the examples you might find some hints for getting the number of coefficients you expect (it might be that I used for example WaveletFilterCoefficients[...,"PrimalLowPass"], I don't remember for certain).

For what it's worth, I sent a note to the image processing team, back in January I think, noting several issues I had with Wavelet-related documentation. But I do not know if they have the expertise to address this lacuna in the documentation either.

POSTED BY: Daniel Lichtblau

Thank you, Daniel.

I'm certain of the wavelet coefficient count that I'm expecting. I suspect that most applications don't use the wavelet coefficients directly in applications, but perhaps use Mathematica tools to choose or massage the coefficients in some way, and then pass them on to a Mathematica inverse transform. However, my application maps specific wavelet coefficients through my own mapping (specifically to a motor control system to produce vowel sounds). So the identity and count of the coefficients has to be correct and known. I'm willing to assume that the Mathematica transform is correct, but that it is somehow not documented well enough for me to understand its use. Unless this issue is addressed, I will be forced to write my own discrete wavelet transform (using Mathematica tools, of course, perhaps including Mathematica wavelet and scaling functions) in order to have control over the coefficients. That is easy enough, but I would rather not have to do that.

I appreciate your response, and I hope that Wolfram and team are looking at this issue.

Thanks,

-Dave

POSTED BY: Dave Johnson

I will suggest you try some of the ways of getting specific coefficient types, e.g. "PrimalLowPass", to see if that provides the set you actually expect and want to manipulate. That approach worked for me in some examples from the WFR function I mentioned.

I have sent a link to this thread to the group most likely to have some knowledge of this area. Again, I think it's a really good question. Just not one I can answer.

POSTED BY: Daniel Lichtblau

I see now that there might be an ambiguity in the terminology. You are talking about the wavelet coefficients, i.e., the definition of the wavelet function itself. The function WaveletFilterCoefficients[] that you mentioned returns the coefficients of the wavelet function. But I'm talking about the output of the DiscreteWaveletTransform[], namely the {0,0.0,0} coefficients. I may have erred in referring to these as "Wavelet Coefficients", so I probably should call them "Wavelet Transform Coefficients". However, even Wolfram documentation refers to these as "coefficients" (see the documentation for DiscreteWaveletTransform). So I don't think that your suggestion will help. Forgive me, friend. But I think there is a bug in DiscreteWaveletTransform[], or in the documentation, or in my understanding.

-Dave

POSTED BY: Dave Johnson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract