Fast decaying Fourier coefficients for indicator function Let $0 \leq a < b \leq 1$. I wanted to compute the Fourier series expansion of the indicator function $f = \chi_{[a, b]}$ of the interval $[a, b]$, as $f(x) = \sum_{k\geq 0}a_k e(kx)$. My computations gave the following Fourier coefficients: $a_0 = (b - a)$ and $a_k = \frac{e\left(-k\frac{a+b}{2}\right)\sin(\pi(b-a)k)}{\pi k}$ for $k > 0$. But when I plotted the real and imaginary parts of the Fourier series approximation on Matlab of orders 100 and 1000, I got nothing closer to the indicator function, graphically it was more like a sine wave.
My guess is that finite truncation of this series does not actually approximate this function. One observation is that the series of Fourier coefficients in this case does not absolutely converge. Hence, I speculate that the problem here is that the Fourier coefficients are not decaying fast enough. I am new to Fourier theory, could someone elaborate more on this.
Is it possible to instead consider some smooth function that is a reasonable approximation of the indicator function? For example a smooth top hat function. In that case, can you give some references or elaborate on that?
 A: Assuming
$$f_{a,b}(x)=\left\{\begin{array}{cc}
 1 & a\leq x\leq b \\
 0 & \text{otherwise} \\
\end{array}\right.\quad 0\le a<b\le 1\land 0\le x\le 1\tag{1}$$
and
$$g_{a,b}(x)=\underset{\epsilon\to 0}{\text{lim}}\left(\frac{f_{a,b}(x+\epsilon)+f_{a,b}(x-\epsilon)}{2}\right)\tag{2}$$
then $g_{a,b}(x)$ can be approximated by the Fourier series
$$g_{a,b}(x)\approx (b-a)+\underset{K\to\infty}{\text{lim}}\left(\sum\limits_{n=1}^K\left(\frac{(\sin(2 b n \pi)-\sin(2 a n \pi))}{n \pi} \cos(2 \pi n x)+\frac{(\cos(2 a n \pi )-\cos(2 b n \pi))}{n \pi} \sin(2 \pi n x)\right)\right)=(b-a)+\underset{K\to\infty}{\text{lim}}\left(\sum\limits_{n=1}^K \frac{2 \sin(\pi n (b-a))}{\pi n} \cos(\pi n (a+b-2 x))\right)\tag{3}$$
which is periodic with period $T=1$.

Figure (1) below illustrates formula (3) for $g_{a,b}(x)$ above in orange overlaid on $f_{a,b}(x)$ defined in formula (1) above in blue where $a=\frac{1}{3}$, $b=\frac{2}{3}$, and formula (3) is evaluated at $K=100$. The red discrete evaluation points illustrate formula (3) for $g_{a,b}(x)$ evaluated at $x=a=\frac{1}{3}$ and $x=b=\frac{2}{3}$.

Figure (1): Illustration of formula (3) for $g_{a,b}(x)$ (orange curve)

The function $g_{a,b}(x)$ can also be approximated by
$$g_{a,b}(x)\approx\underset{K\to\infty}{\text{lim}}\left(\frac{\text{Si}(2 \pi K (x-a))-\text{Si}(2 \pi K (x-b))}{\pi}\right)\tag{4}$$
which unlike formula (3) above is non-periodic.

Figure (2) below illustrates formula (4) for $g_{a,b}(x)$ above in orange overlaid on $f_{a,b}(x)$ defined in formula (1) above in blue where $a=\frac{1}{3}$, $b=\frac{2}{3}$, and formula (4) is evaluated at $K=100$. The red discrete evaluation points illustrate formula (4) for $g_{a,b}(x)$ evaluated at $x=a=\frac{1}{3}$ and $x=b=\frac{2}{3}$.

Figure (2): Illustration of formula (4) for $g_{a,b}(x)$ (orange curve)

As $b-a$ decreases in magnitude the evaluation limit $K$ in formulas (3) and (4) above must be increased in order to obtain a reasonable approximation.
