When is a Fourier series approximation "close enough"? I just started learning about Fourier series in my math class, and I'm still trying to wrap my head around how ridiculous and amazing it is that pretty much any function can be represented as the sum of sines and cosines.
My question is this: as you add more terms onto the Fourier series, the series more closely approximates the function; i.e. the Fourier series converges to the function. How many terms are required for the Fourier series approximation to be "close enough"? That is, for every function $f(t)$ with Fourier series approximation $S_N[f](t) = \sum_{n=-N}^{N} F_ne^{int}$ where $N$ is some integer, does there exist an integer $M$ such that $|f - S[f](t)| < M$? And if so, how would we find this value $M$ for some given function $f$?
I'm an electrical engineer major and trying to understand how this all works from a signals point of view. It would be nice to be able to say "oh, my Fourier series representation never differs from the original function by more than this value $M$."
I just now taught myself Latex so I could ask my question in a coherent way. You're welcome.
 A: This is by no means a complete answer (a complete answer is generally what a semester-long class in Fourier analysis can begin to provide), but I want to expand on my comment a little bit.  First off, you need to specify what you mean by "$S_N(f)$ converges to $f$."  There are a number of senses in which this can be interpreted.


*

*The condition that you give appears to be uniform convergence.  We say that $f_n \to f$ uniformly if for all $\varepsilon > 0$, there exists some $N$ so large that if $n \ge N$ then $|f_n(x) - f(x)| < \varepsilon$ for all $x$.  It can be shown (though the proof is non-trivial) that if $f$ is continuously differentiable, then you can hope for convergence this good.

*More generally, if a function is piecewise $C^1$ (i.e. it is continuously differentiable on $[0,2\pi]$, except at countably many points), or (more generally) if it is of bounded variation, then the Fourier series converges pointwise.  Indeed, you will get
$$ \lim_{N\to\infty} S_N(f)(t) = \frac{1}{2} \left( f(t^{+}) + f(t^{-1}) \right), $$
where $f(t^{+}) := \lim_{h \to 0^{+}} f(t+h)$, and $f(t^{-}) := \lim_{h \to 0^{-}} f(t+h)$.  If $f$ has any discontinuities, then this convergence cannot possibly be uniform (every Fourier partial sum is continuous, and the uniform limit of continuous functions is continuous, so you would arrive at a contradiction).  Indeed, the behaviour can be quite bad near discontinuities, giving rise to the Gibbs phenomenon mentioned in Brian Borchers' answer.
This result is discussed on Wikipedia under the heading Dirichlet's theorem for 1-dimensional Fourier series.  Dirichlet's original theorem was for continuously differentiable functions, but there are several more modern variants that relax and/or otherwise modify the hypotheses, but still get the same basic pointwise results.

*There are some important technical hurdles to get through, but after a bit of work, conditions can be given such that $S_N(f)$ converges to $f$ in $L^1$, which is to say that
$$ \int_{0}^{2\pi} |S_N(f)(t) - f(t)|\,\mathrm{d}t \to 0.$$
The basic idea is to think of the Fourier series as being the convolution of an integrable function against the Dirichlet kernel $D_N$, where
$$ D_N(t) := \sum_{|n|\le N}\mathrm{e}^{int}. $$
Roughly speaking, $S_N(f) = f\ast D_N$, where
$$ (g\ast h)(t) := \frac{1}{2\pi} \int_{0}^{2\pi} f(t-s) g(s) \,\mathrm{d}s. $$
The Dirichlet kernel isn't quite what we need to get the job done, so we introduce the Fejér kernel $F_N$, which is a Cesàro mean of the Dirichlet kernel.  It is possible to show that under fairly mild conditions, the sequence $f \ast F_N = S_N(f)$ converges to $f$ as an $L^1$ function.  I mention this only because the theory of Fourier transforms in general makes the most sense in the context of convolutions.  It is a lovely theory, and has a number of really useful applications to audio and image processing.


In any event, if you are interested in this theory, there are a number of good books out there at a reasonably accessible level (they assume some background, perhaps a little bit of real analysis and/or topology and/or abstract algebra; an advanced undergraduate should be fine).  Personally, I'm partial to Stein and Shakarchi's book, which has good exposition and some interesting exercises (though the text and problems don't always fit hand-and-glove).
Stein, Elias M.; Shakarchi, Rami, Fourier analysis. An Introduction, Princeton Lectures in Analysis. 1. Princeton, NJ: Princeton University Press. xvi, 311 p. (2003). ZBL1026.42001.
A: You should read up on "Gibbs Phenomenon."  Unfortunately, if there are discontinuities in $f(t)$, then the maximum error won't go to 0 as the number of terms increases.  
