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}
$$
 A: Define problem
Piecewise function: Resolve $f(x)$ into a left, center, and right piece
$$
\begin{align}
  %
  l(x) &= 0, \qquad \qquad \, -1 \le x < -\frac{1}{2} \\
  %
  c(x) &= \cos \left( 3\pi x \right) \quad\ -\frac{1}{2} \le x \le \frac{1}{2} \\
  %
  r(x) &= 0, \qquad \qquad \ \ \ \frac{1}{2} \le x \le 1
  %
\end{align}
$$
The length of the domain is $2$.
Find the Fourier expansion
$$ 
  f(x) = \frac{1}{2}a_{0} +
\sum_{k=1}^{\infty} \left(
  a_{k} \cos \left( k \pi x \right) +
  \color{gray}{b_{k} \sin \left( k \pi x \right)}
\right)
$$
where the amplitudes are given by
$$
\begin{align}
  %
  a_{0} &= \int_{-1}^{1} f(x) dx \\
  %
  a_{k} &= \int_{-1}^{1} f(x) \cos \left( k \pi x \right) dx \\
  %
  \color{gray}{b_{k}} &= \color{gray}{\int_{-1}^{1} f(x) \sin \left( k \pi x \right) dx} \\
  %
\end{align}
$$
Basic integrals
Center piece
$$
\begin{align}
  %
  \int_{-\frac{1}{2}}^{\frac{1}{2}} c(x) dx &= -\frac{2}{3 \pi } \\
  %
  \int_{-\frac{1}{2}}^{\frac{1}{2}} c(x) \sin \left( k \pi x \right) dx &= 0 \\
\end{align}
$$
For $m\ne n$,
$$
\int \cos (m \pi   x) \cos (n \pi x) \, dx =
\left( 2\pi \right)^{-1}
\left( 
\frac{\sin (\pi (m-n) x )}{m-n}+\frac{\sin (\pi (m+n) x )}{m+n}
\right)
$$
$$
\int \cos (3 \pi  x) \cos (3 \pi  x) \, dx = \frac{x}{2}+\frac{\sin (6 \pi  x)}{12 \pi }
$$
Amplitudes
$$
\begin{align}
  a_{0} &= -\frac{2}{3 \pi }, \\
  a_{3} &=  \frac{1}{2}.
\end{align}
$$
For $k=1,2,\dots..$
$$
a_{2k} = \frac{6 \cos \left( \pi  k \right)}{\pi  \left((2k)^2-9\right)}
$$
Convergence sequence
The parameter $n$ represents the highest frequency term in the series, 
$$
  f(x) = \frac{1}{2}a_{0} +
\sum_{k=1}^{n}
  a_{k} \cos \left( \frac{k \pi x}{2} \right)
$$





A: 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}$
