Fourier's Trick
Let \( \{f_n\} \) be an orthonormal basis, that is
$$ \langle f_n, f_m \rangle = \delta_{nm} = \begin{cases} 1 & n = m \\ 0 & n \neq m \end{cases} $$Then any function can be written as a linear combination of \( \{f_n\} \)
$$ g(x) = \sum_{n=1}^{\infty} c_n f_n(x) $$ $$ \int_{-\infty}^{\infty} dx \, f_m^*(x)g(x) = \int_{-\infty}^{\infty} dx \, f_m^*(x) \left( \sum_{n=1}^{\infty} c_n f_n(x) \right) $$ $$ = \sum_{n=1}^{\infty} c_n \int_{-\infty}^{\infty} dx \, f_m^*(x)f_n(x) $$Using orthonormality,
$$ \int_{-\infty}^{\infty} dx \, f_m^*(x)f_n(x) = \delta_{mn} \quad \text{where} \quad \delta_{mn} = \begin{cases} 1 & n = m \\ 0 & n \neq m \end{cases} $$so this becomes
$$ \sum_{n=1}^{\infty} c_n \delta_{mn} = c_m $$The Kronecker delta \( \delta_{mn} \) kills every term except the one for which \( n = m \). Therefore, the \( n \)-th coefficient in the expansion of \( f(x) \) is
$$ c_n = \int_{-\infty}^{\infty} dx \, f_n^*(x)f(x) $$