#!/usr/bin/env python # -*- coding: utf-8 -*- #from matplotlib.pyplot import * from numpy import * from multiprocessing import Process, Pool, cpu_count from fftshift import fftshift #import fftw3 import pyfftw """ Continuous Multi-Wavelet analyzis 0.001 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__ = ["cwt",] 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 = fftshift(2*pi*arange(-N2,N2)/ (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 """ J = floor(dj**-1 * log2((N * dt) / s0)) s = empty(J + 1) s = s0 * 2**(arange(s.shape[0]) * 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 cwt((x, dt, dj, p , res, fmin,fmax)): """ x - transformed signal dt - time step dj - frequency resolution p - tradeoff between spatial and time resolution res - number of the timepoint of the spectrogram fmin,fmax - frequency range """ lenght_ = size(x,0) #reduce lenght to increase speed of fft div = 2**int(log2(lenght_/256)) lenght = div*(lenght_/div) x = csingle(x[:lenght]) w = angularfreq(lenght, dt) s0 = compute_s0(dt, p) scale = scales(lenght, dj, dt, s0) freq = (p + sqrt(2.0 + p**2))/(4*pi * scale) ind = (freq>fmin)&(freq