Skip to content

Commit

Permalink
use fftfreq for the frequencies
Browse files Browse the repository at this point in the history
also set as property and remove ability to select value by call (can do
it by indexing now)

This affects the computation of Cdelta, which is now about 0.768 for the
Morlet, without having to set the values of s0 and dj lower. Setting
them lower doesn't change this much. See #1.
  • Loading branch information
aaren committed Feb 14, 2015
1 parent e1f0d9c commit 0836654
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions wavelets/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,33 +329,16 @@ def compute_optimal_scales(self):
sj = s0 * 2 ** (dj * np.arange(0, J + 1))
return sj

# TODO: use np.frompyfunc on this
# TODO: can we just replace it with fftfreqs?
def w_k(self, k=None):
@property
def w_k(self):
"""Angular frequency as a function of fourier index.
If no k, returns an array of all the angular frequencies
calculated using the length of the data.
See eq5 of TC.
"""
dt = self.dt
N = self.N
a = 2 * np.pi / (N * dt)
if k is None:
k = np.arange(N)
w_k = np.arange(N) * a
w_k[np.where(k > N // 2)] *= -1
elif type(k) is np.ndarray:
w_k = a * k
w_k[np.where(k > N // 2)] *= -1
else:
w_k = a * k
if k <= N // 2:
pass
elif k > N // 2:
w_k *= -1
return w_k
return np.fft.fftfreq(self.N, self.dt)

@property
def wavelet_transform(self):
Expand Down Expand Up @@ -507,7 +490,7 @@ def wavelet_transform_delta(self):
"""
Y_0 = self.wavelet.frequency # wavelet as f(w_k, s)

WK, S = np.meshgrid(self.w_k(), self.scales)
WK, S = np.meshgrid(self.w_k, self.scales)

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

0 comments on commit 0836654

Please sign in to comment.