Given a periodic function $f:[0,2\pi] \rightarrow \mathbb{R}$ one calculates the Fourier coefficients $a_k$ and $b_k$ by
$$a_k \sim \int_0^{2\pi}f(t)\cos(kt)\mathrm{d}t$$
$$b_k \sim \int_0^{2\pi}f(t)\sin(kt)\mathrm{d}t$$
In turn one has $f(t) = a(t) + b(t)$ with
$$a(t) \sim \sum_{k=0}^\infty a_k\cos(kt)$$
$$b(t) \sim \sum_{k=0}^\infty b_k\sin(kt)$$
This is a case of round-tripping, i.e. $a(t)$ and $b(t)$ and thus $f(t)$ are perfectly reproduced.
But then I found a case where this seems to break, and I wonder if a) I made a mistake in my calculations (or assumptions) or b) this is an exceptional case which has an explanation.
For the triangle function $f_\triangle(t) = a_\triangle(t) + b_\triangle(t)$ (shown below in the middle) everything looks fine.
The impurities in the "reconstructions" are due to the fact that I evaluated the sum only up to $k = 100$.
$a$ corresponds to red, $b$ corresponds to blue. The curve shown above in the middle is $a(t) + ib(t)$.
Also for the square function $f_\square(t) = a_\square(t) + b_\square(t)$ everything looks fine.
But for the sawtooth function $f_{/\!|}(t) = a_{/\!|}(t) + b_{/\!|}(t)$ samething strange happens. While $b_{/\!|}(t)$ (blue) is reproduced, $a_{/\!|}(t)$ (red) isn't:
How can this be?
Once again:
Did I make a mistake in my calculations (or assumptions) or is this a somehow exceptional case which has an explanation?
This is how I defined the sawtooth function $f_{/\!|}(t) = a_{/\!|}(t) + b_{/\!|}(t)$ (black, for the sake of convenience with $f:[0,1] \rightarrow \mathbb{R}$):
$$b_{/\!|}(t) = \begin{cases} t & \text{ for } t < \frac{1}{2}\\ t-1 & \text{ otherwise} \end{cases}$$
$a_{/\!|}(t)$ (red) is just $b_{/\!|}(t)$ (blue) shifted by $\frac{1}{4}$ to the left:
$$a_{/\!|}(t) = \begin{cases} t + \frac{1}{4} & \text{ for } t < \frac{1}{4}\\ t - \frac{3}{4} & \text{ otherwise} \end{cases}$$



As it is rather hard for me to enter into your conventions, I thought the best thing I could do is to show you how I compute the coefficients of such a series.
I am going to stick to formulas (Eqn. 2) and (Eqn. 4) for a periodic function $f$ with period $P$ that can be found in the excellent Wikipedia article : https://en.wikipedia.org/wiki/Fourier_series.
I copy them here :
$$\displaystyle {\begin{aligned}a_{n}&={\frac {2}{P}}\int _{x_{0}}^{x_{0}+P}f(x)\cdot \cos \left({\tfrac {2\pi nx}{P}}\right)\ dx\\b_{n}&={\frac {2}{P}}\int _{x_{0}}^{x_{0}+P}f(x)\cdot \sin \left({\tfrac {2\pi nx}{P}}\right)\ dx,\end{aligned}}$$
giving the truncated series at rank $N$ equal to :
$$\displaystyle {\begin{aligned}s_{N}(x)&=a_{0}/2+\sum _{n=1}^{N}\left(a_{n}\cos \left({\tfrac {2\pi nx}{P}}\right)+b_{n}\sin \left({\tfrac {2\pi nx}{P}}\right)\right).\end{aligned}}$$
Let us define our sawtooth function $f$ as the periodic function with period $P=1$ defined on $[-\frac12,+\frac12]$ by $f(x)=x$ (see Fig. below).
As this function is odd in general and on this interval in particular, all $a_n$ coefficients are zero. The $b_n$ coefficients are readily computed (using integration by parts) as
$$b_n=\dfrac{(-1)^{n+1}}{\pi n}$$
(we have taken $x_0=0$).
For example, when we take the 3 first harmonics :
$$s_3(x)=\dfrac{1}{\pi}\left(\sin(2\pi x)-\dfrac{1}{2}\sin(4\pi x)+\dfrac{1}{3}\sin(6\pi x)\right)$$
Here is the graphical representation of $s_3$, in black, and the reference curve of $f$ in red :
Edit : If you shift function $f$ by $1/4$, I think that the error not to be done is to compute for example $a_n$ coefficients by the following formula :
$$a_n = 2 \int_{-1/2}^{1/2}(x+1/4) \cos(2 \pi n x) dx$$
because in this case, you aren't anymore working with a function whose values are in $[-1/2,1/2]$ but in a different interval. Instead, you have to take
$$a_n = 2 \int_{-1/2}^{1/4}(x+1/4) \cos(2 \pi n x) dx+ 2\int_{1/4}^{1/2}(x-3/4) \cos(2 \pi n x) dx$$
I find the following coefficients in this case :
$$a_n=\frac{2}{\pi n}\sin(\pi n/2)\sin(\pi n/4)^2$$
$$b_n=\frac{1}{2\pi n}(1+(-1)^n)$$
I have checked that they give the adequate result.