I am writing a mathematics paper on the convergence of the Fourier series for periodic functions, and in the first section (where I define the Fourier series), I also derive the standard coefficients $a_n, b_n$. The standard way of doing this is to multiply both sides of the function by $\cos{kx}$ or $\sin{kx}$ depending on which coefficient you are calculating, and integrating from $-\pi$ to $\pi$, as follows:
$$\int_{-\pi}^\pi f(x)\cos(kx) \, dx = \int_{-\pi}^\pi a_0 \cos{kx} \, dx + \int_{-\pi}^\pi \left(\sum_{n=1}^\infty a_n\cos{nx}\cos{kx} + b_n\cos{nx}\sin{kx} \right)\,dx.$$
However, from this point, the standard derivation of the coefficients involves interchanging the integral and the sum, but to me this is not inherently obvious. For example, if $a_n = 1$ for all $n$, the summation does not converge and we would be integrating something infinite, which doesn't make sense. I've looked at a few posts that talk about interchanging the order of the sum and integral, and most of them don't really seem to apply.
Monotone convergence and Vitali convergence don't seem to apply since we can't make statements about pointwise convergence of $a_n\cos{kx}$ or $b_n\sin{kx}$ without being circular. Fubini's theorem tells us that if $\int\sum_n |f_n(x)| \,dx $ is finite, then we can interchange the summation and integral. However, we can't guarantee that such an integral is finite unless $\int_{-\pi}^\pi f(x) \cos(x)\, dx$ is finite--which led me to assume that the finiteness of the sum is a sufficient condition for interchanging the integral and sum, but my professor said this was insufficient.
Another thing I am thinking about is that pointwise convergence does not preserve integrability, but uniform convergence does. Does this mean that we can only derive the coefficients $a_n, b_n$ when $f$ is uniformly convergent? In that case, why would anyone care about pointwise convergence with the Dirichlet kernel proof?
I guess put simply, my question is, what can we stipulate about $f$ so that the interchange above is valid?
How about the dominated convergence theorem? If you know the coefficients $a_n$ and $b_n$ decay rapidly enough so that the partial sums $|\sum_{n}^{N} a_n\cos(kx)+b_n\sin(kx)|$ are dominated by an integrable function, then the interchange is legal by dominated convergence. How fast the coefficients decay depends on the smoothness of $f$. For example if $f$ is twice continuously differentiable you can show using integration by parts that the coefficients grow like $\frac{1}{n^2}$. In this case the partial sums are indeed dominated by an $L^1[-\pi,\pi]$ function, namely a constant function.