Reputation: 355
I have to use python to reproduce results from a paper where MODWT is used. I'm currently using pywt and it only has stationary wavelet transform(SWT). I research a little bit and it seems there is currently no package for MODWT and I also find that many say SWT and MODWT are the same thing. But the results from MODWT using MATLAB and SWT from python are different. Is there any package in python that I can use to perform MODWT directly? Or could I achieve the results in MODWT using SWT?
Upvotes: 3
Views: 6504
Reputation: 1
Another option: Install the API to use Matlab from Python as explained in https://es.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html
Then you can use Matlab's MODWT from Python:
import matlab.engine
future = matlab.engine.start_matlab(background=True) # Starts Matlab on the background, meanwhile Python can execute more commands
import numpy as np
x = np.sin(2 * np.pi * np.arange(100) / 20) + np.random.randn(100)
# Transfiere la señal desde Python a MATLAB
eng.workspace['x'] = x
# Realizar la MODWT en MATLAB
wavelet = 'db4' # Nombre de la wavelet (puedes cambiarlo)
level = 5 # Nivel de descomposición
# Llama a la función modwt de MATLAB
eng.eval(f"wcoefs = modwt(x, '{wavelet}', {level})", nargout=0)
# Recupera los coeficientes de detalle y aproximación desde MATLAB
eng.eval("detail_coefficients = wcoefs(end, :)", nargout=0)
eng.eval("approximation_coefficients = wcoefs(1, :)", nargout=0)
# Transfiere los resultados desde MATLAB a Python
detail_coefficients = eng.workspace['detail_coefficients']
approximation_coefficients = eng.workspace['approximation_coefficients']
# Puedes imprimir o graficar los coeficientes según tus necesidades
print("Coeficientes de detalle en el nivel", level, ":", detail_coefficients)
print("Coeficientes de aproximación:", approximation_coefficients)
eng.quit()
Upvotes: 0
Reputation: 371
Recently, I have read the book on wavelet,
Percival, D. B., and A. T. Walden. Wavelet Methods for Time Series Analysis. Cambridge, UK: Cambridge University Press, 2000
Following it, I carried out the algorithms for modwt and multiresolution analysis using python. The python code can be find in the github here. Maybe it is useful to you.
Upvotes: 11