Realization of the Harper Hamiltonian with ultracold atoms in optical lattices