## Choose the one that behaves nicely at the boundaries

If you look up the history of Fourier analysis, youâll see that Jean-Baptiste Joseph Fourier formalized the series that would bear his name while working on the heat flow problem.

A Fourier series represents a periodic signal as a sum of sinusoids whose frequencies are integer multiple of the fundamental frequency.

We intuitively know that a hot spot in a conductive medium will spread heat in all directions until the temperature is uniform. There is no visible oscillatory behavior in this phenomenon, neither in space nor time. Why then introduce a series of sinusoids?

The initial temperature profile, the governing differential equation, and the boundary conditions determine the evolution of the temperature function u(x, t) in the problem of a one-dimensional conductive medium such as a thin metal bar. As it turns out, the spatial frequency components of the initial temperature profile will be damped by a decaying exponential over time, with an exponential factor that grows like the square of the spatial frequency. In other words, high frequencies in the initial temperature profile decay much faster than the low frequencies, which explains the smoothing of the temperature distribution.

In this story, **we will review the basics of Fourier series for a function defined on a finite domain**. Weâll cast the problem such that the resulting Fourier series has some desirable properties at the domain boundaries. This approach will pay off when we apply the Fourier series to solve a problem involving differential equations with some constraints at the boundaries.

## Fourier series: a tool to represent periodic functions

Fourier series can approximate periodic functions. Let g(x) be a periodic function with period 2L.

Why a period of 2L?

We are interested in functions defined on the finite domain [0, L]. We can construct a periodic function g(x) whose period is 2L from the function f(x) defined over [0, L] with some padding chosen to have desirable properties. Weâll get back to this point later.

Assuming a Fourier series exists, we can write g(x) as:

As an example, letâs consider the following periodic function g(x), with period 2L = 0.6:

Applying equations (2), (3), (4) and using Simpson numerical integration gives the following values for aâ, aâ, and bâ:

These values, the Fourier coefficients, allow us to build an approximation of g(x) with equation (1). The more terms we include in the summation, the more precise will be the approximation. Figure 2 shows a few approximations with various numbers of terms from the summation in equation (1).

We can already formulate a few observations:

- Finite discontinuities in the signal are tolerable, but they generate wiggling in the reconstructed approximation. We refer to these oscillations in the neighborhood of discontinuities as the Gibbs phenomenon.
- The Fourier series is the sum of an infinite number of terms, but we can truncate the summation and still have a reasonable approximation of the original function.
- The original signal could be a sample of discrete points. The Fourier series can interpolate the function anywhere on the x-axis.

## Functions defined on a finite domain

In engineering problems, we often encounter functions defined on a finite domain. For example, in the case of the one-dimensional temperature distribution of a conductive medium, the temperature function is defined over the [0, L] range, where L is the length of the thin metal bar. How can the Fourier series be used in this setting?

To answer this question, we first acknowledge that any periodic function g(x) that coincides with the function on interest f(x) over the range [0, L] is a valid candidate for a Fourier series representation of f(x). After all, we donât care how the Fourier series behaves outside the [0, L] range.

## The naive periodic replication of f(x)

The most straightforward way to build g(x) is to replicate f(x) in the interval [-L, 0], as in figure 3:

The Fourier integration for the naive periodic replication of f(x) yields equations (5) to (7):

By inserting (5), (6), (7) in equation (1) to f(x) from Figure 3, we obtain the Fourier series reconstruction shown in Figure 4:

The Fourier series closely matches the original signal, except at the range boundaries, where the reconstruction oscillates and jumps. Since we explicitly constructed a periodic signal of period L, the Fourier series interprets the transitions at x=0 and x=L as finite discontinuities.

Finite discontinuities are allowed by the Fourier series, but the Gibbs phenomenon degrades the reconstruction around the discontinuities.

