A method for homogenizing a static magnetic field with a magnetic field
distribution B0(r) for nuclear magnetic resonance spectroscopy by
adjusting the currents C.sub.i through the shim coils, thus creating
spatial field distributions C.sub.iS.sub.i(r), where r stands for one,
two, or three of the spatial dimensions x, y, and z, and said magnetic
field distribution B0(r) has only a field component along z, in a working
volume of a magnetic resonance apparatus with one or more radio frequency
(=RF) coils (5) for inducing RF pulses and receiving RF signals within a
working volume, said RF coils having a spatial sensitivity distribution
of magnitudes B1.sub.k(r), and with shim coils (6) for homogenizing the
magnetic field within the working volume, said shim coils (6) being
characterized by their magnetic field distributions per unit current
S.sub.i(r) and having components only along z, includes the following
steps: (a) Mapping the magnetic field distribution B0(r) of the main
magnetic field, (b) calculating a simulated spectrum I.sub.S(f) based on
the sum of the magnetic field distribution B0(r) and the additional field
distributions C.sub.iS.sub.i(r) generated by the shim coils (6), and on
the sensitivity distributions B1.sub.k(r) of the RF coils (5), (c)
optimising a quality criterion derived from the simulated spectrum
I.sub.S(f) by using an optimisation procedure within a search range with
the shim currents C.sub.i as a set of parameters, whereby for each new
set of parameter values step (b) has to be repeated, (d) realising the
found optimum of the quality criterion of step (c) by generating the
associated target field distribution B0.sub.T(r). In this way a direct
one-to-one link is obtained between a set of shim currents and the
associated NMR spectrum The quality of the desired NMR spectra can be
improved with this method.