pythonscipysignal-processing

Confused by the inputs of scipy.signal.ShortTimeFFT


I'm confused by the 'hop' and 'fs' inputs in the documentation.

"hop int: The increment in samples, by which the window is shifted in each step."

is this asking the number of samples between each sample of the given dataset? For example, if I give it a dataset with 1000 entries, and I tell it 100, it will perform an fft on 10 sections of a 100 points?

"fs float: Sampling frequency of input signal and window. Its relation to the sampling interval T is T = 1 / fs."

Is this asking for the frequency that the provided sample was taken at?


Solution

  • Short-time Fourier Transform cuts your signal into smaller parts, known as windows/frames. Those windows have their size, often referred as frame_size/window_size/window_length. There is also parameter hop_size that defines how many offset samples are between consecutive frames.

    enter image description here

    IMAGE SOURCE: Area-Efficient Short-Time Fourier Transform Processor for Time–Frequency Analysis of Non-Stationary Signals

    fs is sampling frequency, which is not that important when it comes to SFFT computation. It is very important if you define other parameters (window size, hop size) in seconds rather than in number of samples. Inside the stft function it will be used to compute how many samples are in a window of e.g. 20ms.

    window_size_in_samples = int(np.round(sampling_frequency * window_size_in_seconds))