# CWT

Dear Obspy users;

In the Obspy Tutorial there is an example for the use of the cwt function but it uses the mlpy package of Python.
I would like to use the obspy function on tf_misfit, but on the library reference description, the call for the function is different from the description of the parameters.
Does any body has an example for the use of the cwt similar to the one that is described on the tutorial ?

Thank you very much for your help

Javier Fco. Pacheco.

Hi Javier,

The cwt function in tf_misfit uses the following arguments:

- st: the data array to be processed (either a list or a numpy.ndarray),
- dt: the time difference between two samples in your data array,
- w0: the natural frequency of the wavelet to be used, since only the Morlet wavelet is implemented,
- fmin and fmax: lower and upper limit of the frequency range,
- nf: number of scales (it discretizes the frequency range by this number) (default set to 100),
- wl: the name of the wavelet to be applied (only 'morlet' is implemented).

A short example would be:

from obspy.signal.tf_misfit import cwt
import numpy as np, matplotlib.pyplot as plt
npts = tr.stats.npts
samp_rate = tr.stats.sampling_rate
dt = npts / samp_rate
t = np.linspace(0, dt, npts)
scalogram = cwt(tr.data, 1/samp_rate, 8, 1, 50)
fig = plt.figure()
ax.imshow(np.abs(scalogram)[-1::-1], extent=[t, t[-1], 1, 50], aspect='auto')
ax.set_xlabel("Time")
ax.set.ylabel("Frequency")
plt.show()

Hope it helps.

Cheers,
Jeremie

Dear Javier and Jeremie,

just to clarify on w0: it has units of frequency and is a control parameter that influences the shape of the wavelet (roughly: how many wiggles within the gaussian window). This way it allows to adjust between time and frequency resolution. For more details on that: the cwt function in tf_misfit actually is a straight implementation of equations (4) and (5) in .

The relation between scale and (peak) frequency then is f = w0 / (2 pi a) where a is the scale.

Cheers,
Martin

: ﻿Kristekova, M., Kristek, J., Moczo, P., & Day, S. M. (2006). Misfit Criteria for Quantitative Comparison of Seismograms. Bulletin of the Seismological Society of America, 96(5), 1836-1850.

Hi all,

I've added an entry to the tutorial based on the proposed example, see
https://github.com/obspy/obspy/commit/af9a3ce9062f55a70a9cafcab3d99a71802c3ef8

best,
Tobias