The error stems from the numeric algorithm used for the integration.
If fails for k=15 We have often seen this behavior in non-continuous integrands.
In your case it helps to change the value of the system variable TOL (default is 10-3).
Interestingly the calculation does not only converge if we set it to a larger value like 10-2 but it also works with TOL = 10-4.
You can set the value via the menu or simply write TOL:=10-4 somewhere at the top of the sheet (at least in front of the integral),
Now you can define the FOURIER approximation of the periodic signal and compare the results with the original signal.


Or even better make advantage of the symmetry of the signal (no sine wave components.
Just for demonstration I turned A into a function of k. While this may be more compact, needs no range variable and does not limit N, its less efficient and much more time consuming because A has to be calculated from anew every time f(t,..) is called.

You may also increase the accuracy of the numerical integration if you use ti as upper integral limit instead of T/2 (the integrand is now continuous).

The approach of using symmetry and to integrate from 0 to T/2 or ti works OK even with the default value for TOL.
Now that we have limited the signal to one simple linear function only, we can also use Prime's symbolics (would not work using the "if" statement in the definition of the signal).

Prime 11 sheet attached