For many engineering cases, this is problematic. For example, in the case of heat transfer in a thin metal bar, what happens at the bar extremities (a.k.a. the boundary conditions) is an intrinsic part of the problem description. We could have an isolated bar, which implies the temperature gradient must be 0 at both ends. Alternatively, we could have arbitrary set temperatures at x=0 and x=L. In these common scenarios, we cannot use the naive periodic replication of f(x) because the Gibbs phenomenon corrupts the signal at the ends of the range.

## Even half-range expansion

Instead of replicating f(x), we could have a flipped version of f(x) in the range [-L, 0], like in Figure 5:

This approach eliminates the discontinuities at x=0 and x=L. The Fourier integration for the even half-range expansion of f(x) yields equations (8) to (10):

Figure 6 shows the Fourier series reconstruction of f(x):

A feature of the even half-range expansion is the fact that g(x) being even, all bâ coefficients (Cf. equation (10)) are 0, and thus its Fourier series is exclusively made of cosine terms. As a consequence, **the derivative of the Fourier series is zero at x=0 and x=L**. You can verify this by differentiating equation (1) with respect to x, with all bâ terms set to 0.

That is what we want in a scenario where, for example, the metal bar is isolated, so there is no heat leakage at the extremities.

## Odd half-range expansion

What if we created an odd function instead? This can be accomplished by pasting a rotated version of f(x) in the interval [-L, 0], like in Figure 7:

The Fourier integration for the odd half-range expansion of f(x) yields equations (11) to (13):

Figure 8 shows the Fourier series reconstruction of f(x):

g(x) being odd, the Fourier series is made exclusively of sine terms. For this reason, **the Fourier series is zero at x=0 and x=L**. This property can be exploited, for example, when we simulate the shape of an oscillating guitar string. The string height is constrained to 0 at x=0 and x=L, so we would naturally model the initial condition with odd half-expansion.

## Even quarter-range expansion

We can be even more creative and design a periodic function with a period of 4L. If we want a derivative of exactly 0 at x=0 and a smooth transition, both in value and in derivative, at x=L, we can append a rotated copy of f(x) in the [L, 2L] interval and make this function even. Figure 9 shows an example:

The Fourier integration for the even quarter-range expansion of f(x) yields equations (14) to (16):

Figure 10 shows the Fourier series reconstruction of f(x):

Although it is not visible from the figure, the derivative of the Fourier series reconstruction is 0 at x=0 and identical to the original signal at x=L.

## Odd quarter-range expansion

The last case weâll consider is when we want a value of 0 at x=0 and a derivative of 0 at x=L. We build g(x) by appending a flipped version of f(x) in the [L, 2L] range and make this function odd.

The Fourier integration for the odd quarter-range expansion of f(x) yields equations (17) to (19):

Figure 12 shows the Fourier series reconstruction of f(x):

We can see that the reconstruction goes through 0 at x=0. The derivative is zero at x=L, even if the original signal derivative is not.

## Conclusion

We considered the problem of finding a suitable Fourier series expansion for a signal f(x) defined over the finite interval [0, L]. Fourier series apply to periodic functions, so we had to build a periodic function that matches f(x) over the defined domain. We observed four methods to define the periodic function g(x). Each guarantees specific properties at the range boundaries:

- Even half-range expansion: The Fourier series has a derivative of 0 at x=0 and x=L
- Odd half-range expansion: The Fourier series has a value of 0 at x=0 and x=L
- Even quarter-range expansion: The Fourier series has a derivative of 0 at x=0 and smooth value and derivative at x=L
- Odd quarter-range expansion: The Fourier series has a value of 0 at x=0 and a derivative of 0 at x=L

In a future story, we will examine how heat is transferred in a thin metal bar. The solution involves converting the initial temperature profile to a Fourier series. Weâll observe that the choice for the type of Fourier series expansion is naturally dictated by the boundary conditions (e.g., the bar is isolated at x=0 and held to a fixed temperature at x=L). The seemingly arbitrary periodic functions we created in this post will suddenly make sense!