Spatial localization in nuclear magnetic resonance spectroscopy