# Signals and Systems/Fourier Series
## The Fourier Series

The Fourier Series is a specialized tool that allows for any periodic signal (subject to certain conditions) to be decomposed into an infinite sum of everlasting sinusoids. This may not be obvious to many people, but it is demonstrable both mathematically and graphically. Practically, this allows the user of the Fourier Series to understand a periodic signal as the sum of various frequency components. (Or) The representation of a signal over a certain interval of time in terms of linear combination of orthogonal function is called Fourier series.

## Rectangular Series

The rectangular series represents a signal as a sum of sine and cosine terms. The type of sinusoids that a periodic signal can be decomposed into depends solely on the qualities of the periodic signal.

### Calculations

If we have a function f(x), that is periodic with a period of 2L, we can decompose it into a sum of sine and cosine functions as such:
    $f(x)={\frac {1}{2}}a_{0}+\sum _{n=1}^{\infty }\left[a_{n}\cos \left({\frac {n\pi x}{L}}\right)+b_{n}\sin \left({\frac {n\pi x}{L}}\right)\right]$
The coefficients, a and b can be found using the following integrals:
    $a_{n}={\frac {1}{L}}\int _{-L}^{L}f(x)\cos \left({\frac {n\pi x}{L}}\right)\,dx$
    $b_{n}={\frac {1}{L}}\int _{-L}^{L}f(x)\sin \left({\frac {n\pi x}{L}}\right)\,dx$
"n" is an integer variable. It can assume positive integer numbers (1, 2, 3, etc...). Each value of n corresponds to values for A and B. The sinusoids with magnitudes A and B are called harmonics. Using Fourier representation, a harmonic is an atomic (indivisible) component of the signal, and is said to be orthogonal.
When we set n = 1, the resulting sinusoidal frequency value from the above equations is known as the fundamental frequency. The fundamental frequency of a given signal is the most powerful sinusoidal component of a signal, and is the most important to transmit faithfully. Since n takes on integer values, all other frequency components of the signal are integer multiples of the fundamental frequency.
If we consider a signal in time, the period, T$_0$ is analogous to 2L in the above definition. The fundamental frequency is then given by:
       $f_{0}={\frac {1}{T_{0}}}$
And the fundamental angular frequency is then:
       $\omega _{0}={\frac {2\pi }{T_{0}}}$
Thus we can replace every $\left({\frac {n\pi x}{L}}\right)$ term with a more concise $(n\omega _{0}x)$.

### Signal Properties

Various signal properties translate into specific properties of the Fourier series. If we can identify these properties before hand, we can save ourselves from doing unnecessary calculations.

#### DC Offset

If the periodic signal has a DC offset, then the Fourier Series of the signal will include a zero frequency component, known as the DC component. If the signal does not have a DC offset, the DC component has a magnitude of 0. Due to the linearity of the Fourier series process, if the DC offset is removed, we can analyse the signal further (e.g. for symmetry) and add the DC offset back at the end.

#### Odd and Even Signals

If the signal is even (symmetric over the reference vertical axis), it is composed of cosine waves. If the signal is odd (anti-symmetric over the reference vertical axis), it is composed out of sine waves. If the signal is neither even nor odd, it is composed out of both sine and cosine waves.

#### Discontinuous Signal

If the signal is discontinuous (i.e. it has "jumps"), the magnitudes of each harmonic n will fall off proportionally to 1/n.

#### Discontinuous Derivative

If the signal is continuous but the derivative of the signal is discontinuous, the magnitudes of each harmonic n will fall off proportionally to 1/n$^2$.

#### Half-Wave Symmetry

If a signal has half-wave symmetry, there is no DC offset, and the signal is composed of sinusoids lying on only the odd harmonics (1, 3, 5, etc...). This is important because a signal with half-wave symmetry will require twice as much bandwidth to transmit the same number of harmonics as a signal without:
$a_{0}=0\,$ $a_{n}={\begin{cases}0,&{\mbox{if }}n{\mbox{ is even}}\\{\frac {2}{L}}\int _{0}^{L}f(x)\cos(n\omega _{0}x)dx,&{\mbox{if }}n{\mbox{ is odd}}\end{cases}}$
$b_{n}={\begin{cases}0,&{\mbox{if }}n{\mbox{ is even}}\\{\frac {2}{L}}\int _{0}^{L}f(x)\sin(n\omega _{0}x)dx,&{\mbox{if }}n{\mbox{ is odd}}\end{cases}}$

