## Friday, November 8, 2013

### Fourier Series: Several functions

Second post dedicated to the Fourier series [Link] with several examples of classical periodic functions.

1- Triangle wave

The formula is:

$f\left(x\right)=\frac{4}{\pi }\left(\frac{1}{9}\mathrm{cos\left(3x\right)}+\frac{1}{25}\mathrm{cos\left(5x\right)}+...+\frac{1}{{n}^{2}}\mathrm{cos\left(}nx\right)\right)$
Or can be written like this...
$f\left(x\right)=\frac{4}{\pi }\sum _{k=1}^{\infty }\frac{\mathrm{cos\left(2k+1\right)}.x}{{\left(2k+1\right)}^{2}}$

and the corresponding macro...

+++ IJ snippet: Triangle_wave_fourier_series.ijm +++
+++ End of IJ snippet +++

To create the triangle wave, select the whole image (Ctrl+A) then compute the profile (`Analyze > Plot Profile` or Ctrl +K).

 Fig. 1: Triangle wave obtained from the sum of each row of the Fourier Series.

##### 2- Sawtooth wave
Another function defined by ...

$f\left(x\right)=\frac{2}{\pi }\left(\mathrm{sinx}-\frac{1}{2}\mathrm{sin\left(}2x\right)+\frac{1}{3}\mathrm{sin\left(3x\right)}-\frac{1}{4}\mathrm{sin\left(}4x\right)+...+{\left(-1\right)}^{n+1}\frac{1}{n}\mathrm{sin\left(}nx\right)\right)$

The following video shows the evolution of the resulting curve when we add more components.

#### 3- JavaScript

Here is a small script containing all the various functions previously described. For sake of convenience, this script is written in JavaScript but uses exactly the same function `Process > Math > Macro...`

+++ IJ JavaScript snippet +++ +++ End of IJ JavaScript snippet +++