Here is an example:
sage: f = lambda x:x^2
sage: f = Piecewise([[(-1,1),f]])
sage: x = var("x")
sage: n = var("n")
sage: f.fourier_series_cosine_coefficient(n,1)
((2*pi^2*n^2 - 4)*sin(pi*n) + 4*pi*n*cos(pi*n))/(pi^3*n^3)
sage: maxima.eval('declare(n,integer)')
'done'
sage: f.fourier_series_cosine
The module piecewise.py has fairly extensive functionality for the
computation of Fourier series of piecewise defined periodic functions.
It even allows filters. There are examples at
http://www.sagemath.org/doc/html/const/node12.html
http://www.sagemath.org/hg/sage-main/file/cc1e12a492fc/sage/fun