0

I want to run a loop over every 33 observations and perform a discrete wavelet transform using PyWavelets on that subset of data. I've searched far and wide for a similar issue using PyWavelets, but can't find anything. I've looked into looping with array outputs as well, with no luck.

Here's the code I'm using:

mnum = 0
tbar = 0
nsize = 33
data = np.random.random_sample((99,))


for jtim in range(ntot):
    mnum = mnum + 1
    if (mnum > nsize):
        num = mnum -32
        sub = data[num:mnum]
        (cA, cD) = pywt.dwt(sub, 'db4', mode='sym')

And here is the error I'm getting:

RuntimeError Traceback (most recent call last) <ipython-input-145-a565a74d0593> in <module>()
      7         num = mnum -32
      8         sub = data[num:mnum]
----> 9         (cA, cD) = pywt.dwt(sub, 'db4', mode='sym')
    _pywt.pyx in _pywt.dwt (pywt/src/_pywt.c:11729)()
    _pywt.pyx in _pywt.dwt_single (pywt/src/_pywt.c:13519)()

RuntimeError: Invalid output length.

I'm pretty sure the error is because I'm trying to output arrays (cA, cD are both arrays).

So I tried a modification with two append statements and go it to work:

results = []
results2 = []
for jtim in range(len(data):
    mnum = mnum + 1
    if (mnum > nsize):
        num = mnum -32
        sub = data[num:mnum]
        (cA, cD) = pywt.dwt(sub, 'db4', mode='sym')
        results.append(cA)
        results2.append(cD)
user2573355
  • 271
  • 2
  • 3
  • 12

0 Answers0