Framing
Contents
9.1. Framing#
The key idea behind the Short-Time Fourier transform is to divide a long signal up into short pieces, and analyze each piece separately. While the frequency content of a signal may change over long periods of time, real signals tend to be approximately stationary if we look only at short fragments.
These fragments are known as frames, and typically span a few thousand samples at a time.
The number of samples in a frame is conveniently known as the frame length, which we’ll denote by
In addition to the frame length, we also must decide how many frames to take.
This is controlled by the hop length: the number of samples between frames, which we will denote by
The framing process is illustrated by Fig. 9.1.
Fig. 9.1 Top: a signal
Combining these two quantities, the
Here, we are using a two-dimensional array
The
Equivalently, in Python, the
x[k * NH:k * NH + NF]
Using some dimensional analysis, we can convert frame indices to time as well:
From this, we can observe that
9.1.1. How many frames are there?#
Calculating the exact number of frames in a signal from the framing parameters can be a little subtle, but it’s not too hard if we’re careful.
It can be helpful to think of a few of extreme cases:
What if
, so that the frame length is exactly the same as the signal length? In this case, there should be only 1 frame. The hop length does not matter here because any index offset other than 0 would push the frame off the end of the input array, and we would not have a full frame.What if
? In this case, each sample is a frame by itself, so we should have frames (one per sample).What if
and ? In this case, we’re effectively decimating the signal by a factor of 2 (taking every other sample), so we should have frames (if is even) or (if is odd).
More generally, how many steps
Counting frames
A signal of
The “extra”
Note that (9.1) divides the signal length (minus one frame) by the hop length.
However, the hop length generally may not evenly divide
The Python equivalent of (9.1) is:
# Integer division // rounds down
N_frames = 1 + (len(x) - N_F) // N_H
Now that we have a handle on how to apply framing to a signal, we are ready to define the Short-Time Fourier transform.