Skip to content

Commit

Permalink
v0.5.0 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
OverLordGoldDragon authored Dec 19, 2020
1 parent 9554fc5 commit dd57f2e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Synchrosqueezing is a powerful _reassignment method_ that focuses time-frequency
- Generalized Morse Wavelets

## Installation
`pip install git+https://github.com/OverLordGoldDragon/ssqueezepy` or clone repository; PyPi-available after 0.5.0.
`pip install ssqueezepy`. Or, for latest version (most likely stable):

`pip install git+https://github.com/OverLordGoldDragon/ssqueezepy`

## Examples

Expand Down
4 changes: 2 additions & 2 deletions examples/ridge_chirp.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def echirp(N):
pkw = dict(abs=1, w=.86, h=.9, aspect='auto', cmap='bone')
_Tx = np.pad(Tx, [[4, 4]]) # improve display of top- & bottom-most freqs
imshow(Wx, **pkw)
imshow(np.flipud(_Tx), norm=(0, 2e-1), **pkw)
imshow(np.flipud(_Tx), norm=(0, 4e-1), **pkw)
#%%# Estimate inversion ridge ###############################################
bw, slope, offset = .035, .45, .45
Cs, freqband = lin_band(Tx, slope, offset, bw, norm=(0, 2e-1))
Cs, freqband = lin_band(Tx, slope, offset, bw, norm=(0, 4e-1))
#%%###########################################################################
xrec = issq_cwt(Tx, kw['wavelet'], Cs, freqband)[0]
plot(xo)
Expand Down
4 changes: 2 additions & 2 deletions examples/se_ans0.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def cos_f(freqs, N=128, phi=0):
f, N = 12, 512

x = cos_f([f], N=N)
Wx, scales, *_ = cwt(x, wavelet, dt=1/N)
Wx, scales, *_ = cwt(x, wavelet, fs=N)

#%%# Show, print max row
imshow(Wx, abs=1, yticks=scales, title="f=%d, N=%d" % (f, N), show=1)
mxidx = np.where(np.abs(Wx) == np.abs(Wx).max())[0][0]
print("Max row idx:", mxidx, flush=True)

#%%# Plot around max row
#%%# Plot aroundI max row
idxs = slice(mxidx - 30, mxidx + 20)
Wxz = Wx[idxs]
imshow(Wxz, abs=1, title="abs(CWT), zoomed", show=0)
Expand Down
18 changes: 11 additions & 7 deletions ssqueezepy/wavelets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class Wavelet():
"""Central wavelet class. `__call__` computes Fourier frequency-domain
wavelet, `psih`, `.psifn` computes time-domain wavelet, `psi`.
wavelet, `psih`, `.psifn` computes time-domain wavelet, `psi`.
`Wavelet.SUPPORTED` for names of built-in wavelets passable to `__init__()`;
`Wavelet.VISUALS` for names of visualizations passable to `viz()`.
Expand Down Expand Up @@ -359,17 +359,18 @@ def _hhhat(_w):


#### Wavelet properties ######################################################
def center_frequency(wavelet, scale=10, N=1024, kind='energy', force_int=True,
def center_frequency(wavelet, scale=10, N=1024, kind='energy', force_int=None,
viz=False):
"""Energy center frequency (radian); Eq 4.52 of [1]:
wc_1 = int w |wavelet(w)|^2 dw 0..inf
wc_scale = int (scale*w) |wavelet(scale*w)|^2 dw 0..inf = wc_1 / scale
`force_int` (relevant only if kind='energy') can be set to False to compute
via formula - i.e. first integrate at a "well-behaved" scale, then rescale.
For intermediate scales, not much difference either way. Fro extremes, it
matches the continuous-time result closer - but this isn't recommended, as it
overlooks limitations imposed by discretization (trimmed/few-sample bell).
`force_int` (relevant only if kind='energy', defaults to True) can be set to
False to compute via formula - i.e. first integrate at a "well-behaved" scale,
then rescale. For intermediate scales, not much difference either way. For
extremes, it matches the continuous-time result closer - but this isn't
recommended, as it overlooks limitations imposed by discretization
(trimmed/few-sample bell).
For very high scales, 'energy' w/ `force_int=True` will match 'peak'; for
very low scales, 'energy' will always be less than 'peak'.
Expand Down Expand Up @@ -428,6 +429,7 @@ def _peak_wc(wavelet, scale, N):

wavelet = Wavelet._init_if_not_isinstance(wavelet)
if kind == 'energy':
force_int = force_int or True
wc, params = _energy_wc(wavelet, scale, N, force_int)
elif kind == 'peak':
wc, params = _peak_wc(wavelet, scale, N)
Expand Down Expand Up @@ -468,6 +470,7 @@ def _viz():

wavelet = Wavelet._init_if_not_isinstance(wavelet)

# formula criterion not optimal; thresholds will vary by wavelet config
use_formula = ((scale < 4 or scale > N / 5) and not force_int)
if use_formula:
scale_orig = scale
Expand Down Expand Up @@ -572,6 +575,7 @@ def _make_integration_t(wavelet, scale, N, min_decay, max_mult, min_mult):

wavelet = Wavelet._init_if_not_isinstance(wavelet)

# formula criterion not optimal; thresholds will vary by wavelet config
use_formula = ((scale < 4 or scale > N / 5) and not force_int)
if use_formula:
scale_orig = scale
Expand Down

0 comments on commit dd57f2e

Please sign in to comment.