NMR in inhomogeneous magnetic fields