This chapter is not in Prof. Morlier’s original notes. It fills a natural gap: the basics chapters use the Laplace/frequency-response machinery extensively (Chapter 2’s FRF, Chapter 3’s Duhamel convolution) but never show how to go the other way — extracting frequency content from a measured or simulated time signal. This is exactly the “Experimental Modal Analysis and System Identification” topic the original notes flag as missing at the very end. Structure and motivation are inspired by PEC00025’s Fourier-transform class.
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
from scipy.integrate import solve_ivp
plt.rcParams["figure.figsize"] = (7, 4.2)
plt.rcParams["axes.grid"] = True8.1 From Fourier series to the Fourier transform¶
Any periodic signal with period can be written as a Fourier series:
Let’s decompose a square wave and watch the series converge as we add harmonics (the famous Gibbs phenomenon — an overshoot near the discontinuity that never disappears, no matter how many harmonics are added).
T0 = 1.0
t = np.linspace(-1.5, 1.5, 3000)
square = signal.square(2 * np.pi * t / T0)
fig, ax = plt.subplots()
ax.plot(t, square, "k", lw=0.8, alpha=0.4, label="exact square wave")
for N in [1, 3, 9, 49]:
approx = np.zeros_like(t)
for n in range(1, N + 1, 2): # odd harmonics only, by symmetry
approx += (4 / np.pi) * np.sin(2 * np.pi * n * t / T0) / n
ax.plot(t, approx, label=f"N={N} harmonics")
ax.set_xlabel("t / T0")
ax.set_title("Fourier series reconstruction of a square wave (Gibbs phenomenon)")
ax.legend(fontsize=8)
plt.show()
For a non-periodic signal, letting turns the discrete harmonics into a continuum, and the sum becomes an integral: the Fourier transform
which is exactly the Laplace transform (Chapter 2) evaluated on the imaginary axis, — the two are the same tool, just restricted to different classes of signals (Laplace also handles growing/decaying transients via ).
8.2 The Discrete Fourier Transform (DFT) and FFT¶
In practice we only ever have sampled data: points at sampling interval (sampling frequency ). The DFT (computed efficiently by the FFT algorithm) gives the frequency content at discrete frequencies spaced by , up to the Nyquist frequency .
fs = 100.0 # Hz
T = 10.0 # seconds
t = np.arange(0, T, 1 / fs)
f1, f2 = 3.0, 7.5 # Hz
x = 1.0 * np.sin(2 * np.pi * f1 * t) + 0.5 * np.sin(2 * np.pi * f2 * t)
X = np.fft.rfft(x)
freqs = np.fft.rfftfreq(len(x), d=1 / fs)
amplitude = 2 * np.abs(X) / len(x) # scale so peaks read as the true sine amplitudes
fig, axes = plt.subplots(2, 1, figsize=(7, 6))
axes[0].plot(t, x)
axes[0].set_xlabel("Time [s]")
axes[0].set_title("Time signal: two sines at 3.0 and 7.5 Hz")
axes[1].stem(freqs, amplitude, basefmt=" ")
axes[1].set_xlim(0, 15)
axes[1].set_xlabel("Frequency [Hz]")
axes[1].set_ylabel("Amplitude")
axes[1].set_title("Amplitude spectrum (FFT)")
plt.tight_layout()
plt.show()
print(f"Peaks found near {freqs[np.argsort(amplitude)[-2:]]} Hz (true: {f1}, {f2} Hz)")
Peaks found near [7.5 3. ] Hz (true: 3.0, 7.5 Hz)
8.3 Spectral leakage and windowing¶
The DFT implicitly assumes the sampled window repeats periodically. If the record does not contain an integer number of cycles, energy “leaks” into neighbouring frequency bins.
f0 = 5.3 # Hz -- NOT a multiple of 1/T, so it doesn't fall exactly on an FFT bin
x_leak = np.sin(2 * np.pi * f0 * t)
X_rect = np.fft.rfft(x_leak)
X_hann = np.fft.rfft(x_leak * signal.windows.hann(len(x_leak)))
freqs = np.fft.rfftfreq(len(x_leak), d=1 / fs)
fig, ax = plt.subplots()
ax.semilogy(freqs, np.abs(X_rect) / len(x_leak), label="rectangular window (no taper)")
ax.semilogy(freqs, np.abs(X_hann) / len(x_leak), label="Hann window")
ax.set_xlim(0, 15)
ax.set_ylim(1e-5, 1)
ax.set_xlabel("Frequency [Hz]")
ax.set_title(r"Spectral leakage at $f_0=5.3$ Hz, and how a Hann window reduces it")
ax.legend()
plt.show()
The rectangular window’s spectrum has a slowly-decaying sidelobe pattern (leakage smeared across many bins); the Hann-windowed spectrum concentrates energy much more tightly around the true frequency, at the cost of a slightly wider main lobe. This trade-off (leakage vs. resolution) is central to any real signal-processing / modal-testing workflow.
8.4 Power spectral density and identifying a resonance from noise¶
scipy.signal.welch estimates the power spectral density (PSD) of a signal by averaging
periodograms of overlapping, windowed segments — much less noisy than a single raw FFT for
stochastic signals.
This is exactly how a real experimental FRF is often measured: excite the structure with broadband (e.g. random or hammer-impact) noise, and estimate from the input/output PSDs. Let’s demonstrate this on the SDOF system from the basics chapters.
m, k = 1.0, 1.0
zeta = 0.05
c = 2 * zeta * np.sqrt(k * m)
wn = np.sqrt(k / m)
fs = 50.0
T = 400.0
t = np.arange(0, T, 1 / fs)
rng = np.random.default_rng(0)
f_noise = rng.standard_normal(len(t)) # broadband random forcing
def sdof_ode(t_, y, f_interp):
x, v = y
f = f_interp(t_)
return [v, (f - c * v - k * x) / m]
f_interp = lambda tt: np.interp(tt, t, f_noise)
sol = solve_ivp(sdof_ode, [t[0], t[-1]], [0, 0], args=(f_interp,), t_eval=t, max_step=1 / fs)
x_resp = sol.y[0]
freqs_psd, Sff = signal.welch(f_noise, fs=fs, nperseg=2048)
_, Sxx = signal.welch(x_resp, fs=fs, nperseg=2048)
_, Sxf = signal.csd(x_resp, f_noise, fs=fs, nperseg=2048)
H_est = Sxf / Sff
H_theory = 1.0 / (k - m * (2 * np.pi * freqs_psd) ** 2 + 1j * c * (2 * np.pi * freqs_psd))
fig, ax = plt.subplots()
ax.semilogy(freqs_psd, np.abs(H_est), label="Estimated |H| from input/output PSDs (Welch)")
ax.semilogy(freqs_psd, np.abs(H_theory), "--", label="Theoretical |H(jw)| (Chapter 2 formula)")
ax.set_xlim(0, 0.5)
ax.set_xlabel("Frequency [Hz]")
ax.set_ylabel("|H|")
ax.set_title("Recovering the FRF of an unknown system from random-noise excitation")
ax.legend()
plt.show()
print(f"Theoretical resonance omega_n/(2 pi) = {wn/2/np.pi:.4f} Hz")Theoretical resonance omega_n/(2 pi) = 0.1592 Hz
The peak of the estimated FRF sits right at the theoretical printed above — recovered without ever writing down the equation of motion, purely from measured input/output signals. This is the essence of experimental modal analysis / system identification: exactly the topic the original lecture notes point to as “missing” and refer to a companion French-language lecture note for.