Member-only story

Short Time Fourier Transform

Nita Ghosh
3 min readDec 28, 2022

--

The Short Time Fourier Transform (STFT) is a special kind of time-frequency analysis (others are wavelet analysis etc.) used in cases where it is important to monitor the evolution of certain frequencies with time.

Workflow:

  1. Slice-up the time domain signal into small segments by sliding a defined window.
  2. Take Fourier transformation of each of these slices.

To look at the code, first, import libraries and generate a pseudo-dataset.

import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import stft

Suppose, you are doing an experiment and collecting signals in the form of time series data. There are some details about the experimental set-up that is important to take note of during data collection.

Total number of samples (N),

Sampling rate (number of samples collected in unit time (typically, second), n), i. e., the total time for data collection is N/n

# Number of samplepoints
N = 600
# sampling frequency (# of samples per second)
Fs = 800.0
# sample period; time spent per sample
T = 1.0 / Fs # N*T (#samples x sample period) is the tmax, i.e., signal recording time

Now, we create a fictitious dataset following the above parameters which is a linear combination of two sinusoidal functions having two characteristic frequencies (50 and 80 Hz, respectively).

x = np.linspace(0.0, N*T, N)
#generate…

--

--

Nita Ghosh
Nita Ghosh

No responses yet