Mathematics

**Approximating a square wave using the Fourier series**

*Cont’d from “Fourier series”*

Finally! The long-time-coming Fourier approximation of a square wave, as promised in this post.

Let’s start by considering a rectangular square pulse, which we’ll call the function *f*(*x*), and define such that

*i.e.* a square pulse of width *π* centred at the origin. We’ll let the periodicity be such that *f*(*x*) = *f*(*x* + 4*π*), meaning the function has a period of 4*π*. Graphically this will be a square
wave:

To analyse this using the Fourier series we consider only one square pulse:

First, we’ll evaluate the *a*_{0} coefficient, the average of the function. We can find this either by inspecting the graph or mathematically. generally, for a periodic function *f*(*x*) centred at the origin with period *P*, *a*_{0} is expressed as

In this case, *P* = 4*π*, and so

Now, we shall evaluate the *a _{n}* term. There’s a trick we can use here regarding a function’s odd or even properties:

If the function is even, the *a _{n}* term will contain the integral of an even term so it will contribute the Fourier series. However, the

*b*term will contain an integral of an odd function, which is zero. Therefore, in this case, we can ignore the

_{n}*b*term:

_{n}Conversely, if the function were odd, the *a _{n}* term would contain the integral of an odd function and the

*b*term would contain the integral of an even function. Hence, only the

_{n}*b*term would contribute and we could ignore the an term.

_{n}Now, since the function is symmetric in the *y*-axis it is even and we should analyse the an
coefficient.

Using piecewise analysis we can represent the function as the sum of the individual integrals of each respective parts of the function.

Since sin(−*x*) = − sin(*x*),

In turn, it can also be inferred that the integral of an odd function centred at the origin between symmetric limits ±ℓ is twice the integral of the same function between half of those limits. Generally, this is,

Now we can obtain a final value for *a _{n}*. We can express

*a*in terms of the sinc function, defined such that

_{n}therefore,

Thus, we can substitute these expressions into the Fourier series.

So what does this function look like? Let’s approximate the function by taking the summation to the
7^{th} term.

Clearly we can see that this is not a completely perfect approximation. As we take it to higher orders, we’d expect the function to look more like the original piece-wise function.