Solution (source code)

= Solution

Use degree-indexed <Fourier partial sums> and <Fejér sums>, as in this paper. For a $2\pi$-periodic <continuous function>, put
$$
\widehat f_k=\frac1{2\pi}\int_{-\pi}^{\pi}f(t)e^{-ikt}\,dt,\qquad s_n(f,x)=\sum_{k=-n}^n\widehat f_ke^{ikx},\qquad \sigma_n(f)=\frac1{n+1}\sum_{j=0}^ns_j(f).
$$
Equivalently,
$$
\sigma_n(f,x)=\sum_{|k|\le n}\left(1-\frac{|k|}{n+1}\right)\widehat f_ke^{ikx}.
$$
These are <trigonometric polynomials> of degree at most $n$. Some treatments index the <Fejér sum> by the number of terms rather than its degree; the degree convention here is why the formulas below contain $\sigma_{2n-1}$ and $\sigma_{n-1}$.