#### Quarter-Wave Symmetry of an Even Signal

If a 2L-periodic signal has quarter-wave symmetry, then it must also be half-wave symmetric, so there are no even harmonics. If the signal is even and has quarter-wave symmetry, we only need to integrate the first quarter-period:
       $a_{n}={\begin{cases}0,&{\mbox{if }}n{\mbox{ is even}}\\{\frac {4}{L}}\int _{0}^{L/2}f(x)\cos(n\omega _{0}x)dx,&{\mbox{if }}n{\mbox{ is odd}}\end{cases}}$
We also know that because the signal is half-wave symmetric, there is no DC offset:
       $a_{0}=0\,$
Because the signal is even, there are are no sine terms:
       $b_{n}=0\,$

#### Quarter-Wave Symmetry of an Odd Signal

If the signal is odd, and has quarter wave symmetry, then we can say:
Because the signal is odd, there are no cosine terms:
       $a_{0}=0\,$
       $a_{n}=0\,$
There are no even sine terms due to half-wave symmetry, and we only need to integrate the first quarter-period due to quarter-wave symmetry.
       $b_{n}={\begin{cases}0,&{\mbox{if }}n{\mbox{ is even}}\\{\frac {4}{L}}\int _{0}^{L/2}f(x)\sin(n\omega _{0}x)dx,&{\mbox{if }}n{\mbox{ is odd}}\end{cases}}$

### Summary

By convention, the coefficients of the cosine components are labeled "a", and the coefficients of the sine components are labeled with a "b". A few important facts can then be mentioned:
* If the function has a DC offset, a$_0$ will be non-zero. There is no B$_0$ term.
* If the signal is even, all the b terms are 0 (no sine components).
* If the signal is odd, all the a terms are 0 (no cosine components).
* If the function has half-wave symmetry, then all the even coefficients (of sine and cosine terms) are zero, and we only have to integrate half the signal.
* If the function has quarter-wave symmetry, we only need to integrate a quarter of the signal.
* The Fourier series of a sine or cosine wave contains a single harmonic because a sine or cosine wave cannot be decomposed into other sine or cosine waves.
* We can check a series by looking for discontinuities in the signal or derivative of the signal. If there are discontinuities, the harmonics drop off as 1/n, if the derivative is discontinuous, the harmonics drop off as 1/n$^2$.

## Polar Series

The Fourier Series can also be represented in a polar form which is more compact and easier to manipulate.
If we have the coefficients of the rectangular Fourier Series, a and b we can define a coefficient x, and a phase angle φ that can be calculated in the following manner:
    $x_{0}=a_{0}\,$
    $x_{n}={\sqrt {a_{n}^{2}+b_{n}^{2}}}$
    $\phi _{n}=\tan ^{-1}\left({\frac {b_{n}}{a_{n}}}\right)$
We can then define f(x) in terms of our new Fourier representation, by using a cosine basis function:
    $f(x)=x_{0}+\sum _{n=1}^{\infty }x_{n}\cos(n\omega x-\phi _{n})$
The use of a cosine basis instead of a sine basis is an arbitrary distinction, but is important nonetheless. If we wanted to use a sine basis instead of a cosine basis, we would have to modify our equation for φ, above.

### Proof of Equivalence

We can show explicitly that the polar cosine basis function is equivalent to the "Cartesian" form with a sine and cosine term.
    $f(x)=x_{0}+\sum _{n=1}^{\infty }x_{n}\cos(n\omega x-\phi _{n})$
By the double-angle formula for cosines:
    $f(x)=x_{0}+\sum _{n=1}^{\infty }x_{n}\left[\cos(n\omega x)\cos(-\phi _{n})-\sin(n\omega x)\sin(-\phi _{n})\right]$
By the odd-even properties of cosines and sines:
    $f(x)=x_{0}+\sum _{n=1}^{\infty }x_{n}\left[\cos(n\omega x)\cos(\phi _{n})+\sin(n\omega x)\sin(\phi _{n})\right]$
Grouping the coefficents:
    $f(x)=x_{0}+\sum _{n=1}^{\infty }[x_{n}\cos(\phi _{n})\cos(n\omega x)+x_{n}\sin(\phi _{n})\sin(n\omega x)]$
This is equivalent to the rectangular series given that:
    $a_{n}=x_{n}\cos(\phi _{n})\,$
    $b_{n}=x_{n}\sin(\phi _{n})\,$
