Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spikes in wavelet after cwt #784

Open
MatthijsRN opened this issue Dec 11, 2024 · 0 comments
Open

Spikes in wavelet after cwt #784

MatthijsRN opened this issue Dec 11, 2024 · 0 comments
Labels

Comments

@MatthijsRN
Copy link

MatthijsRN commented Dec 11, 2024

I run the following code to visualize some wavelets with specific wavelengths. However when I increase my wavelength some samples will spike towards 0. This gets increasingly worse with longer wavelengths. I would greatly appreciate your solution or insight

import pywt
import numpy as np
import math
import matplotlib.pyplot as plt

def generate_wavelet(wavelet_name, n_points, wavelength):
    # Scale computation
    scale = pywt.frequency2scale(wavelet_name, 1/wavelength, precision=math.log2(n_points))

    # Signal (impulse to visualize wavelet)
    signal = np.zeros(n_points)
    signal[n_points//2] = 1

    # Perform Continuous Wavelet Transform
    coeffs, _ = pywt.cwt(signal, scales=[scale], wavelet=wavelet_name)

    return coeffs[0]

wavelengths = [20, 40, 80, 100]
n = len(wavelengths)

plt.figure(figsize=(20,5))
for i, wavelength in enumerate(wavelengths):
    wavelet = generate_wavelet('morl', 5*wavelength, wavelength)
    plt.subplot(1, n, i+1)
    plt.title("wavelength: " + str(wavelength))
    plt.plot(wavelet)

Wavelet_spikes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants