Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
OverLordGoldDragon committed Jan 14, 2021
1 parent 4024d80 commit fac0c82
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
- `cwt()` no longer returns `x_mean`
- `padsignal` now only returns padded input by default; `get_params=True` for old behavior
- Moved methods: `phase_cwt` & `phase_cwt_num` from `ssqueezing` to `_ssq_cwt`
- _In future release_: return order of `cwt` and `stft` will be changed to have `Wx, dWx` and `Sx, dSx`
- _In future release_: return order of `cwt` and `stft` will be changed to have `Wx, dWx` and `Sx, dSx`, and `ssq_cwt` and `ssq_stft` to have `Tx, Wx` and `Tx, Sx`.
2 changes: 1 addition & 1 deletion ssqueezepy/_ssq_cwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def ssq_cwt(x, wavelet='morlet', scales='log', nv=None, fs=None, t=None,
Input vector, 1D.
wavelet: str / tuple[str, dict] / `wavelets.Wavelet`
Wavelet sampled in Fourier frequency domain. See help(cwt).
Wavelet sampled in Fourier frequency domain. See `help(cwt)`.
scales: str['log', 'linear', 'log:maximal', ...] / np.ndarray
CWT scales. See `help(cwt)`.
Expand Down
15 changes: 8 additions & 7 deletions ssqueezepy/_ssq_stft.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def ssq_stft(x, window=None, n_fft=None, win_len=None, hop_len=1, fs=1.,
modulated=True, ssq_freqs=None, padtype='reflect', squeezing='sum',
mapkind='maximal', gamma=None):
gamma=None):
"""Synchrosqueezed Short-Time Fourier Transform.
Implements the algorithm described in Sec. III of [1].
Expand All @@ -19,7 +19,7 @@ def ssq_stft(x, window=None, n_fft=None, win_len=None, hop_len=1, fs=1.,
window, n_fft, win_len, hop_len, fs, padtype, modulated
See `help(stft)`.
ssq_freqs, squeezing, mapkind
ssq_freqs, squeezing
See `help(ssqueezing.ssqueeze)`.
gamma: float / None
Expand Down Expand Up @@ -52,17 +52,18 @@ def ssq_stft(x, window=None, n_fft=None, win_len=None, hop_len=1, fs=1.,
n_fft = n_fft or len(x)
_check_squeezing_arg(squeezing)

Sx, dSx = stft(x, window, n_fft=n_fft, win_len=win_len,
hop_len=hop_len, fs=fs, padtype=padtype,
modulated=modulated, derivative=True)
Sx, dSx = stft(x, window, n_fft=n_fft, win_len=win_len, hop_len=hop_len,
fs=fs, padtype=padtype, modulated=modulated, derivative=True)

Sfs = np.linspace(0, .5, Sx.shape[0]) * fs
w = phase_stft(Sx, dSx, Sfs, gamma)

if ssq_freqs is None:
ssq_freqs = Sfs
Tx, ssq_freqs = ssqueeze(Sx, w, transform='stft', squeezing=squeezing,
ssq_freqs=Sfs)
ssq_freqs=ssq_freqs)

return Tx, ssq_freqs, Sx, dSx, w
return Tx, ssq_freqs, Sx, Sfs, dSx, w


def issq_stft(Tx, window=None, cc=None, cw=None, n_fft=None, win_len=None,
Expand Down
10 changes: 7 additions & 3 deletions ssqueezepy/_stft.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,22 @@ def get_window(window, win_len, n_fft=None, derivative=False):

if window is not None:
if isinstance(window, str):
# fftbins=True -> 'periodic' window -> narrower main side-lobe and
# closer to zero-phase in left=right padded case
# for windows edging at 0
window = sig.get_window(window, win_len, fftbins=True)

elif isinstance(window, np.ndarray):
if len(window) != win_len:
WARN("len(window) != win_len (%s != %s)" % (len(window), win_len))
if len(window) < (win_len + pl + pr):
window = np.pad(window, [pl, pr])

else:
raise ValueError("`window` must be string or np.ndarray "
"(got %s)" % window)
else:
# fftbins=True -> 'periodic' window -> narrower main side-lobe and
# closer to zero-phase in left=right padded case
# for windows edging at 0
# sym=False <-> fftbins=True (see above)
window = sig.windows.dpss(win_len, 4, sym=False)
window = np.pad(window, [pl, pr])

Expand All @@ -221,6 +224,7 @@ def get_window(window, win_len, n_fft=None, derivative=False):
xi = _xifn(1, Nw)
if Nw % 2 == 0:
xi[Nw // 2] = 0
# frequency-domain differentiation; see `dWx` return docs in `help(cwt)`
diff_window = ifft(wf * 1j * xi).real

return (window, diff_window) if derivative else window
Expand Down
2 changes: 1 addition & 1 deletion ssqueezepy/ssqueezing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def ssqueeze(Wx, w, ssq_freqs=None, scales=None, fs=None, t=None, transform='cwt
# Arguments:
Wx or Sx: np.ndarray
CWT or STFT of `x`. Wx is assumed L1-normed.
CWT or STFT of `x`. `Wx` is assumed L1-normed.
w: np.ndarray
Phase transform of `Wx` or `Sx`. Must be >=0.
Expand Down

0 comments on commit fac0c82

Please sign in to comment.