Consider a signal in the time domain defined by the function
$$
f(t) = \cos ( 2\pi \nu t) e^{-t/\tau},
$$
with frequency $\nu = 250\;\mathrm{Hz}$ decaying exponentially with a lifetime $\tau = 0.2\;\mathrm{s}$. Plot the function, sampled at 1000 Hz, and its discrete Fourier transform against frequency.
Examine, by means of a suitable plot, the effect of apodization on the DFT by truncating the time sequence after (a) 0.5 s, (b) 0.2 s.
Solution P6.7.1
The code below truncates the function at 0.5 s and 0.2 s, showing the effect on its Fourier transform.
import numpy as np
import matplotlib.pyplot as plt
freq, tau = 250, 0.2
fsamp = 1000
duration = 10
t = np.arange(0, duration, 1 / fsamp)
n = len(t)
f = np.cos(2 * np.pi * freq * t) * np.exp(-t / tau)
for thresh in (0.5, 0.2):
# Truncate the signal for all times > thresh.
f[t > thresh] = 0.0
F = np.fft.rfft(f)
freq = np.fft.rfftfreq(n, 1 / fsamp)
plt.plot(t, f, lw=1)
plt.xlim(0, 0.6)
plt.xlabel(r"$t\;/\mathrm{s}$")
plt.ylabel(r"$f(t)$")
plt.show()
plt.plot(freq, abs(F), lw=1)
plt.xlabel("frequency /s$^{-1}$")
plt.ylabel(r"$\mathrm{FT}[f(t)]$")
plt.show()
An illustration of the effects of apodization of a signal by truncation of the time series at 0.5 s (top) and 0.2 s (bottom). The signal is on the left and its Fourier Transform on the right.