Fourier series expansion for nonlinear Hamiltonian oscillators