The trigonometric Fourier series is a beautiful mathematical theory that shows how to decompose a periodic function into an infinite sum of sinusoids. These are my notes on the subject, with some examples and the connection to linear algebra in Hilbert space.
Coefficients of Fourier series
Let’s assume that
is a well-behaved -periodic [1]
function and that we can find coefficients and
such that:
Then we say that the Fourier series on the right-hand side converges
to
. We’ll talk more about the assumptions mentioned above
and convergence in the next section.
Note that when , the sum becomes just
; therefore
it’s customary to write the series starting with , with a
separate constant component (which is the function's average over
one period). To make computations nicer, this constant is typically
called , so:
Our goal is to find the coefficients and that satisfy this equation. We’ll do this in three steps.
Step 1: Integrate both sides of the equation between and [2].
Per Appendix A, all integrals within the sum are zero, so we’re left with:
And thus we find
:
Step 2: Multiply both sides by ( is a positive integer constant) and integrate between and .
Looking at the right-hand side, the first integral is zero per Appendix A, and the last integral is zero per Appendix B. We’re left with:
Per Appendix B, the integral on the right is zero for all , and for . Therefore, we can write:
Recall that is an arbitrary integer, just like
; for
consistency, we’ll replace by
and isolate
:
Step 3: Hopefully it’s clear where this is going now; multiply both sides by and integrate between and . Using a very similar reasoning to step 2, we’ll end up with:
We’ve just found a way to calculate all the coefficients of our Fourier
series for
:
Where:
Conditions on f and convergence of Fourier series
The previous section discusses Fourier series for a function
that is well-behaved - but what does that mean? The full
answer would lead us deep into analysis, which I’d like to avoid here.
So I’ll keep it brief.
We typically assume that
is square
integrable,
which is denoted as . Moreover, we assume that the function
is piecewise
smooth: each
segment of the function has continuous derivatives. A very simple
example of a piecewise smooth function is . Another is
the triangular wave function used in the example below.
These conditions hold for pretty much any reasonable function we want to approximate using Fourier series, so they aren’t a serious burden.
For a function
that satisfies these conditions, it’s
guaranteed to have a Fourier series that pointwise converges to it.
This means that at every continuous point of
, the Fourier
series converges to it exactly; at every jump point, the Fourier series
converges to the mid-point of the jump.
Cosine and Sine series
Sometimes, additional properties of the function
can help
us simplify the Fourier series for it. If is an even
function,
then we know that:
Because the function inside the integral is odd, and integrating an odd function over a symmetric interval results in 0.
Therefore, the Fourier series for such is a cosine series:
With coefficients
and given as before.
Similarly if is an odd function, then its
and are 0, and its Fourier series is a sine series:
Fourier series for a non-periodic function defined on an interval
So far we’ve been talking about -periodic functions that can be faithfully represented by Fourier series. But what if we have a non-periodic function defined on a finite interval?
E.g. suppose we have on the interval . Can we approximate it with a Fourier series?
Yes! First, we have to make a choice of how to extend the function to the negative interval . Then, we simply repeat the function every - this is called a periodic extension. Note that the Fourier series calculation only cares about the range . The resulting series will approximate the generated periodic function in its entirety, and in particular will also converge to it in the interval (except maybe the endpoints, depending on the mode of extension).
There are several natural ways to extend a function defined on into the interval [3]:
- Direct periodic repetition: we simply repeat
every
: . - Even extension:
- Odd extension:
when and
when .
Here’s an example of extending our sample function onto the full interval and then repeating it periodically every :
Note that the Fourier series for these extended functions will be
different. However, they will all converge to
in the
interval . Typically, even and odd extensions have the
benefit of producing either cosine or sine series, correspondingly (as
discussed in the previous section).
We’ve seen that Fourier series work well for periodic functions and also non-periodic functions defined on a finite domain (because we can extend these periodically). But what about aperiodic functions defined on the entire real line? This is where we’ll have to leave Fourier series behind and move on to their generalization - the Fourier transform; this will be a topic for a separate post.
Example
Let’s take the following triangular function [4]:
is periodic with period 4. We can define it by starting with a formula on the interval :
Then making an odd extension into and repeating it periodically. Now we can go ahead to calculate its Fourier coefficients.
Since this function is odd, we know that we’ll get a sine series, as
are going to be 0 for all
. Let’s calculate
; in our case (half the period).
Since is odd and so is the sine, we’re integrating an even function over a symmetric interval. Therefore, we only have to integrate on the positive half of the range and multiply the result by two:
Let’s set :
And split up the integral for the different segments of :
The first integral, by the method described in Appendix C:
The second integral can also be split into two:
The first of these is trivial to calculate; the second can once again use Appendix C. After some tedious but straightforward calculations [5] we’ll get:
Adding , we get:
Now let’s substitute back. This makes zero because the sine of an integer multiple of is always zero:
We have , so the Fourier series for our is:
Note that for even values of
, is
zero, so only the odd terms remain:
Here’s an interactive chart showing how the series
converges to our triangular function. You can set the number of terms in
the Fourier series and see the effect (red line). Note that all even
coefficients are zero so it will look the same for
as for
when
is odd.
Compact formula using a single phase-shifted sinusoid
We’ve written the Fourier series for
as follows so far:
We can rewrite this in a somewhat more compact form, using a single
sinusoid with a configurable phase at each
:
Based on Appendix D, and can be computed as follows:
When Fourier series are used in the context of signal processing, this
formulation is easier to reason about because it represents the
magnitude and phase shift of each harmonic of
in the
frequency domain [6]
Complex Fourier series
It should not come as a surprise that the Fourier series, being a combination of trigonometric functions, can also be represented with complex exponential functions.
Specifically, we’ll show that our
can be approximated as
follows:
Let’s calculate . We proceed in a manner similar to before, by multiplying both sides of the equation by and taking an integral in the range :
By Appendix A, the sum elements are all zero when . When , we get:
Therefore, renaming to
(since it’s just an arbitrary
integer constant):
We’ve found an alternative formulation to Fourier series, using complex exponentials instead of trigonometric functions. While this was a direct derivation, another way to achieve the same result is to use the Euler Formula to derive:
And substitute these into the original Fourier series formula. I’ll leave this as an exercise for the diligent reader; eventually, the result will be the same. Moreover, it’s possible to show a direct correspondence between , and , for :
Note that when both and are
real (which is the case for a real-valued
). This helps
explain why the complex formulation has negative frequencies in the sum;
when the function is actually real, each negative frequency is paired up
with a positive frequency and the result is real [7]:
So, for a real function we only need to account for positive frequencies:
We can take it further. is a complex number, so let’s represent it in polar form as (the factor of half will make sense soon). Then:
And substituting back into the sum:
This is precisely the compact formulation from the previous section!
Fourier orthogonal basis in Hilbert space
The most beautiful aspect of Fourier theory is that it doesn’t just happen to work by chance, and is deeply connected to linear algebra. Please read my post on Hilbert space before proceeding.
The space of real-valued square integrable functions forms a Hilbert space, in which we can define the inner product (assuming real functions):
We’ve demonstrated that the family of functions:
Are all mutually orthogonal, because their pairwise inner products are zero! We’ve also shown that any function in can be represented as a weighted sum of these functions:
So these functions form a basis for . When we think of
these functions as vectors (in an infinite Hilbert space), much of what
we did in this post starts feeling like "normal" linear algebra. For
example, when we have a set of basis vectors and we want to know how to
represent some vector
in this basis, we usually find the
coefficients by projecting
it
onto the basis. E.g. with a basis vector , the coefficient of
:
Similarly, when we calculate the coefficient for some
function
, we project
onto the basis vector
by calculating:
From Appendix B, we know that the denominator is , and we’ve just denoted:
So we get:
Which should look familiar!
This is the core linear-algebra idea behind Fourier series: the
functions , , and
play the role of orthogonal basis vectors,
while the Fourier coefficients are coordinates of
in this
basis. The integral formulas for and are not
mysterious tricks; they are projections, just like dot products with
basis vectors in ordinary Euclidean space.
Fourier series therefore let us decompose a function into independent
orthogonal directions, much like decomposing a vector into its
,
, and components.
Appendix A: Integrals of sinusoids
For any integer and an arbitrary constant L, we have:
Similarly:
Using these, we can calculate the integral of a complex exponential function for an integer :
Appendix B: Integrals of products of sinusoids
We’ll start with the product of two sines, for any positive integers
and
:
Using the trigonometric identity for a product of sines, we can write:
Now let’s focus on two different scenarios, and .
If , then each of the integrals constituting ss are 0 (see on Appendix A), so .
If , then the second integral is still 0, but the first one isn’t:
Therefore:
We can use exactly the same approach to show that:
One more variant to cover:
Since sine is an odd function and cosine is an even function, their product is an odd function. And the integral of an odd function over a symmetric interval is 0 (see this post for more details).
Therefore:
Appendix C: A useful integral
Let’s calculate the indefinite integral:
For some constant . We’ll use integration by parts:
Here , so . Also , so .
Putting it together:
Appendix D: Sinusoid with phase as a sum of sin and cos
Let’s take a general sinusoid with magnitude , frequency
and phase
:
We’re going to show that can be represented as a sum of a sine and a cosine with no phase. This is related to my earlier post on the sum of same-frequency sinusoids.
Let’s start by expanding using a trigonometric identity:
Now we’ll denote: and , so:
We have and in terms of and
, but what about the other way around?
Let’s take the equations:
Square both of them and add together:
Now we’ll take the equations for and and divide one by the other:
Where the atan2 function is
careful to take into account the sign of both numerator and denominator.
Also it’s worth mentioning that
is determined up to
additions of .
To conclude, for any ,
and
:
With the aforementioned conversion formulas for , .
| [1] | A function is called periodic if there exists some
constant such that . In our
case, we denote the period as to make presentation and
calculations neater. |
| [2] | Since , we know that it’s integrable on a finite interval |
| [3] | There’s also an infinite number of less natural ways to extend the function; they will still work, but may make the calculation needlessly complicated |
| [4] | I chose this one because the more common ones like a square wave and a sawtooth wave have many derivations available online, including on Wikipedia. |
| [5] | Try it for yourself - it’s a good exercise. |
| [6] | When for some , the corresponding
can be chosen arbitrarily. |
| [7] | For a complex-valued , this conjugate symmetry no longer
holds in general. and may be complex, so
and need not be conjugates. |