Partial Sums of Fourier Series
A partial sum of a Fourier series is the truncated synthesis \[ y(t) \approx \frac{a_0}{2} + \sum_{n=1}^N a_n \cos(\omega_n t) + b_n \sin(\omega_n t), \] where and are the trigonometric series coefficients of and is a finite positive integer. The complex form is \[ y(t) \approx \sum_{n=-N}^N c_n e^{j \omega_n t}, \] where are the complex series coefficients of .
Partial sums are often necessary approximations for concrete calculations.
Consider the function one period of which shown in figure 6.2. Compute a partial sum approximation and plot it.
We proceed in Python. First, load packages.
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt
Over the period $[-T/2, T/2)$, the function $y(t)$ is defined as: $$ y(t) = \begin{cases} (4 A/T) t + A & -T/2 \leq t < -T/4 \\ 0 & -T/4 \leq t < T/4 \\ (4 A/T) t - A & T/4 \leq t < T/2. \end{cases} $$ We will use a partial sum of the complex Fourier series to approximate the function $y(t)$.
We begin symbolically. Define the symbolic variables.
= sp.symbols('A, T', real=True, positive=True)
A, T = sp.symbols('t', real=True, nonnegative=True)
t = sp.symbols('n', integer=True)
n = 2 * sp.pi * n / T w_n
Define the function $y(t)$.
= []
y_list 4 * A / T * t + A) # -T/2 <= t < -T/4
y_list.append(0 * A) # -T/4 <= t < T/4
y_list.append(4 * A / T * t - A) # T/4 <= t < T/2
y_list.append(= [-T/2, -T/4, T/4, T/2] lims
Compute the complex Fourier series coefficients $c_n$ (i.e., perform the Fourier series analysis).
= 0 # Initialize the coefficient
c_n for i in range(len(y_list)):
+= (1 / T) * sp.integrate(
c_n * sp.exp(-sp.I * w_n * t), (t, lims[i], lims[i + 1])
y_list[i]
)= c_n.simplify() c_n
Letting $A = 1$ and $T = 1$, we can compute the harmonic amplitude and phase spectrum.
= 10
N = {A: 1, T: 1}
params = np.full(2 * N + 1, np.nan, dtype=complex)
c_n_num = np.arange(-N, N + 1)
n_num for n_ in n_num:
= n_ + N
i = c_n.subs({n: n_}).evalf(subs=params) c_n_num[i]
Let’s plot the amplitude and phase spectrum.
= plt.subplots(2, 1, sharex=True)
fig, ax 0].stem(n_num, np.abs(c_n_num))
ax[0].set_title('Amplitude spectrum')
ax[1].stem(n_num, np.angle(c_n_num))
ax[1].set_title('Phase spectrum')
ax[1].set_xlabel('Harmonic $n$')
ax[ plt.draw()
Now, we will compute the partial sum of the complex Fourier series up to the $N$-th harmonic.
= sp.Sum(c_n * sp.exp(sp.I * w_n * t), (n, -N, N)).doit() y_N
Let’s plot the function $y(t)$ and the partial sum of the complex Fourier series. First we define the function $y(t)$ beyond the interval $[-T/2, T/2)$ with the use of the periodicity of the function.
def y_num(t, params, T, A):
= params[T]
T_ = np.mod(t + T_ / 2, T_) - T_ / 2
t = np.zeros_like(t)
y = (-T_ / 2 <= t) & (t < -T_ / 4)
i1 = (-T_ / 4 <= t) & (t < T_ / 4)
i2 = (T_ / 4 <= t) & (t < T_ / 2)
i3 = 4 * params[A] / T_ * t[i1] + params[A]
y[i1] = 0
y[i2] = 4 * params[A] / T_ * t[i3] - params[A]
y[i3] return y
Now we plot the function $y(t)$ and the partial sum of the complex Fourier series.
= np.linspace(-1, 1, 1001)
t_num = sp.lambdify(t, y_N.subs(params), 'numpy')(t_num)
y_N_num = plt.subplots()
fig, ax ='Partial sum')
ax.plot(t_num, y_N_num, label='Actual $y(t)$')
ax.plot(t_num, y_num(t_num, params, T, A), label'$t$')
ax.set_xlabel('$y(t)$')
ax.set_ylabel(
ax.legend() plt.show()
Online Resources for Section 6.2
No online resources.