From 121ca8826cd2fe844375aa6ebb62eeff95ad0f2a Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:49:45 +0100 Subject: [PATCH] Update README.md Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com> --- pywavelet/README.md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/pywavelet/README.md b/pywavelet/README.md index 1d71970..d76c3e2 100644 --- a/pywavelet/README.md +++ b/pywavelet/README.md @@ -31,6 +31,38 @@ print(wavelet_list) * The Shannon wavelets ("shanB-C" with floating point values B and C) * The frequency B-spline wavelets ("fpspM-B-C" with integer M and floating point B, C) - see [Choosing the scales for cwt](https://pywavelets.readthedocs.io/en/latest/ref/cwt.html#choosing-the-scales-for-cwt) +see [Choosing the scales for cwt](https://pywavelets.readthedocs.io/en/latest/ref/cwt.html#choosing-the-scales-for-cwt) - ## Visualizing wavelets +## Visualizing wavelets + +```python +import numpy as np +import matplotlib.pyplot as plt +import pywt + +wavelet_name: str = "cmor1.5-1.0" + +# "linked" to how many peaks and +# troughs the wavelet will have +scale: float = 10 + +# Invoking the complex morlet wavelet object +wav = pywt.ContinuousWavelet(wavelet_name) + +# Integrate psi wavelet function from -Inf to x +# using the rectangle integration method. +int_psi, x = pywt.integrate_wavelet(wav, precision=10) +int_psi /= np.abs(int_psi).max() +wav_filter: np.ndarray = int_psi[::-1] + +nt: int = len(wav_filter) +t: np.ndarray = np.linspace(-nt // 2, nt // 2, nt) +plt.plot(t, wav_filter.real, label="real") +plt.plot(t, wav_filter.imag, label="imaginary") +plt.ylim([-1, 1]) +plt.legend(loc="upper left") +plt.xlabel("time (samples)") +plt.title(f"filter {wavelet_name}") +``` + +![figure 1](image1.png)