[Math] Fourier (sine) series of a piecewise function

fourier seriesfunctionsgraphing-functions

I need to find fourier series of the following function:
$$
f(x) =
\begin{cases}
0 & \text{if $x\in(0,\frac{\pi}{2})$} \\
\pi & \text{if $x\in(\frac{\pi}{2}, \pi)$}
\end{cases}
$$

and sketch the graph if sum of this series. I have a lot of such functions to transform into fourier series, however I'm not sure how to approach it and all I need to fully understand the topic is one step by step example on this function. I'd be really grateful for any help, as I have trouble understanding how to approach this topic.

I know that
$$
S_n(x) = \frac{A_0}{2} + \sum_{n=1}^{\infty}[A_ncos(nx)+B_nsin(nx)]
$$

I also managed to calculate, that
$$
A_0 = \frac{1}{\pi}\int_0^\pi f(x)cos(nx)dx
$$

And Bn respectively with sin instead of cos. The problem is, when I try to calculate An, it alternates between $0$, $\frac{1}{n}$ and $-\frac{1}{n}$. I don't really know how to approach this problem.

Best Answer

The Fourier series coefficients of

$$f(\text{x})=\pi\ \theta\left(x-\frac{\pi}{2}\right),\quad 0<x<\pi\tag{1}$$

are given by

$$b_n=\frac{1}{\pi/2}\int\limits_0^{\pi} f(x)\ \sin\left(\frac{\pi\ n\ x}{\pi/2}\right)\,dx\tag{2}=\frac{\cos(\pi\ n)-\cos(2\ \pi\ n)}{n}$$

and the values of these coefficients for $1\le n\le 10$ are as follows:

$$\begin{array}{cc} n & b_n \\ 1 & -2 \\ 2 & 0 \\ 3 & -\frac{2}{3} \\ 4 & 0 \\ 5 & -\frac{2}{5} \\ 6 & 0 \\ 7 & -\frac{2}{7} \\ 8 & 0 \\ 9 & -\frac{2}{9} \\ 10 & 0 \\ \end{array}$$


Therefore the Fourier series representation of $f(x)$ is as follows:

$$f(x)=\frac{\pi}{2}-\underset{K\to\infty}{\text{lim}}\left(\sum\limits_{k=1}^K\frac{2}{2\ k-1}\ \sin\left(\frac{\pi\ (2\ k-1)\ x}{\pi/2}\right)\right),\quad 0<x<\pi\tag{3}$$


The figure below illustrates the Fourier series defined in formula (3) above in orange overlaid on the reference function $f(x)$ defined in formula (1) above in blue where formula (3) is evaluated at $K=10$.

Illustration of formula (2) in orange overlaid on top of formula (1) in blue

Related Question