# How is a Coordinate transformation done?

The starting point is Binary to ASCII conversion of the raw data file so that you have access to the three velocity files, *.v1, *.v2 *.v3, the transformation matrix and the *.sen file. Heading, pitch and roll are presented in the .sen file (ref *.hdr), and these angles are output in degrees. The figure below indicates the three coordinate systems that the velocity data in *.v1, *.v2 *.v3 are measured in; Beam, XYZ or ENU. The coordinate system selected during the deployment planning are indicated in the *.hdr file.

Each instrument has its own unique transformation matrix, based on the transducer geometry. This matrix can be found, as previously mentioned, in the *.hdr file, generated when performing a binary data conversion in the software. Each row of the matrix represents a component in the instrument’s XYZ coordinate system, starting with X at the top row. Each column represents a beam. The third and fourth rows of the Vectrino transformation matrix represent the two estimates of vertical velocity (Z1 and Z2) produced by the instrument. XYZ coordinates are defined relative to the instrument, so they do not take into account heading, pitch and roll. ENU utilize the attitude measurements to provide an earth relative coordinate system.

**Beam to XYZ:**

The transformation between beam and xyz coordinates are done using the original T matrix listed in the header file. In matrix form (using Matlab notation, so [ X; Y; Z ] is a column vector), the math is

T * [ B1; B2; B3 ] = [ X; Y; Z ]

Taking the matrix inverse of T will get you back to beam

inv( T ) * [ X; Y; Z ] =[ B1; B2; B3 ]

For the Vectrino Profiler: The transformation matrix for the Vectrino Profiler range cells is stored in Config.ProbeCalibration_calibrationMatrix, one row per each cell. To get the calibration matrix in a more usable form for transforms, this can be used:

T = reshape( Config.ProbeCalibration_calibrationMatrix( cell, : ), 4, 4 )' - Note the transpose

And to convert from XYZ to beam:

inv( T ) * [ X; Y; Z1; Z2 ]

**Beam or XYZ to ENU:**

The transformation matrix must be recalculated every time the heading, pitch or roll changes, when selecting ENU coordinates.

The procedure is as follows:

- Find the transformation matrix in the *.hdr file
- Scale the transformation matrix if it has not been scaled already (i.e. has a value of several thousand). The scaling parameter is 4096
- Check orientation of the instrument (*.sen file, status bit, bit no.0. 0 = uplooking, 1 = downlooking). If instrument is pointing down rows 2 and 3 of the matrix must change sign.
- Make a heading matrix
- Make a tilt matrix
- Make a new transformation matrix (R), including the heading and tilt matrix (refer to the matlab script attached for details)
- Then:

[E; N; U;] = R * [ B1; B2; B3 ]

[ B1; B2; B3 ] = inv(R) * [E; N; U;]

[E; N; U;] = R * inv(T) * [ X; Y; Z ]

[ X; Y; Z ] = T * inv(R) * [E; N; U;]

Here is a matlab script describing how to do the transformation: Matlab script

**Four Beam ADCP velocities into ENU:**

The matlab scipt above can be used for four beam systems also. As seen from the script, the transform has two steps - one from beam to XYZ and then from XYZ to ENUcoordinates.

The first step is a little different for a 4-beam systems:

Vx= (V1 – V3)/2*sin(20 deg)

Vy= (V2 – V4)/2*sin(20 deg)

Vz= (V1+V2+V3+V4)/4*cos(20 deg)

(For a 4 beam system with 20 degree beams, where the beams are numbered with the clock)

The next step from XYZ to ENU is the same as for 3-beam systems.