.. _example_03:

(3) Spectral estimation and xy-plots
------------------------------------

In this example we will show how to use the GMT programs
:doc:`fitcircle </fitcircle>`, :doc:`project </project>`,
:doc:`sample1d </sample1d>`, :doc:`spectrum1d </spectrum1d>`,
and :doc:`plot </plot>`. Suppose you have (*lon, lat,
gravity*) along a satellite track in a file called ``sat.xyg``, and (*lon, lat,
gravity*) along a ship track in a file called ``ship.xyg``. You want to make a
cross-spectral analysis of these data. First, you will have to get the
two data sets into equidistantly sampled time-series form. To do this,
it will be convenient to project these along the great circle that best
fits the sat track. We must use
:doc:`fitcircle </fitcircle>` to find this great circle
and choose the L\ :sub:`2` estimates of best pole. We project the data
using :doc:`project </project>` to find out what their
ranges are in the projected coordinate. The
:doc:`gmtinfo </gmtinfo>` utility will report the minimum
and maximum values for multi-column ASCII tables. Use this information
to select the range of the projected distance coordinate they have in
common. The script computes the common range. We can then resample the projected data, and carry
out the cross-spectral calculations, assuming that the ship is the input
and the satellite is the output data. The final plot ``example_03.ps`` shows the ship and sat power
in one diagram and the coherency on another diagram, both on the same
page, with an auto-generated legend. Thus, the complete automated script reads:

.. literalinclude:: /_verbatim/ex03.txt
   :language: bash

The final illustration shows that the
ship gravity anomalies have more power than altimetry derived gravity
for short wavelengths and that the coherency between the two signals
improves dramatically for wavelengths > 20 km.

.. figure:: /_images/ex03.*
   :width: 500 px
   :align: center

   Spectral estimation and x=y-plots.
