This paper describes a method for synthesizing spin rotations with arbitrary space dependence on a sample of noninteracting spin 12 by using nonselective radio frequency pulses and pulsed field gradients. This method is used to map out spatial distribution of inhomogeneous B(0) field and to engineer a space dependent evolution of spins that cancels the space dependent phase spins acquire when precessing in an inhomogeneous magnetic field. The technique allows one to record high resolution spectra in inhomogeneous magnetic field by using only time varying linear gradients and rf fields and is expected to find applications in ex situ NMR.