Consider the well-known rectangle function.
f(x) = \left\{\begin{array}{cc}<br />
-k & -\pi < x < 0 \\<br />
k & 0 < x < \pi<br />
\end{array}\right.
The first question to ask yourself is: what is the period of this function?
What is the length of this function before it repeats itself? Quite simply, the period is 2\pi. Draw it on some paper, and notice that it repeats the same pattern every 2\pi. So since this function has the fundamental period, we use the corresponding Euler formulae and Fourier Series.
The second question to ask yourself is: is this function even or odd?
Luckily, this is one of those functions which you can picture in your head, or write down on a piece of paper. It is odd, since it is NOT symmetric about 0.
When a function is odd, the first Fourier coefficient is always 0, no matter how much don't want it to be. To see this, we compute
a_n = \frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\cos(nx)dx
= \frac{1}{\pi}\left[\int_{-\pi}^{0}(-k)\cos(nx)dx + \int_{0}^{\pi}k\cos(nx)dx\right]
Notice how I have split the integral into two integrals. The rest of the computation is simple calculus, and
a_n = 0
Why does an odd function always have a_n = 0? Remember, that the Fourier Series of a function is just an approximation of that function as a sum of sines and cosines. The sine function is by definition odd, and the cosine function is by definition even.
The Forier coefficient that accompany the sine and cosine term in the Fourier Sum are like weighted parameters. The larger the a_n the more the function will be "like" a cosine and hence even. The larger the b_n the more the function will be "like" a sine and hence odd.
So the Fourier coefficients a_n and b_n influence how the Fourier Sum will act.
In our example, the rectangle function is odd. So we are going to expect that the Fourier Series will be a sine wave. In fact we will see that the more sine terms we allow into our Fourier Series, the more and more the Fourier Series will look like our function. This will become clear in a minute...
So it is of no surprise that a_n = 0 because it is a_n that accompanies the cosine term.
This leaves us to calculate a_0. This coefficient is special in that it always defined as the average value of the function. This coefficient tells us where the function is located.
So for our rectangle function, what do you think its average value is? Zero of course. So we guess that a_0 = 0. Let's see if we are right?
a_0 = \frac{1}{2\pi}\left[\int_{-\pi}^0-kdx + \int_0^{\pi}kdx\right]
a_0 = \frac{1}{2\pi}\left[\left.-kx\right|_{-\pi}^0 + \left.kx\right|_0^{\pi}\right]
a_0 = \frac{1}{2\pi}\left(k\pi -k\pi\right)
a_0 = 0
Of course the same technique applies to all functions.
Now
b_n = \frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\sin(nx)dx
b_n = \frac{1}{\pi}\left[\int_{-\pi}^{0}(-k)\sin(nx)dx + \int_{0}^{\pi}k\sin(nx)dx\right]
b_n = \frac{1}{\pi}\left[\left.k\frac{\cos(nx)}{n}\right|_{-\pi}^0 - \left.k\frac{\cos(nx)}{n}\right|_0^{\pi}\right]
b_n = \frac{k}{n\pi}\left[\cos0 - \cos(-n\pi) - \cos(n\pi) + \cos0\right]
b_n = \frac{2k}{n\pi}(1-\cos(n\pi))
Now, something which you must always do when you get to this stage in your calculations, something that a lot of people forget. Simply note that the sum of Fourier Series take on values of n \in \mathbb{N}. That is
n = 1,2,\dots
And we must note that
\cos(n\pi) = (-1)^n \, \forall \, n \in \mathbb{N}
This is just a fancy way of writing...
\cos(n\pi) = \left\{\begin{array}{cc}<br />
1 & \mbox{for even}\, n \\<br />
-1 & \mbox{for odd}\, n<br />
\end{array}<br />
\right.
and thus
1-\cos(n\pi) = \left\{\begin{array}{cc}<br />
2 & \mbox{for odd}\, n \\<br />
0 & \mbox{for even}\, n<br />
\end{array}<br />
\right.
Now we can explicitly calculate our b_n coeffcients
b_1 = \frac{4k}{\pi}
b_2 = 0
b_3 = \frac{4k}{3\pi}
b_4 = 0
Obviously for every even n, b_n = 0.
Hence the Fourier Series is
f(x) = \frac{2k}{\pi}\sum_{n=1}^{\infty}b_n\sin(nx)
f(x) = \frac{2k}{\pi}\left(\sin(x) + \frac{1}{3}\sin(3x) + \frac{1}{5}\sin(5x) + \dots \right)