I'm trying to understand how bad the Gibbs phenomenon is. Say I have for instance a square wave on $[0, 1]$, and I want to approximate it with a Fourier series. How many terms would I need to approximate $x=\delta$ within $\epsilon$?
In general, is there a big-O expression for how many terms would be needed to overcome the Gibbs phenomenon at a discontinuity?
I'm aware that the convergence is not uniform. I'm curious about the pointwise convergence of a point $\delta$ away from a discontinuity, particularly how the number of terms $n$ needed to be within $\epsilon$ varies with $\delta$.
A typical way to estimate the error is to write the partial sum as the convolution of the function with the Dirichlet kernel, and estimate that integral. Here we consider the $2$-periodic function $f$ which agrees with $\operatorname{sign}x$ on $(-1,1)$. The Dirichlet kernel is $D_n(t)=\sin((n+1/2)\pi t)/\sin(\pi t/2)$, and the partial sum $s_n$ is related to it by $$s_n(x) = \frac12 \int_{-1}^1 f(x-t)D_n(t)\,dt$$ Subtract $f(x)$, using the fact that $\frac12 \int_{-1}^1 D_n(t)\,dt=1$. $$s_n(x)-f(x) = \frac12 \int_{-1}^1 (f(x-t)-f(x)) D_n(t)\,dt$$ Here $x$ is your $\delta$, a fixed positive number. As a function of $t$, the difference $f(x-t)-f(x)$ is equal to $-2$ on $(-1,x-1)\cup (x,1)$ and $0$ elsewhere (I don't care which way the endpoints go). So, $$s_n(x)-f(x) = -\int_{-1}^{x-1} D_n(t)\,dt - \int_{x}^{1} D_n(t)\,dt $$ Both integrals are estimated in the same way, since $D_n$ is an even function. Integrate by parts: $$\int_{x}^{1} D_n(t)\,dt = \left[-\frac{\cos((n+1/2)\pi t)}{\pi(n+1/2)}\frac{1}{\sin(\pi t/2)}\right]\bigg|_{t=x}^{t=1} \\ - \frac{1}{2n+1}\int_x^1 \frac{\cos((n+1/2)\pi t)\cos(\pi t/2)}{\sin(\pi t/2)^2}\,dt$$ Estimate cosines from above by $1$ (except $\cos((n+1/2)\pi )=0$), the sine from below as $\sin(\pi t/2)\ge t$: $$\left|\int_{x}^{1} D_n(t)\,dt\right| \le \frac{1}{\pi(n+1/2)} \frac{1}{x} + \frac{1}{2n+1}\int_x^1 \frac{1}{t^2}\,dt \\ = \frac{1}{\pi(n+1/2)}\frac{1}{x} + \frac{1}{2n+1}\left(\frac{1}{x}-1\right)$$ We also have the other integral, with $1-x$ instead of $x$. Add the error bounds: $$|s_n(x)-f(x)|\le \frac{1}{\pi(n+1/2)}\left[ \frac{1}{x(1-x)} + \frac{\pi}{2}\left(\frac{1}{x(1-x)}-2\right)\right]$$ So, you are guaranteed to be within $\epsilon$ at $x=\delta$, if $$ n\ge \frac{1}{\epsilon}\left[ \frac{1}{\delta(1-\delta)} + \frac{\pi}{2}\left(\frac{1}{\delta(1-\delta)}-2\right)\right]-\frac12 $$