I'm using this definition, which is probably yours (?): .

Note that is the -th complex Fourier coefficient of the function (extended periodically). The general theory says that its Fourier series converges: for all . Take the real part of both sides, and notice that so that terms with odd indices cancel, while terms with even (non-zero) indices count twice (this gives the 2 in your formula). That's it.