```javascript
%%javascript
MathJax.Hub.Config({TeX: { equationNumbers: { autoNumber: "AMS" } }});
```


    <IPython.core.display.Javascript object>


# Fourier Series
## Trigonometric Fourier Series
Any arbitrary periodic function can be expressed as an infinite sum of  weighted sinusoids, this is called a *Fourier series*. The Fourier series can be expressed in three different forms, *exponential*, *amplitude-phase* and *trigonometric*, we will only use the latter.  The trigonometric Fourier series of a periodic function $f(t)$ is given by 

\begin{equation} \label{eq:TrigFourier}
f(t) = a_0 + \sum_{n=1}^{\infty} \left[a_n \cos\left(2\pi n f_0 t \right) + b_n \sin\left(2\pi n f_0 t \right)\right] 
\end{equation}

The relationship between angular frequency, $\omega$ $[rad/s]$,  and the linear frequency, $f$ $[Hz]$ is shown by the following equation

\begin{equation}
\omega=2\pi f
\end{equation} 

Equation \eqref{eq:TrigFourier} can therefor  also be written as

$$
f(t) = a_0 + \sum_{n=1}^{\infty} \left[a_n \cos\left( n \omega_0 t \right) + b_n \sin\left(n \omega_0 t \right)\right] 
$$

The Fourier component $a_0$ is the dc component (the time average) of function $f(t)$. The Fourier components $a_n$ and $b_n$ are the amplitudes of the cosinusoids and sinusoids, respectively. 
The frequency $f_0$ is the **fundemental frequency** and the frequency of every trem is an integer multiple of $f_0$,  the resulting waves are called **harmonics**. So the first wave of the Fourier series, $n=1$, is the fundamental wave (1st harmonic), the next wave , $n=2$, is called the 2nd harmonic and has the frequency $2f_0$. The frequencies of the harmonics are strictly integer multiples of the fundamental frequency: $f_0,\,2f_0,\,3f_0,\, \ldots \,nf_0$. 

Sources: [Fourier Series](https://link.springer.com/chapter/10.1007%2F978-90-481-9443-8_16) and [Trigonometric Fourier Series](https://onlinelibrary.wiley.com/doi/pdf/10.1002/9781118844373.app4).

## Magnitude Spectrum

To draw the magnitude spectrum for a trigonometric Fourier series we need to consider both $a_n$ and $b_n$. To find the magnitudes to the harmonics of the two coefficients we take the root-sum-square (RSS), [source](https://link.springer.com/chapter/10.1007%2F978-3-642-28818-0_2).

\begin{equation}\label{eq:magnitude}
M_n=\sqrt{a_n^2 + b_n^2}
\end{equation}

The distinction between amplitude and magnitude can be somewhat confusing, and often these two terms are used interchangeably. Lets try to make the destination as clear as possible how these will be used when we talk about Fourier series. The Fourier components $a_n$ and $b_n$ are the amplitudes of the cosinusoids and sinusoids, respectively, they can have both positive and negative values. When we take the RSS of these two we get the magnitude, which is always positive. The amplitude and magnitude can have the same value in some [cases](https://www.mathworks.com/academia/books/the-intuitive-guide-to-fourier-analysis-and-spectral-estimation-with-matlab-langton.html).
The magnitude spectrum for the Fourier series can now be drawn, where the y-axis magnitude and the x-axis is frequency.

To make a small example we can take the Fourier series of a square wave with the fundamental frequency $f_0=1$ Hz

\begin{equation}
\text{Square}(t) =  \sin{2\pi t}+\dfrac{\sin{3 \cdot2\pi t}}{3}+\dfrac{\sin{5\cdot 2\pi t}}{5} + \ldots =  \sum_{n=1}^{\infty}\dfrac{\sin{(2n-1)2\pi t}}{2n - 1}
\end{equation}

This is an odd function, meaning that it is symmetric about the origin. It contains only sinusoids, not cosinusoids, so $a_n=0$. The magnitudes become $Mn=\sqrt{a_n^2+b_n^2}=\sqrt{b_n^2}$. For this Fourier series, the amplitudes $b_n$ of the sinusoids will be the same as the  magnitude $M_n$, since all the values of $b_n$ are positive. The magnitudes spectrum of the first 5 harmonics can be seen in the following figure



In the figure below, the magnitude spectrum and the time series of the signal in the same plot. We call the three first harmonics for $h_1$, $h_2$ and $h_3$, with the magnitudes $M_1=1$, $M_2=\frac{1}{3}$ and $M_3=\frac{1}{5}$, and linear frequencies, $f_1=f_0=1$,  $f_2=3f_0=3$ and $f_3=5f_0=5$, respectively. 

\begin{align*}
h_1 = \underset{\substack{\downarrow \\ M_1}}{1}\cdot \sin{2\pi\cdot \underset{\substack{\downarrow \\ f_1}}{1} \cdot x}, \hspace{8pt}
h_2 = \underset{\substack{\downarrow \\ M_2}}{\dfrac{1}{3}}\sin{2\pi \cdot \underset{\substack{\downarrow \\ f_2}}{3} \cdot  x} , \hspace{8pt}
h_3 = \underset{\substack{\downarrow \\ M_3}}{\dfrac{1}{5}}\sin{2\pi\cdot \underset{\substack{\downarrow \\ f_3}}{5} \cdot x}
\end{align*}

Taking the sum of $h_1$, $h_2$ and $h_3$ gives us the signal in the blue field, we see that the square wave starts to take form, the more harmonics we add the better the approximation gets. The magnitude spectrum is plotted in the red field. 



```python

```

4ddaca134a26622b72fec7de85c701eb6ea77c86
ipynb
Jupyter Notebook
1. Fourier Series.ipynb
Bjarten/flc-based-filters
4299cc4010f41a52c16770a1e712b2fe2a878dc5
MIT
2019-03-08T02:38:45.000Z
2022-03-18T12:13:26.000Z
1. Fourier Series.ipynb
Bjarten/flc-based-filters
4299cc4010f41a52c16770a1e712b2fe2a878dc5
MIT
1. Fourier Series.ipynb
Bjarten/flc-based-filters
4299cc4010f41a52c16770a1e712b2fe2a878dc5
MIT
2020-06-04T16:13:06.000Z
2020-06-04T16:13:06.000Z
Qwen/Qwen-72B
1. YES
2. YES