Fourier series of a half-wave rectified ramp (source code)

= Fourier series of a half-wave rectified ramp
{c}
{title2=$f(x)=x+|x|\quad(-1<x<1)$}

Extend $f(x)=\max(0,2x)$ on $(-1,1)$ with period two. Its <Fourier coefficients> in the basis $\cos(n\pi x),\sin(n\pi x)$ are $a_0=1$, $a_n=2[(-1)^n-1]/(n\pi)^2$, and $b_n=2(-1)^{n+1}/(n\pi)$, by <integration by parts> on $(0,1)$. Thus
$$
f(x)\sim\frac12-\frac4{\pi^2}\sum_{r=0}^{\infty}\frac{\cos((2r+1)\pi x)}{(2r+1)^2}+\frac2\pi\sum_{n=1}^{\infty}\frac{(-1)^{n+1}\sin(n\pi x)}n.
$$
Its <even> part is the periodic extension of $|x|$ and its <odd> part is the <Fourier series of a periodic sawtooth> for $x$. The cosine terms converge absolutely and uniformly; the sine terms account for the jump at odd integers. At each jump, the full <Fourier series> has value $1$, the average of the two one-sided limits $0$ and $2$.