  We develop an approach, by calculating the autocorrelation function of spins, to derive the magnetic field gradient induced transverse ($T_2$) relaxation of spins undergoing restricted diffusion. This approach is an extension to the method adopted by McGregor. McGregor's approach solves the problem only in the fast diffusion limit; however, our approach yields a single analytical solution suitable in all diffusion regimes, including the intermediate regime. This establishes a direct connection between the well-known Torrey's slow diffusion result and the fast diffusion result. We also perform free induction decay measurements on spin-exchange optically polarized $^3$He gas with different diffusion constants. The transverse relaxation profiles are compared with the theory and satisfactory agreement has been found throughout all diffusion regimes. In addition to the transverse relaxation, this approach is also applicable to solving the longitudinal relaxation ($T_1$) regardless of the diffusion limits. It turns out that the longitudinal relaxation in the slow diffusion limit differs by a factor of two, compared with that in the fast diffusion limit. 
General Solution to Gradient Induced Transverse and Longitudinal   Relaxation of Spins Undergoing Restricted Diffusion