_wavelets.py 886 B

1234567891011121314151617181920212223242526272829
  1. import numpy as np
  2. from scipy.signal._signaltools import convolve
  3. def _ricker(points, a):
  4. A = 2 / (np.sqrt(3 * a) * (np.pi**0.25))
  5. wsq = a**2
  6. vec = np.arange(0, points) - (points - 1.0) / 2
  7. xsq = vec**2
  8. mod = (1 - xsq / wsq)
  9. gauss = np.exp(-xsq / (2 * wsq))
  10. total = A * mod * gauss
  11. return total
  12. def _cwt(data, wavelet, widths, dtype=None, **kwargs):
  13. # Determine output type
  14. if dtype is None:
  15. if np.asarray(wavelet(1, widths[0], **kwargs)).dtype.char in 'FDG':
  16. dtype = np.complex128
  17. else:
  18. dtype = np.float64
  19. output = np.empty((len(widths), len(data)), dtype=dtype)
  20. for ind, width in enumerate(widths):
  21. N = np.min([10 * width, len(data)])
  22. wavelet_data = np.conj(wavelet(N, width, **kwargs)[::-1])
  23. output[ind] = convolve(data, wavelet_data, mode='same')
  24. return output