Matlab dwtleader equivalent

235 views
Skip to first unread message

Kevin Scott

unread,
Apr 29, 2022, 5:34:34 AM4/29/22
to PyWavelets
Is there anything equivalent for matlab's dwtleader function: https://nl.mathworks.com/help/wavelet/ref/dwtleader.html#bvfgqrt ?

I am working with multifractal analysis and trying to extract the singularity spectrum and holder exponents from a time-series. This follows the wavelet leaders multi-fractal formalism (WLMF) which consists of the steps:
1. DWT
2. Wavelet leaders
3. Structure function
4. Scaling exp.
5. Singularity spectrum


But I can't seem to find any information about doing this with python.
Any help is greatly appreciated!

Deepu

unread,
May 22, 2023, 2:32:02 AM5/22/23
to PyWavelets
The `dwtleader` function in MATLAB calculates the wavelet leaders using the discrete wavelet transform (DWT) and provides functionality for multifractal analysis. In Python, you can achieve similar functionality using the PyWavelets library, but you would need to perform the steps of the wavelet leaders multi-fractal formalism manually.

Here's a high-level overview of how you can perform the steps using PyWavelets:

1. DWT: Use the `pywt.wavedec` function to perform the discrete wavelet transform on your time-series data. This will give you the wavelet coefficients at different scales.

2. Wavelet leaders: Compute the wavelet leaders by taking the modulus of the wavelet coefficients raised to a certain power. This step is specific to the WLMF method. You can define the power as per your requirement.

3. Structure function: Calculate the structure function using the wavelet leaders. The structure function quantifies the variability of the data at different scales.

4. Scaling exponent: Compute the scaling exponent by fitting a line to the log-log plot of the structure function.

5. Singularity spectrum: Finally, calculate the singularity spectrum from the scaling exponents obtained for different scales.

Here's a basic example to demonstrate the process:

```python
import numpy as np
import pywt
import matplotlib.pyplot as plt

# Step 1: DWT
data = np.random.randn(1000)  # Replace with your time-series data
coeffs = pywt.wavedec(data, 'db4', level=5)  # Perform DWT

# Step 2: Wavelet leaders
power = 2  # Define the power for wavelet leaders
leaders = np.abs(coeffs) ** power

# Step 3: Structure function
scales = [2 ** (-i) for i in range(1, len(coeffs) + 1)]  # Scales for the structure function
structure_function = np.mean(leaders, axis=0)  # Calculate the structure function

# Step 4: Scaling exponent
log_scales = np.log2(scales)
log_structure_function = np.log2(structure_function)
coefficients = np.polyfit(log_scales, log_structure_function, 1)
scaling_exponent = coefficients[0]

# Step 5: Singularity spectrum
singularity_spectrum = 1 - scaling_exponent

# Plotting (optional)
plt.plot(log_scales, log_structure_function, 'o', label='Structure Function')
plt.plot(log_scales, np.polyval(coefficients, log_scales), label='Fitted Line')
plt.xlabel('log2(Scale)')
plt.ylabel('log2(Structure Function)')
plt.legend()
plt.show()
```

Note that this is a basic example to illustrate the process of wavelet leaders multifractal analysis using PyWavelets. Depending on your specific requirements and the WLMF method, you may need to modify and extend the code accordingly.

I hope this helps you get started with wavelet leaders analysis in Python using PyWavelets! Let me know if you have any further questions.
Reply all
Reply to author
Forward
0 new messages