Dividing, we get:
    ${\frac {b_{n}}{a_{n}}}={\frac {x_{n}\sin(\phi _{n})}{x_{n}\cos(\phi _{n})}}=\tan(\phi _{n})$
    $\phi _{n}=\tan ^{-1}\left({\frac {b_{n}}{a_{n}}}\right)$
Squaring and adding, we get:
    $a_{n}^{2}+b_{n}^{2}=x_{n}^{2}\left[\cos ^{2}(\phi _{n})+sin^{2}(\phi _{n})\right]$
    $a_{n}^{2}+b_{n}^{2}=x_{n}^{2}\,$
    $x_{n}={\sqrt {a_{n}^{2}+b_{n}^{2}}}$
Hence, given the above definitions of x$_n$ and φ$_n$, the two are equivalent. For a sine basis function, just use the sine double-angle formula. The rest of the process is very similar.

## Exponential Series

Using Eulers Equation, and a little trickery, we can convert the standard Rectangular Fourier Series into an exponential form. Even though complex numbers are a little more complicated to comprehend, we use this form for a number of reasons:
* Only need to perform one integration
* A single exponential can be manipulated more easily than a sum of sinusoids
* It provides a logical transition into a further discussion of the Fourier Transform.
We can construct the exponential series from the rectangular series using Euler's formulae:
    $\sin(x)={\frac {-i}{2}}\left(e^{ix}-e^{-ix}\right);\quad \quad \cos(x)={\frac {1}{2}}\left(e^{ix}+e^{-ix}\right)$
The rectangular series is given by:
    $f(x)=a_{0}+\sum _{n=1}^{\infty }\left[a_{n}\cos(n\omega x)+b_{n}\sin(n\omega x)\right]$
Substituting Euler's formulae:
    $f(x)=a_{0}+\sum _{n=1}^{\infty }\left[{\frac {a_{n}}{2}}e^{in\omega x}+{\frac {a_{n}}{2}}e^{-in\omega x}-{\frac {ib_{n}}{2}}e^{in\omega x}+{\frac {ib_{n}}{2}}e^{-in\omega x}\right]$
Splitting into "positive n" and "negative n" parts gives us:
    $f(x)=a_{0}+\sum _{n=1}^{\infty }\left[{\frac {a_{n}}{2}}e^{in\omega x}-{\frac {ib_{n}}{2}}e^{in\omega x}\right]+\sum _{n=-\infty }^{-1}\left[{\frac {a_{-n}}{2}}e^{in\omega x}+{\frac {ib_{-n}}{2}}e^{in\omega x}\right]$
    $f(x)=a_{0}+\sum _{n=1}^{\infty }{\frac {1}{2}}(a_{n}-ib_{n})e^{in\omega x}+\sum _{n=-\infty }^{-1}{\frac {1}{2}}(a_{-n}+ib_{-n})e^{in\omega x}$
We now collapse this into a single expression:
[Exponential Fourier Series]
    $f(x)=\sum _{n=-\infty }^{\infty }c_{n}e^{in\omega x}$
Where we can relate c$_n$ to a$_n$ and b$_n$ from the rectangular series:
    $c_{n}={\begin{cases}{\frac {1}{2}}(a_{-n}+ib_{-n}),&n<0\\a_{0},&n=0\\{\frac {1}{2}}(a_{n}-ib_{n}),&n>0\end{cases}}$
This is the exponential Fourier series of f(x). Note that c$_n$ is, in general, complex. Also note that:
   * $\Re (c_{n})=\Re (c_{-n})$
   * $\Im (c_{n})=-\Im (c_{-n})$
We can directly calculate c$_n$ for a 2L-periodic function:
    $c_{n}={\frac {1}{2L}}\int _{-L}^{L}f(x)e^{-in\pi x/L}dx$
This can be related to the a$_n$ and b$_n$ definitions in the rectangular form using Euler's formula: $e^{ix}=\cos {x}+i\sin {x}$.

## Negative Frequency

