# Source code :: CMWT

[Return]
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208``` ```#!/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,ifft from _extend import extend """ 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_new = empty((lenght_ext,n_detec)) #print shape(x) for i in range(n_detec): #print i , lenght_ext,n_detec, m x[:,i]-= arange(lenght+0.0)/lenght*(x[-1,i]-x[0,i])+x[0,i] #print '---' x_new = extend(x, method='zeros') #x = x_new #print shape(x_new), shape(x) #return None, None w = angularfreq(lenght, dt) s0 = compute_s0(dt, p) s = scales(lenght, dj, dt, s0) freq = (p + sqrt(2.0 + p**2))/(4*pi * s) ind = where((freq>fmin)&(freq