Calculate the Fourier series of $f(x)= \frac{1}{2} - |x-\frac{1}{2}|$
According to our definition of Fourier Series $\hat{f}(k) = \int_{0}^1 f(x) e^{-2 \pi ikx} dx $ is the k-th Fourier coefficient of $f$.
for $k\ne 0$ $$\int_{0}^1 ( \frac{1}{2} - |x -\frac{1}{2}|)e^{-2 \pi ikx} dx $$ $$=\frac{1}{2}\int_{0}^1 e^{-2 \pi ikx} dx + \int_{0}^1 |x -\frac{1}{2}|e^{-2 \pi ikx} dx$$
Integrating the first integral, it evaluates to zero $\left[ \frac{1}{2} \frac{e^{-2 \pi ikx}}{-2 \pi ik} \right]_0^{1} = 0$ $$=0 + \int_{0}^1 |x -\frac{1}{2}|e^{-2 \pi ikx} dx$$ Now I substitute $t=x-\frac{1}{2}$ and change the integration boundaries to $t=-\frac{1}{2}$ and $t=\frac{1}{2}$ $$\int_{-\frac{1}{2}}^\frac{1}{2} |t|e^{-2 \pi ki(t+\frac{1}{2})} dt $$ I can pull out $e^{-\pi ik}$ because it does not depend on t and this $e^{-\pi ik}= (-1)^k $ according to my notes(correct me if I am wrong) $$(-1)^k \int_{-\frac{1}{2}}^\frac{1}{2} |t|e^{-2 \pi ki(t)} dt$$ Now I use integration by parts and set $f=|t|$, $f^\prime(t)= \frac{t}{|t|}$, $g=\frac{e^{-2 \pi ikt}}{-2 \pi ik}$ and $g^\prime(t) = e^{-2 \pi ikt}$ $$(-1)^k \left[ |t| \frac{e^{-2 \pi ikt}}{-2 \pi ik} \right]_\frac{-1}{2}^\frac{1}{2} - \int_{-\frac{1}{2}}^\frac{1}{2} \frac{t}{|t|} \frac{e^{-2 \pi ikt}}{-2 \pi ik} dt$$ The first integrand evaluates to zero. Thus we have $$(-1)^k - \int_{-\frac{1}{2}}^\frac{1}{2} \frac{t}{|t|} \frac{e^{-2 \pi ikt}}{-2 \pi ik} dt$$ Then I use subsitution $u=\frac{t}{|t|}e^{-2 \pi ikt}$ and $\frac{du}{dt}= \frac{-2 \pi ikte^{-2 \pi ikt}}{|t|}$ and $dt=|t|\frac{e^{-2 \pi ikt}}{-2 \pi ik} du$ $$(-1)^k \left[ t \frac{e^{-2 \pi ikt}}{-2 \pi ik} \right]_\frac{-1}{2}^\frac{1}{2}$$ $$=(-1)^k [\frac{1}{-4\pi ik} + \frac{1}{-4\pi ik}] = \frac{2}{-4\pi ik} = \frac{1}{-2\pi ik}= \frac{(-1)^k}{-2\pi ik}$$
for $k=0$ we know the $e^{-2 \pi ikx}=0$ $$\int_{0}^1 |x-\frac{1}{2}|dx = \frac{1}{4}$$
So $$Sf(x)= \frac{1}{4} +\sum_{k\ne 0} \frac{(-1)^k}{-2\pi ik}e^{2\pi ikx}= \frac{1}{4} -\frac{1}{2\pi i}\sum_{k\ne 0} \frac{(-1)^k}{k}e^{2\pi ikx}= \frac{1}{4} -\frac{1}{2\pi i}\sum_{k\ne 0} \frac{(-1)^k}{k}i\sin(2\pi kx)$$ $$ = \frac{1}{4} -\frac{1}{2\pi}\sum_{k\ne 0} \frac{(-1)^k}{k}\sin(2\pi kx)$$
Could someone please verify if what I have done is correct. I hope this is clear enough as I had to let out some "somehow more obvious" parts otherwise I would have been very long. Also sorry if I had some typos. Any help is appreciated and Thanks.