MIT 6.300 — Lecture 15
Short-Time Fourier Transform
§ Lecture: Updated DFT Conventions
This note is purely definitional, but it's an important use of jargon that will be assumed for this lecture.
Definition. Let be a DT signal with length . The of when is the result of first zero-padding to have length , then taking the length- DFT of the result.
So far, we've only talked about the case. This lecture will use the case.
Remark. In contrast, the case is completely nonsensical.
§ Lecture: Spectrograms
If you were to shove a recording of a piano playing a single chord through the DFT, you'd be able to retrieve the frequencies of that chord. But if you were to shove a recording of a piano playing an entire song through the DFT, you'd only retrieve the set of all frequencies present in the entire song—not the timing of each frequency, or even what order they came in.
The DFT no longer works when frequencies change over time. If we want to analyze the frequencies in an entire song, we need data that shows the frequencies present at each moment in time.

Such data is called a spectrogram, pictured above. It is produced by performing several short-time DFTs.

Problem. You're given a DT signal with sampling rate samples per second and want a spectrogram such that:
Sixteenth notes at a tempo of beats per minute (each lasting of a second) are distinguished from each other.
Errors in frequency are less than or equal to Hz.
Determine the range of all possible window lengths you might use.
Solution: The first condition implies , and the second condition implies . Together, this implies .
This process of taking DFTs over sliding windows is known as the Short-Time Fourier Transform (STFT).
§ Lecture: Streaming Windows
Recall from Lecture 10 that applying a band-pass filter to a DT signal is equivalent to multiplying its DTFT by a box-shaped frequency response , which is itself equivalent to convolving with the unit-sample response .
In the following discussion, we'll try to isolate the melody of the following.
When working with finite-length DFTs, two issues arise.
The FFT runs in time. For very long DT signals , it is not feasible to filter the entire signal at once.
Filtering DT signals via circular convolution gives rise to time aliasing (see Lecture 13), yielding buggy noises.
A natural fix for the first issue is to apply STFT:
Bad Approach. Break into subsignals of length . For each subsignal, compute , where is a length- unit-sample response of a band-pass filter. Finally, concatenate all of the together.
Here's how the result sounds:
Clearly something sounds off. The main issue comes from our neglect of issue #2: circular convolution and time-aliasing.
Remark. The reason why circular convolution fails is subtle. It is true that each only contains frequencies inside the desired band. But consider the following two extensions of from the domain to the domain .
All that can be said is that the DTFT of contains only band frequencies—but not for . Yet the concatenation of all of the is the sum of the —not the .
Therefore, there is no reason for the DTFT of the concatenation of the to only contain band frequencies.
We really should be taking a linear convolution, not a circular convolution, meaning we need to allow time in one window to overflow into the next, rather than aliasing it back around.
Good Approach (Overlap-Add — Time Domain). Break into subsignals of length . For each subsignal, compute the length- subsignal , where is a length- unit-sample response of a band-pass filter.
Finally, add all of the together.
Note that each window's linear convolution overlaps with the linear convolutions from other windows—hence the name “overlap-add” and not “overlap-concatenate”.
We can equivalently think of overlap-add from the frequency domain.
Good Approach (Overlap-Add — Frequency Domain). Break into subsignals of length . For each subsignal, zero-pad to have length , then compute its DFT of size . Then compute the element-wise products , where is a length- frequency response of a band-pass filter.
Finally, compute the length- subsignals and sum them together.
Note that is the DFT of size of , where the length of is only . (Implicitly, we zero-pad first…)
There are two reasons for wanting to think from the perspective of the frequency domain.
It's how we would go about algorithmically implementing such a filter.
Naive linear convolution is , but two DFTs plus an element-wise product is .
It lets us think more closely about filter design: a better filter will have a better .
We'll discuss that second point in the next section: designing and .
§ Lecture: Short-Time Filter Design
The challenge is that , yet has some length that is less than the length of . We must compromise in our design of so that the last entries of are all zeroes.
Box Approach. Let's work in reverse: we'll design an of length , then hope the we get is an effective filter.
Take a perfect (continuous) filtering frequency response . No compromises here.
Define to be the discretized version of the impulse response , truncated to length .
Define to be a version of that is zero-padded to have length .
Define of length .
Then is our designed frequency response . Here's how the result sounds when used with overlap-add:
That works pretty well! But if you listen closely, you can still faintly hear some of the frequencies from the harmony, especially in the second half. You can see why in the graph of : the graph has “ripples” that make it an imperfect filter.
These ripples come from Step #2: ideally, we would take to be an infinite DT signal, but instead, we must compromise by truncating to have length .
Here's the trick, though: what if we truncated a bit more smoothly?
Hann Window Approach. We take the same approach as before, but we instead define as follows.
The signal is called a Hann Window, in contrast to the typical rectangular window
used in the previous approach. Yet another alternative choice is a triangle window; you can observe the efficacy of each of these truncation methods through the diagram below.
In the previous approach, the frequencies present in would be the result of convolving our perfect filter with the ripple-filled signal . No wonder the result had so many ripples!
Expectedly, using the Hann window to construct the truncation gives a much cleaner .
And it sounds much better, too—no more harmonies still lingering around.
§ Recitation: Windows and Decibels
We already saw how the rectangular, triangular, and Hann windows compare. But let's compare them at a logarithmic scale.

In the above, decibels are a relative unit of measurement. (So turning the volume knob up won't alter these graphs.)
Definition. Given a signal , say its highest value is . Then in decibels is .
So a measurement of dB corresponds to a measurement in the signal that is the highest measurement. For reference, measurements of dB are essentially inaudible, whereas measurements of dB are still weakly perceptible.
§ Recitation: Short-Time Fourier Transform
We never actually formally defined the STFT. Let's do that.
Definition. Given a signal and a window , the STFT is the two-dimensional array:
Note that and each only appear once on the RHS. The value of controls the frequency being measured, and the value of controls the time being measured. A spectrogram is a diagram that displays .
Note that the STFT of depends on three different parameters:
Importantly, , , and do not have to be equal!
You can take , meaning each data point will be used multiple times!
Or , meaning some data points are completely ignored…
You can take , meaning the data collected from the window will be zero-padded to have length .
It does not make sense to take . You cannot take a DFT of size on a DT signal of length .
Compare the cleanliness of a rectangular window (at left) versus a Hann window (at right).

Expectedly, the parameter settings affect the spectrogram as follows.
Increasing increases the frequency resolution, at the cost of time resolution.
Increasing increases the fineness of frequency measurements—but only superficially. (Recall Lecture 13.)
Decreasing increases the fineness of time measurements.
Of course, these improvements to parameter settings come at a cost of time complexity.
Here's how the result sounds: 





