#!/usr/bin/env python # -*- coding: utf-8 -*- from matplotlib.pyplot import * from numpy import * #from scipy.fftpack import rfft, irfft,fftshift,ifft from numpy.fft import rfft, irfft,fftshift from scipy.fftpack import ifft from _extend import extend import sys from scipy import signal """ Continuous Multi-Wavelet analyzis 0.1 Description: The continius wavelet analysis od the multiple signal is calculated. Instead of the single one dimensional wavelet a n-dimensional Morlet wavelet with shifted component is created. The moving scalar product with such wavelets helps to identify and amplify the correctly time shifted signals and suppress the other. """ __all__ = ["NTM_CWT", "angularfreq", "scales", "compute_s0"] def angularfreq(N, dt): """Compute angular frequencies. :Parameters: N : integer number of data samples dt : float time step :Returns: angular frequencies : 1d numpy array """ # See (5) at page 64. N2 = N / 2.0 w = empty(N) for i in range(w.shape[0]): if i <= N2: w[i] = (2 * pi * i) / (N * dt) else: w[i] = (2 * pi * (i - N)) / (N * dt) return w def scales(N, dj, dt, s0): """Compute scales. :Parameters: N : integer number of data samples dj : float scale resolution dt : float time step :Returns: scales : 1d numpy array scales """ # See (9) and (10) at page 67. J = floor(dj**-1 * log2((N * dt) / s0)) s = empty(J + 1) for i in range(s.shape[0]): s[i] = s0 * 2**(i * dj) return s def compute_s0(dt, p): """Compute s0. :Parameters: dt :float time step p : float omega0 ('morlet') or order ('paul', 'dog') :Returns: s0 : float """ return (dt * (p + sqrt(2 + p**2))) / (2 * pi) def NTM_CWT((x, dt, dj, p,m , res, fmin,fmax)): n_detec = size(x,1) lenght = size(x,0) lenght_ext = int(2**ceil(log2(lenght))) x = signal.detrend(x, axis=0, type='linear') x_new = extend(x, method='zeros') w = angularfreq(lenght_ext, dt) s0 = compute_s0(dt, p) s = scales(lenght_ext, dj, dt, s0) freq = (p + sqrt(2.0 + p**2))/(4*pi * s) ind = where((freq>fmin)&(freq