# Fourier series complex to real

I have to find the Fourier series of this function in complex form and transfer it to real:

$$\f:(-\pi;\pi]\to \mathbb{R},\;\;\;f(x)= \begin{cases} x & -\frac{\pi}{2} \leq x \leq \frac{\pi}{2} \\ 0 & -\pi \leq x < -\frac{\pi}{2} \;\;\; \bigcup \;\;\; \frac{\pi}{2} < x \leq \pi\end{cases}\$$

Calculating complex Fourier coefficients:

$$\c_n=\frac{1}{2\pi}\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}f(x)e^{-inx}dx\$$

$$\c_0=\frac{1}{2\pi}\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}xe^0dx=0\$$

$$\c_n=\frac{1}{2\pi}\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}xe^{-inx}dx=\frac{1}{2\pi n^2}(in\frac{\pi}{2} e^{in\frac{\pi}{2}}+in\frac{\pi}{2} e^{-in\frac{\pi}{2}}+e^{-in\frac{\pi}{2}}-e^{in\frac{\pi}{2}})\$$

$$\=\frac{1}{2\pi n^2}(in\frac{\pi}{2}(e^{in\frac{\pi}{2}}+e^{-in\frac{\pi}{2}})-(e^{in\frac{\pi}{2}}-e^{-in\frac{\pi}{2}})\$$

$$\=\frac{1}{2\pi n^2}(2in\pi cos(n\frac{\pi}{2})-2isin(n\frac{\pi}{2}))\$$

$$\=\frac{icos(n\frac{\pi}{2})}{n}-\frac{isin(n\frac{\pi}{2})}{\pi n^2}\$$

I use such formula:

$$\cos(n\frac{\pi}{2})=(-1)^n \;\;\; \;\;\; \;\;\; n, 2n\$$

$$\sin(n\frac{\pi}{2})=(-1)^{n+1} \;\;\; \;\;\; n, 2n-1\$$

$$\=\frac{i(-1)^n}{2n}-\frac{i(-1)^{n+1}}{\pi (2n-1)^2}\$$

At this point I´ve no idea how to transform it further into real. How can I handle even and odd $$\n\$$ into a formula?

I want a Fourier series like:

$$\A_0=\sum_{i=1}^{\infty}cos(n\omega_0 x+\phi_0)\$$

Any help would be appreciated.

I have tried this but solution is not correct. Can you show me right result

$$\\\\$$

$$\=(\frac{(-1)^n}{2n}+\frac{(-1)^{n+2}}{\pi (2n-1)^2})i=(\frac{(-1)^n}{2n}+\frac{(-1)^{n+2}}{\pi (2n-1)^2})e^{i\frac{\pi}{2}}\$$

$$\\\\$$

$$\=f(x)=\sum_{-\infty}^{\infty}(\frac{(-1)^n}{2n}+\frac{(-1)^{n+2}}{\pi (2n-1)^2})e^{i\frac{\pi}{2}x}e^{-i\frac{\pi}{2}x}\$$

$$\\\\$$

$$\=\sum_{n=1}^{\infty}2(\frac{(-1)^n}{2n}+\frac{(-1)^{n+2}}{\pi (2n-1)^2})cos(nx+\frac{\pi}{2})\$$

Make use of the following two facts: $$z + z^* = 2\cdot Re(z)$$ $$z\cdot e^a = |z|\cdot e^{a + i\cdot arg(z)}$$ The first equation comes into play when summing corresponding complex terms for +/- $$\n\$$. The second is used for determining the real parts in the form of $$\A_n cos(\omega_n t + \varphi_n)\$$.
Edit: I will show you how to apply the previously stated facts to reach the desired solution. Notice that $$\c_{-n} = c_n^*\$$ because $$\Im(f) = 0\$$. Hence $$c_{-n}\cdot e^{-i\omega_n t} + c_{n}\cdot e^{i\omega_n t} = z_n + z_n^*$$ for $$\z_n = c_{n}\cdot e^{i\omega_n t}\$$. We therefore get $$z_n + z_n^* = 2\cdot Re(z_n)$$ by making use of fact number one. To calculate $$\Re(z_n)\$$ in the desired form we will have make use of fact number 2. The real part follows to $$Re(z_n) = |c_n|\cdot cos(\omega_n t + arg(c_n)).$$ Hence the final answer is given by $$f(t) = c_0 + \sum_{n>0} 2\cdot |c_n|\cdot cos(\omega_n t + arg(c_n)).$$