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

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)
$$





