Closed ulaai closed 7 years ago
The message AttributeError: 'numpy.ndarray' object has no attribute 'items'
is because
coeffs[0]
is an array, not a dictionary, so you cannot use .items()
on it. The first element of coeffs
is an array containing the approximation coefficients. The remaining elements of the list are dictionaries containing the various detail coefficients at each level of decomposition (see the wavedecn
documentation for more details of the output format).
If you want the approximation coefficients set to zero you can do either:
coeffs[0] = np.zeros_like(coeffs[0])
or
coeffs[0][:] = 0
For the remaining levels, you can replace the coefficients with arrays of zeros using a statement of the form suggested in #303:
coeffs[1] = {k: np.zeros_like(v) for k, v in coeffs[1].items()}
Thank you for your help!
You might also want to check out denoise_wavelet
from scikit-image (it is implemented using PyWavelets). Despite being in an "image processing" library, it should also work for 1D ECG data. The coefficient thresholding used there is likely going to work better than just setting all coefficients at a given level to zero.
I'm trying to denoise an ECG signal. I want to omit the approximation and level 1 & 2 details from the signal, then reconstruct it. I looked around and followed #302. This is what I currently have:
I read that there is implementation already in #303 but I can't seem to wrap my head around this. I got the error:
I also tried using other alternative solutions (from the same #302), like setting the coefficients to None but it also raised an error.
Please let me know if I'm doing this wrong, I'm new to wavelets and this library. Thank you very much.