2
$\begingroup$

I am new to wavelet transformation. I am learning it as a tool for signal processing. I have a time series that I want to analyze. I tried to learn wavelet transformation by applying it to a periodic function.

This is my code:

## Meta imports

import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
from scipy import signal

## Sine wave

## making time array

dt   = 1 / 1e3 ## interval between two consecutive time
t    = np.arange(1000)*dt
#frequency
f    = 100
# sine wave
sig  = 5 * np.sin(2 * np.pi * f * t)

fs   = 1. / dt
w    = 8.       

freq   = np.linspace(50, 150, num = 100)
widths = w*fs / (2*freq*np.pi)

cwtm   = signal.cwt(sig, signal.morlet2, widths, w=w)
outz   = np.abs(cwtm**2)

plt.pcolormesh(t, freq, outz, cmap='jet')
plt.yscale('linear')
plt.ylim(min(freq), max(freq))

plt.xlabel('Time (s)')
plt.ylabel('Freq (Hz)')

I got the following plots:

  1. Wavelet Transformation
  2. Signal

Now, I don't really know how to decide the widths, freq or w. I tried writing similar code for my data and cwtr returns 0 for all time.

I also tried using pywt.cwt but wasn't able to get the appropriate wavelet plot.

These are the resources I used to understand Wavelet transformation:

  1. scipy.signal.cwt
  2. Wavelet analysis applied to the real dataset in a quick and easy way

I would like to understand the syntax of the wavelet transformation, how to decide widths, frequency etc. Also if you have any recommendations for resources, that would be awesome.

$\endgroup$
2
  • $\begingroup$ What's the goal of your analysis? What are you trying to find out? $\endgroup$
    – Hilmar
    Sep 15, 2022 at 12:36
  • $\begingroup$ I applied Fourier transformation on my data previously. Now, I am trying to conform our fft finding using wavelet transformation. $\endgroup$ Sep 15, 2022 at 15:34

1 Answer 1

2
$\begingroup$

widths is the array of scale parameters. For the CWT, scale parameter $a$ is inversely proportional to the corresponding Fourier frequency $f$, i.e. $$ a=c_a/f, $$ where $c_a$ is a proportionality constant whose value depends on the specific wavelet function. In the Discrete Fourier Transform (DFT), we know $$ 2\pi/L\leq f< \pi N/L, $$ where $L$ is the physical length of one signal, $N$ is the number of sampling points of the signal, and $\pi N/L$ is the Nyquist frequency. Therefore, the range of values of $a$ is $$ c_a L/(\pi N)< a\leq c_a L/(2\pi). $$

The proportionality constant $c_a$ can be determined in a variety of ways. For more information on this, I recommend you to refer to

$\endgroup$
1
  • $\begingroup$ Thanks a lot for clarifying what widths really mean. I appreciate the resources you shared. $\endgroup$ Sep 16, 2022 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.