The Exponential form of the Fourier series does something that is very interesting in comparison to the rectangular and polar forms of the series: it allows for negative frequency components. To this effect, the Exponential series is often known as the "Bi-Sided Fourier Series", because the spectrum has both a positive and negative side. This, of course, prods the question, "What is a negative Frequency?"
Negative frequencies seem counter-intuitive, and many people would be quick to dismiss them as being nonsense. However, a further study of electrical engineering (which is outside the scope of this book) will provide many examples of where negative frequencies play a very important part in modeling and understanding certain systems. While it may not make much sense initially, negative frequencies need to be taken into account when studying the Fourier Domain.
Negative frequencies follow the important rule of symmetry: For real signals, negative frequency components are always mirror-images of the positive frequency components. Once this rule is learned, drawing the negative side of the spectrum is a trivial matter once the positive side has been drawn.
However, when looking at a bi-sided spectrum, the effect of negative frequencies needs to be taken into account. If the negative frequencies are mirror-images of the positive frequencies, and if a negative frequency is analogous to a positive frequency, then the effect of adding the negative components into a signal is the same as doubling the positive components. This is a major reason why the exponential Fourier series coefficients are multiplied by one-half in the calculation: because half the coefficient is at the negative frequency.
Note: The concept of negative frequency is actually unphysical. Negative frequencies occur in the spectrum only when we are using the exponential form of the Fourier series. To represent a cosine function, Euler's relationship tells us that there are both positive and negative exponential required. Why? Because to represent a real function, like cosine, the imaginary components present in exponential notation must vanish. Thus, the negative exponent in Euler's formula makes it appear that there are negative frequencies, when in fact, there are not.

### Example: Ceiling Fan

Another way to understand negative frequencies is to use them for mathematical completeness in describing the physical world. Suppose we want to describe the rotation of a ceiling fan directly above our head to a person sitting nearby. We would say "it rotates at 60 RPM in an anticlockwise direction". However, if we want to describe its rotation to a person watching the fan from above then we would say "it rotates at 60 RPM in a clockwise direction". If we customarily use a negative sign for clockwise rotation, then we would use a positive sign for anticlockwise rotation. We are describing the same process using both positive and negative signs, depending on the reference we choose.

## Bandwidth

Bandwidth is the name for the frequency range that a signal requires for transmission, and is also a name for the frequency capacity of a particular transmission medium. For example, if a given signal has a bandwidth of 10kHz, it requires a transmission medium with a bandwidth of at least 10kHz to transmit without attenuation.
Bandwidth can be measured in either Hertz or Radians per Second. Bandwidth is only a measurement of the positive frequency components. All real signals have negative frequency components, but since they are only mirror images of the positive frequency components, they are not included in bandwidth calculations.

### Bandwidth Concerns

It's important to note that most periodic signals are composed of an infinite sum of sinusoids, and therefore require an infinite bandwidth to be transmitted without distortion. Unfortunately, no available communication medium (wire, fiber optic, wireless) have an infinite bandwidth available. This means that certain harmonics will pass through the medium, while other harmonics of the signal will be attenuated.
Engineering is all about trade-offs. The question here is "How many harmonics do I need to transmit, and how many can I safely get rid of?" Using fewer harmonics leads to reduced bandwidth requirements, but also results in increased signal distortion. These subjects will all be considered in more detail in the future.

### Pulse Width

Using our relationship between period and frequency, we can see an important fact:
    $f_{0}={\frac {1}{T}}$
As the period of the signal decreases, the fundamental frequency increases. This means that each additional harmonic will be spaced further apart, and transmitting the same number of harmonics will now require more bandwidth! In general, there is a rule that must be followed when considering periodic signals: Shorter periods in the time domain require more bandwidth in the frequency domain. Signals that use less bandwidth in the frequency domain will require longer periods in the time domain.

## Examples
### Example: x$^3$

Let's consider a repeating pattern based on a cubic polynomial:
    $f\left(x\right)=x^{3},\quad -\pi \leq x<\pi \,$
and f(x) is 2π periodic:
By inspection, we can determine some characteristics of the Fourier Series:
* The function is odd, so the cosine coefficients (a$_n$) will all be zero.
* The function has no DC offset, so there will be no constant term (a$_0$).
* There are discontinuities, so we expect a 1/n drop-off.
We therefore just have to compute the b$_n$ terms. These can be found by the following formula:
    $b_{n}={1 \over \pi }\int \limits _{-\pi }^{\pi }{f\left(x\right)\sin \left({nx}\right)dx}$
Substituting in the desired function gives
    $b_{n}={1 \over \pi }\int \limits _{-\pi }^{\pi }{x^{3}\sin \left({nx}\right)dx}$
Integrating by parts,
    $b_{n}={1 \over \pi }\left({\left[{-x^{3}{{\cos \left({nx}\right)} \over n}}\right]_{-\pi }^{\pi }+\int \limits _{-\pi }^{\pi }{3x^{2}{{\cos \left({nx}\right)} \over n}dx}}\right)$
