2.3. Fourier Series#
1. Representing Periodic Signals Using Fourier Series#
The Fourier series is a mathematical tool used to represent any periodic signal as a sum of sinusoidal components. These components, consisting of sines and cosines or complex exponentials, have frequencies that are integer multiples of the fundamental frequency of the signal.
For a periodic signal \( f(t) \) with a period \( T \), the Fourier series is expressed as:
Alternatively, using the complex exponential form:
where:
\( \omega_0 = \frac{2\pi}{T} \): Fundamental angular frequency,
\( a_n \): Coefficients for cosine terms,
\( b_n \): Coefficients for sine terms,
\( c_n \): Complex Fourier coefficients, with:
\[c_n = \frac{a_n - j b_n}{2}, \quad c_{-n} = \frac{a_n + j b_n}{2}.\]
Fourier Coefficients#
The coefficients are determined as follows:
DC Component:
(2.8)#\[a_0 = \frac{1}{T} \int_{0}^{T} f(t) \, dt\]Cosine Terms:
(2.9)#\[a_n = \frac{2}{T} \int_{0}^{T} f(t) \cos(n\omega_0 t) \, dt\]Sine Terms:
(2.10)#\[b_n = \frac{2}{T} \int_{0}^{T} f(t) \sin(n\omega_0 t) \, dt\]Complex Coefficients:
(2.11)#\[c_n = \frac{1}{T} \int_{0}^{T} f(t) e^{-jn\omega_0 t} \, dt\]
2. Examples of Sound Waves as Periodic Signals#
Sound waves from musical instruments or voices can often be approximated as periodic signals. For instance:
Pure Tones: A tuning fork generates a sinusoidal waveform, which can be represented using a single term in the Fourier series.
Complex Tones: A piano produces harmonics, resulting in multiple terms in the Fourier series.
Square Waves: Periodic square waves can approximate digital signals and are represented by a Fourier series containing odd harmonics.
The periodic nature of these sounds makes Fourier series a powerful tool for analyzing and synthesizing audio signals in acoustics.
3. Basic Applications in Analyzing Acoustic Phenomena#
Fourier series finds extensive applications in acoustics:
Room Acoustics: Analyzing how a room resonates at specific harmonic frequencies.
Filter Design: Designing acoustic filters that emphasize or suppress particular harmonics.
Sound Synthesis: Generating musical tones by combining harmonic components.
Noise Analysis: Decomposing noise into frequency components to identify and mitigate problematic frequencies.
Example: Representation of a Square Wave#
A square wave with period \( T \) can be represented using its Fourier series:
This series contains only odd harmonics, demonstrating how Fourier analysis isolates specific frequency components.
Interactive Demonstration I#
Below is the Python code to simulate the approximation accuracy of the Fourier series for two different periodic signals (Square Wave or Sawtooth Wave). Adjust the number of terms in the Fourier series to observe the convergence behaviour.
import numpy as np
import matplotlib.pyplot as plt
import ipywidgets as widgets
from ipywidgets import interact
def plot_fourier_series(signal_type, terms):
t = np.linspace(0, 1, 1000)
f = np.zeros_like(t)
if signal_type == "Square Wave":
for n in range(1, 2 * terms, 2):
f += (4 / np.pi) * (1 / n) * np.sin(2 * np.pi * n * t)
elif signal_type == "Sawtooth Wave":
for n in range(1, terms + 1):
f += (2 / np.pi) * ((-1) ** (n + 1)) * (1 / n) * np.sin(2 * np.pi * n * t)
plt.figure(figsize=(10, 6))
plt.plot(t, f, label=f"{signal_type} with {terms} terms")
plt.title("Fourier Series Approximation")
plt.xlabel("Time")
plt.ylabel("Amplitude")
plt.legend()
plt.grid()
plt.show()
interact(plot_fourier_series, signal_type=["Square Wave", "Sawtooth Wave"], terms=(1, 20, 1))
Interactive Demonstration II#
Below is the Python code to visualize how a truncated Fourier series can approximate a sawtooth wave. It progressively adds more terms (nmax
) to improve the approximation. It computes and plots Fourier coefficients and the amplitude spectrum of the signal. There is also an option to listen to the synthesized sound.
import micropip
await micropip.install("IPython")
import numpy as np
import matplotlib.pyplot as plt
from scipy.fft import fft, fftfreq
import ipywidgets as widgets
from ipywidgets import interact, fixed
from IPython.display import Audio
# Example usage
f = 100 # Frequency of the signal (Hz)
s_amp = 1.0 # Amplitude of the signal
fs = 48000 # Sampling frequency (Hz)
nmax = 20 # Maximum number of Fourier terms
play_sound = 1 # 1 to play sound, 0 otherwise
@interact(
f=widgets.IntSlider(min=20, max=50, step=10),
s_amp=fixed(s_amp),
fs=fixed(fs),
nmax=widgets.IntSlider(min=1, max=100, step=1, continuous_update=True),
ps=fixed(play_sound),
)
def sawtooth_like_signal(f, s_amp, fs, nmax, ps):
"""
Demonstrates the convergence of Fourier series to a sawtooth-like signal.
Parameters:
f : float
Frequency of the signal (Hz).
s_amp : float
Amplitude of the signal.
fs : int
Sampling frequency (Hz).
nmax : int
Maximum number of Fourier series terms.
"""
# Time and sawtooth signal generation
T = 1 / f
dt = 1 / fs
t = np.arange(-T / 2, T / 2, dt)
s = 2 * s_amp * t / T
stot = np.tile(s, 10) # Repeat signal for 10 periods
ttot = np.arange(0, 10 * T, dt)
# Fourier series approximation
C = np.zeros_like(s)
Cn = []
for n in range(1, nmax + 1):
coeff = 2 * s_amp / (np.pi * n)
term = coeff * np.sin(n * 2 * np.pi * t / T)
C += term if n % 2 == 1 else -term
Cn.append(1 / n)
Ctot = np.tile(C, 10) # Repeat Fourier approximation for 10 periods
# Plot the sawtooth signal and Fourier approximation
plt.figure(figsize=(10, 6))
plt.plot(ttot, stot, "k", label="Original Sawtooth")
plt.plot(ttot, Ctot, "b", label=f"Fourier Approximation (n={nmax})")
plt.axis([0, max(ttot), -2 * s_amp, 2 * s_amp])
plt.xlabel("t (s)", fontsize=14)
plt.ylabel("s (-)", fontsize=14)
plt.title("Convergence of Fourier Series to Sawtooth Signal", fontsize=16)
plt.legend()
plt.grid(True)
plt.show()
# Plot the Fourier coefficients
plt.figure(figsize=(8, 4))
plt.bar(range(1, nmax + 1), Cn, color="k", width=0.8)
plt.xlabel("n (-)", fontsize=14)
plt.ylabel("Cn (-)", fontsize=14)
plt.title("Fourier Coefficients", fontsize=16)
plt.grid(True)
plt.show()
if ps == 1:
audio_widget = Audio(Ctot, rate=fs)
display(audio_widget)
print(" Play the sound.")
sawtooth_like_signal(f, s_amp, fs, nmax, play_sound)
References#
[JJ13]
[Kut06]
Wikipedia contributors. “Fourier series.” Wikipedia, The Free Encyclopedia. Available at: https://en.wikipedia.org/wiki/Fourier_series