Stokes' well-known formula integrates gravity anomalies on a sphere to geoi
dal undulations. Traditionally the effect of continuing the observed gravit
y anomaly from the Earth's surface to sea level is estimated in a rather ro
ugh manner, which significantly degrades the resulting geoidal undulations.
In addition, the derived fictitious gravity anomalies at sea level are num
erically unstable. This problem is solved by directly deriving a surface in
tegral for the effects on the geoidal undulation and height anomaly. In add
ition, the solution is stabilized by optimized spectral smoothing by minimi
zing the mean square error. The final formula is a function of the gravity
anomaly, height anomaly and topographic height.