Multilevel Wavelet Decomposition not working

3k views Asked by At

I am trying to decompose the given wave by using a db4 wavelet and 5 level decomposition. Here is the code for the same :

coeffs = pywt.wavedec(yourResultA,'db4',level = 5)

However the editor is giving me the following error:

Level value of 5 is too high.  Maximum allowed is 0.

I am not understanding the meaning of this error as level 0 does not make any sense. I even tried to find the maximum possible level for db4 wavelet using this code:

w = pywt.Wavelet('db4')
x = pywt.dwt_max_level(len(yourResultA), w)

The value of x here was 15 so,I guess that it can calculate for 15 levels.Where exactly is the error occurring in my code?

2

There are 2 answers

0
imchukwu On

The wave file being decomposed is in stereo format, so you either convert to mono format or set your axis to 0.

You can use:

rate, data = scipy.io.wavfile.read('wavfile.wav')
data = data[:, 0]

then pass your data

coeffs = pywt.wavedec(yourResultA,'db4',level = 5)

or:

set the axis parameter to 0

coeffs = pywt.wavedec(yourResultA,'db4',level = 5, axis = 0)
0
Shasa Foster On

If you read the documentation on pywt.dwt_max_level() you can see that the max level is dependent on the length of your data. Could that be the issue?

Docs: https://pywavelets.readthedocs.io/en/0.2.2/ref/dwt-discrete-wavelet-transform.html#maximum-decomposition-level-dwt-max-level