Fourier Series/ fourier transform What is the Fourier series of the following piece-wise function?
$$
f(x) = \begin{cases}
  0  &  -1 \leq x < -0.5 \\
  \cos (3 \pi x) & -0.5 < x < 0.5 \\
  0  &  0.5 \leq x < 1
\end{cases}
$$

Given f(x) = \begin{cases}
  0  &  -1 \leq x < -0.5 \\
  \cos (3 \pi x) & -0.5 < x < 0.5 \\
  0  &  0.5 \leq x < 1
\end{cases}
Its nth Fourier polynomial is $S_n(x)=\sum_{v=-n}^{n}\alpha_ve^{ivx}$, where $\alpha_v=\int_{-\pi}^{\pi}f(x)e^{ivx}dx=\int_{-1/2}^{1/2} \cos(3\pi x)e^{ivx}dx$. Notice that $\dfrac{e^{3\pi ix}+e^{-3\pi ix}}{2}=cos(3 \pi x)$, so $$\alpha_v=\int_{-1/2}^{1/2}\dfrac{e^{(v+3\pi) ix}+e^{(v-3\pi) ix}}{2}dx=\dfrac{e^{(v+3\pi)ix}}{2i(v+3\pi)}+\dfrac{e^{(v-3\pi)ix}}{2i(v-3\pi)}\mid_{-1/2}^{1/2}=\dfrac{e^{(v+3\pi)i/2}}{2i(v+3\pi)}+\dfrac{e^{(v-3\pi)i/2}}{2i(v-3\pi)}-\dfrac{e^{-(v+3\pi)i/2}}{2i(v+3\pi)}-\dfrac{e^{-(v-3\pi)i/2}}{2i(v-3\pi)}=\dfrac{\sin(\dfrac{v+3\pi}{2})}{2(v+3\pi)}+\dfrac{\sin(\dfrac{v-3\pi}{2})}{2(v-3\pi)}=\dfrac{3\pi\cos(\dfrac v2)}{v^2-9\pi^2}$$
Notice that if we regard $\alpha_v$ as a function of $v$, it is an even function. That is, $\alpha_v=\alpha_{-v} \;\forall |v|\le n$. Furthermore, $\alpha_0=-\dfrac1{3\pi}$. Hence $S_n(x)=-\dfrac1{3\pi}+3\pi\sum_{v=1}^{n}\dfrac{e^{ivx/2}+e^{3ivx/2}}{v^2-9\pi^2}$