Bring out factors:
    $b_{n}={1 \over {n\pi }}\left({\left[{-x^{3}\cos \left({nx}\right)}\right]_{-\pi }^{\pi }+3\int \limits _{-\pi }^{\pi }{x^{2}\cos \left({nx}\right)dx}}\right)$
Substitute limits into the square brackets and integrate by parts again:
    $b_{n}={1 \over {n\pi }}\left({-\left({\pi ^{3}\cos \left({n\pi }\right)+\pi ^{3}\cos \left({-n\pi }\right)}\right)+3\left({\left[{x^{2}{{\sin \left({nx}\right)} \over n}}\right]_{-\pi }^{\pi }-\int \limits _{-\pi }^{\pi }{2x{{\sin \left({nx}\right)} \over n}dx}}\right)}\right)$
Recall that cos(x) is an even function, so cos(-nπ) = cos(nπ). Also bring out the factor of 1/n from the integral:
    $b_{n}={1 \over {n\pi }}\left({-\left({\pi ^{3}\cos \left({n\pi }\right)+\pi ^{3}\cos \left({n\pi }\right)}\right)+{3 \over n}\left({\left[{x^{2}\sin \left({nx}\right)}\right]_{-\pi }^{\pi }-2\int \limits _{-\pi }^{\pi }{x\sin \left({nx}\right)dx}}\right)}\right)$
Simplifying the left part, and substituting in limits in the square brackets,
    $b_{n}={1 \over {n\pi }}\left({-2\pi ^{3}\cos \left({n\pi }\right)+{3 \over n}\left({\left({\pi ^{2}\sin \left({n\pi }\right)-\pi \sin \left({-n\pi }\right)}\right)-2\int \limits _{-\pi }^{\pi }{x\sin \left({nx}\right)dx}}\right)}\right)$
Recall that sin(nπ) is always equal to zero for integer n:
    $b_{n}={1 \over {n\pi }}\left({-2\pi ^{3}\cos \left({n\pi }\right)+{3 \over n}\left({0-2\int \limits _{-\pi }^{\pi }{x\sin \left({nx}\right)dx}}\right)}\right)$
Bringing out factors and integrating by parts:
    $b_{n}={1 \over {n\pi }}\left({-2\pi ^{3}\cos \left({n\pi }\right)-{6 \over n}\left[{-\left[{x{{\cos \left({nx}\right)} \over n}}\right]_{-\pi }^{\pi }+\int \limits _{-\pi }^{\pi }{{{\cos \left({nx}\right)} \over n}dx}}\right]}\right)$
    $b_{n}={1 \over {n\pi }}\left({-2\pi ^{3}\cos \left({n\pi }\right)-{6 \over {n^{2}}}\left[-{\left[{x\cos \left({nx}\right)}\right]_{-\pi }^{\pi }+\int \limits _{-\pi }^{\pi }{\cos \left({nx}\right)dx}}\right]}\right)$
Solving the now-simple integral and substituting in limits to the square brackets,
    $b_{n}={1 \over {n\pi }}\left({-2\pi ^{3}\cos \left({n\pi }\right)-{6 \over {n^{2}}}\left[{-\left({\pi \cos \left({n\pi }\right)+\pi \cos \left({-n\pi }\right)}\right)+\left[{\sin \left({nx}\right)}\right]_{-\pi }^{\pi }}\right]}\right)$
Since the area under one cycle of a sine wave is zero, we can eliminate the integral. We use the fact that cos(x) is even again to simplify:
    $b_{n}={1 \over {n\pi }}\left({-2\pi ^{3}\cos \left({n\pi }\right)-{6 \over {n^{2}}}\left[{-2\pi \cos \left({n\pi }\right)+0}\right]}\right)$
Simplifying:
    $b_{n}={1 \over {n\pi }}\left({-2\pi ^{3}\cos \left({n\pi }\right)+{{12\pi } \over {n^{2}}}\cos \left({n\pi }\right)}\right)$
    $b_{n}={{-2\pi ^{2}\cos \left({n\pi }\right)} \over n}+{{12\cos \left({n\pi }\right)} \over {n^{3}}}$
    $b_{n}=\cos \left({n\pi }\right)\left({{{-2\pi ^{2}n^{2}} \over {n^{3}}}+{{12} \over {n^{3}}}}\right)$
    $b_{n}={{-2\cos \left({n\pi }\right)} \over {n^{3}}}\left({\pi ^{2}n^{2}-6}\right)$
