Skip to content

Commit b426035

Browse files
author
tyler
committed
attempt to fix error with istft in example
added todo for stft_tukey return value
1 parent 396130e commit b426035

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

docs/examples_tutorial/e00_intro_set/s02_tone_stft_vs_spectrogram.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,24 @@
9494
time_spect_s = time_spect_s - time_spect_s[0]
9595

9696
# Compute the spectrogram with the stft option
97-
frequency_stft_hz, time_stft_s, stft_complex = stft.stft_tukey(
98-
timeseries=mic_sig,
97+
stft_obj = stft.get_stft_object_tukey(
9998
sample_rate_hz=frequency_sample_rate_hz,
10099
tukey_alpha=alpha,
101100
segment_length=time_fft_nd,
102101
overlap_length=time_fft_nd // 2, # 50% overlap
103102
scaling="magnitude",
104-
padding="zeros",
105103
)
104+
stft_complex = stft_obj.stft(mic_sig, padding="zeros")
105+
106+
stft_magnitude = np.abs(stft_obj.stft_detrend(x=mic_sig, detr="constant", padding="zeros"))
107+
# calculate the time and frequency bins
108+
time_stft_s = np.arange(start=0, stop=stft_obj.delta_t * np.shape(stft_magnitude)[1], step=stft_obj.delta_t)
109+
frequency_stft_hz = stft_obj.f
110+
111+
# frequency_stft_hz, time_stft_s, stft_complex = stft.stft_tukey(
112+
# timeseries=mic_sig,
113+
# padding="zeros",
114+
# )
106115
# Since one-sided, multiply by 2 to get the full power
107116
stft_power = 2 * np.abs(stft_complex) ** 2
108117

quantum_inferno/utilities/short_time_fft.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def get_stft_object_tukey(
6060
return stft_obj
6161

6262

63+
#todo: check for ways to return the stft object instead of the magnitude and rewrite calls to the function
6364
def stft_tukey(
6465
timeseries: np.ndarray,
6566
sample_rate_hz: Union[float, int],
@@ -72,6 +73,7 @@ def stft_tukey(
7273
"""
7374
Calculate the Short-Time Fourier Transform (STFT) of a signal with a Tukey window using ShortTimeFFT class
7475
Returns the frequency, time bins, and magnitude of the STFT similar to legacy scipy.signal.stft
76+
NOTE: the stft_detrend method used to get the magnitude makes it unable to be inverted using istft_tukey
7577
7678
:param timeseries: input signal
7779
:param sample_rate_hz: sample rate of the signal

0 commit comments

Comments
 (0)