I’m trying to write an algorithm for lazily plotting spectrograms on long, high-sampled audio files.
I want to break my audio array into chunks of size equal to the width of my fft sliding window for computing [nfft//2+1:1] sub-spectrogram arrays.
However, scipy still wants to create 2 windows, one ranging from [-nfft/2 : nfft/2] and one from [nfft/2 : 1.5 * nfft/2].
I understand from the doc that the first window is centered on the first sample. Does anyone know if I can force the first window to be aligned with the first sample?
Or should I just create a new ShortTimeFFT with hop=nfft/2
and only consider the middle window of the 3 processed windows?
Here is a minimal reproducible example:
from scipy.signal import ShortTimeFFT
from scipy.signal.windows import hamming
import numpy as np
sig = np.random.randn(1024)
fs = 48_000
nfft = 1024
winsize = 1024
window = hamming(M = nfft)
fft = ShortTimeFFT(win = window, hop = nfft, fs = fs, mfft = nfft)
print(f"{fft.p_num(sig.shape[0])} windows from samples {fft.k_min=} to sample {fft.k_max(sig.shape[0])=}")
# 2 windows from samples fft.k_min=-512 to sample fft.k_max(sig.shape[0])=1536