Skip to content

Commit 08baf66

Browse files
committedFeb 14, 2015
use fftfreq for the frequencies
also set as property and remove ability to select value by call (can do it by indexing now) n.b. the frequencies returned by numpy are adimensional, on the interval [-1/2, 1/2], so we multiply by 2 * pi. This affects the computation of Cdelta, which now comes out as correct when s0 = 1 (for the Morlet). See #1.
1 parent e1f0d9c commit 08baf66

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed
 

‎wavelets/transform.py

+4-21
Original file line numberDiff line numberDiff line change
@@ -329,33 +329,16 @@ def compute_optimal_scales(self):
329329
sj = s0 * 2 ** (dj * np.arange(0, J + 1))
330330
return sj
331331

332-
# TODO: use np.frompyfunc on this
333-
# TODO: can we just replace it with fftfreqs?
334-
def w_k(self, k=None):
332+
@property
333+
def w_k(self):
335334
"""Angular frequency as a function of fourier index.
336335
337336
If no k, returns an array of all the angular frequencies
338337
calculated using the length of the data.
339338
340339
See eq5 of TC.
341340
"""
342-
dt = self.dt
343-
N = self.N
344-
a = 2 * np.pi / (N * dt)
345-
if k is None:
346-
k = np.arange(N)
347-
w_k = np.arange(N) * a
348-
w_k[np.where(k > N // 2)] *= -1
349-
elif type(k) is np.ndarray:
350-
w_k = a * k
351-
w_k[np.where(k > N // 2)] *= -1
352-
else:
353-
w_k = a * k
354-
if k <= N // 2:
355-
pass
356-
elif k > N // 2:
357-
w_k *= -1
358-
return w_k
341+
return 2 * np.pi * np.fft.fftfreq(self.N, self.dt)
359342

360343
@property
361344
def wavelet_transform(self):
@@ -507,7 +490,7 @@ def wavelet_transform_delta(self):
507490
"""
508491
Y_0 = self.wavelet.frequency # wavelet as f(w_k, s)
509492

510-
WK, S = np.meshgrid(self.w_k(), self.scales)
493+
WK, S = np.meshgrid(self.w_k, self.scales)
511494

512495
# compute Y_ over all s, w_k and sum over k
513496
norm = (2 * np.pi * S / self.dt) ** .5 # normalisation factor with dt=1

0 commit comments

Comments
 (0)
Failed to load comments.