0
0
Signal Processingdata~10 mins

Short-Time Fourier Transform (STFT) in Signal Processing - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Short-Time Fourier Transform (STFT)
Input Signal
Split into Overlapping Windows
Apply Window Function to Each Segment
Compute FFT of Each Windowed Segment
Collect FFT Results
Form Time-Frequency Matrix (Spectrogram)
STFT splits a signal into small overlapping parts, applies a window to each, then finds frequency content using FFT, producing a time-frequency view.
Execution Sample
Signal Processing
import numpy as np
from scipy.signal import stft

x = np.sin(2*np.pi*5*np.linspace(0,1,100))
f, t, Zxx = stft(x, nperseg=20)
This code computes the STFT of a 5 Hz sine wave sampled 100 times over 1 second using windows of length 20.
Execution Table
StepActionInput Segment IndicesWindow AppliedFFT Output ShapeNotes
1Split signal into first window0-19Hann window11 complex valuesFirst 20 samples selected and windowed
2Compute FFT of first window0-19Hann window11 complex valuesFFT shows frequency content of first segment
3Split signal into second window10-29Hann window11 complex valuesWindow shifted by 10 samples (50% overlap)
4Compute FFT of second window10-29Hann window11 complex valuesFFT of second segment
5Repeat for all windowsvariesHann window11 complex values eachProcess continues until end of signal
6Collect all FFT resultsall windowsHann windowMatrix shape (freq_bins x time_slices)Final STFT matrix formed
7ExitN/AN/AN/AAll windows processed, STFT complete
💡 All signal segments processed with overlapping windows, STFT matrix fully computed
Variable Tracker
VariableStartAfter 1After 2After 3Final
xFull signal array (length 100)UnchangedUnchangedUnchangedUnchanged
segment_indicesN/A0-1910-2920-39Last window indices
windowed_segmentN/ASegment 0-19 * HannSegment 10-29 * HannSegment 20-39 * HannLast windowed segment
FFT_outputN/A11 complex values11 complex values11 complex valuesAll FFTs collected in matrix
STFT_matrix_shapeN/AN/AN/AN/A(freq_bins=11, time_slices=9)
Key Moments - 3 Insights
Why do we use overlapping windows instead of non-overlapping?
Overlapping windows (see rows 1 and 3 in execution_table) ensure smooth transitions and better time resolution by capturing signal changes between segments.
What does the window function do to each segment?
The window (like Hann) reduces edge effects by tapering segment ends, preventing sharp jumps that distort FFT results (rows 1 and 3).
Why is the FFT output complex numbers?
FFT outputs complex values representing both amplitude and phase of frequencies, essential for reconstructing signal frequency content (rows 2 and 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the input segment indices for the third window processed?
A20-39
B0-19
C10-29
D30-49
💡 Hint
Check the 'Input Segment Indices' column for step 5 or infer from overlapping windows shifting by 10 samples
At which step does the STFT matrix get fully formed?
AStep 4
BStep 6
CStep 2
DStep 1
💡 Hint
Look for the step mentioning 'Final STFT matrix formed' in the 'Notes' column
If the window length (nperseg) was increased, how would the FFT output shape change?
ANo change in FFT output size
BFewer frequency bins (smaller FFT output)
CMore frequency bins (larger FFT output)
DFFT output becomes real numbers only
💡 Hint
FFT output length equals window length; increasing window length increases frequency resolution
Concept Snapshot
Short-Time Fourier Transform (STFT):
- Splits signal into overlapping windows
- Applies window function (e.g., Hann) to each segment
- Computes FFT on each windowed segment
- Produces time-frequency matrix (spectrogram)
- Balances time and frequency resolution via window size and overlap
Full Transcript
The Short-Time Fourier Transform (STFT) breaks a signal into small overlapping parts. Each part is multiplied by a window function to reduce edge effects. Then, the FFT is computed on each windowed segment to find its frequency content. These FFT results are collected into a matrix showing how frequencies change over time. Overlapping windows help capture smooth transitions. The FFT outputs complex numbers representing amplitude and phase. Increasing window size increases frequency resolution but reduces time resolution. This process creates a time-frequency view of the signal.