Now, use the fact that cos(nπ)=(-1)$^n$:
    $b_{n}={{-2\left({-1}\right)^{n}} \over {n^{3}}}\left({\pi ^{2}n^{2}-6}\right)$
This is our final b$_n$. We see that we have a approximate 1/n relationship (the constant "6" becomes insignificant as n grows), as we expected. Now, we can find the Fourier approximation according to
    $f\left(x\right)={1 \over 2}a_{0}+\sum \limits _{n=1}^{\infty }{\left[{a_{n}\cos \left({nx}\right)+b_{n}\sin \left({nx}\right)}\right]}$
Since all a terms are zero,
    $f\left(x\right)=\sum \limits _{n=1}^{\infty }{b_{n}\sin \left({nx}\right)}$
So, the Fourier Series approximation of f(x) = x$^3$ is:
    $f\left(x\right)=\sum \limits _{n=1}^{\infty }{\left[{{{-2\left({-1}\right)^{n}} \over {n^{3}}}\left({\pi ^{2}n^{2}-6}\right)\sin \left({nx}\right)}\right]}$
The graph below shows the approximation for the first 7 terms (red) and the first 15 terms (blue). The original function is shown in black.

### Example: Square Wave

We have the following square wave signal, as a function of voltage, traveling through a communication medium:
We will set the values as follows: A = 4 volts, T = 1 second. Also, it is given that the width of a single pulse is T/2.
Find the rectangular Fourier series of this signal.
First and foremost, we can see clearly that this signal does have a DC value: the signal exists entirely above the horizontal axis. DC value means that we will have to calculate our a$_0$ term. Next, we can see that if we remove the DC component (shift the signal downward till it is centered around the horizontal axis), that our signal is an odd signal. This means that we will have b$_n$ terms, but no a$_n$ terms. We can also see that this function has discontinuities and half-wave symmetry. Let's recap:
* DC value (must calculate a$_0$)
* Odd Function (a$_n$ = 0 for n > 0)
* Discontinuties (terms fall off as 1/n)
* Half-wave Symmetry (no even harmonics)
Now, we can calculate these values as follows:
    $a_{0}={\frac {1}{T}}\int _{0}^{T}f(t)dt$
    $a_{0}={\frac {1}{T}}\int _{0}^{T/2}4dt$
    $a_{0}={\frac {1}{T}}\left[4t\right]_{0}^{T/2}={\frac {4\times T}{T\times 2}}=2$
This could also have been worked out intuitively, as the signal has a 50% duty-cycle, meaning that the average value is half of the maximum.
Due to the oddness of the function, there are no cosine terms:
    $a_{n}=0\quad {\mbox{ for all }}n>0$.
Due to the half-wave symmetry, there are only odd sine terms, which are given by:
    $b_{n}={\frac {1}{T/2}}\int _{0}^{T}f(t)\sin \left({\frac {2n\pi t}{T}}\right)dt$
    $b_{n}={\frac {2}{T}}\int _{0}^{T/2}4\sin \left(2n\pi t\right)dt$
    $b_{n}=-2\left[{\frac {4}{2n\pi }}\cos \left(2n\pi t\right)\right]_{0}^{1/2}$
    $b_{n}=-2\left[{\frac {4}{2n\pi }}\cos \left({\frac {2n\pi }{2}}\right)-{\frac {4}{2n\pi }}\cos \left(2n\pi \times 0\right)\right]$
    $b_{n}=-{\frac {4}{n\pi }}\left[\cos \left(n\pi \right)-1\right]$
Given that cos(nπ)=(-1)$^n$:
    $b_{n}=-{\frac {4\left((-1)^{n}-1\right)}{n\pi }}$
For any even n, this equals zero, in accordance with our predictions based on half-wave symmetry. It also decays as 1/n, as we expect, due to the presence of discontinuities.
Finally, we can put our Fourier series together as follows:
    $f(t)=a_{0}+\sum _{n=1}^{\infty }{b_{n}\sin \left({\frac {\pi nt}{\frac {L}{2}}}\right)}$
    $f(t)=2-{\frac {4}{\pi }}\sum _{n=1}^{\infty }{{\frac {(-1)^{n}-1}{n}}\sin(2\pi nt)}$
This is the same as
    $f(t)=2+{\frac {8}{\pi }}\sum _{n=1,3,5,\ldots }^{\infty }{{\frac {1}{n}}\sin(2\pi nt)}$
We see that the Fourier series closely matches the original function:

## Further Reading

Wikipedia has an article on the Fourier Series, although the article is very mathematically rigorous.