# ECEF to relative displacement in meters

I have GPS NMEA (National Marine Electronics Association) data that I collected being stationary and I can see the displacement of 4 meters just by looking at GPX data uploaded to google maps.

I am trying to see this 4 meters by math. I am using Matlab where I read the data in geodetic degrees and used a function to translate it to ECEF in XYZ. I have done that for both the measurement of GPS and my true location and subtracted both in XYZ.

The result is showing a difference of 312 in X-axis and 60 in Y-axis, instead, I was expecting around 4 for both.

Below is the code I used for Geodetic DD conversion to ECEF XYZ:

``````  lat = lat/180*pi; %converting to radians
long = long/180*pi; %converting to radians
a = 6378137.0; % earth semimajor axis in meters
f = 1/298.257223563; % reciprocal flattening
e2 = 2*f -f^2; % eccentricity squared

chi = sqrt(1-e2*(sin(lat)).^2);
X = (a./chi +h).*cos(lat).*cos(long);
Y = (a./chi +h).*cos(lat).*sin(long);
Z = (a*(1-e2)./chi + h).*sin(lat);
``````

example of latitude/x-axis allocation:

GPSDD(1,1) = 50.682201667 >> XYZmeas(1) = 3976168.03008252

TrueDD(1) = 50.682214 >> XTZtrue(1) = 3975855.46252364

XYZmeas(1) - XTZtrue(1) = 312.567558876704

Did I miss anything or is there any suggestion what would be my mistake?

• it is the Standard NMEA-0183 "National Marine Electronics Association" the way GPS receiver receives the data actually for ex. \$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47 gpsinformation.org/dale/nmea.htm. But generally I used matlab gpx function reader to get the data de.mathworks.com/help/map/ref/gpxread.html – Mour_Ka Sep 14 '18 at 11:38
• Do you use Latitude, Longitude AND height in all your calculations for all of your points? Does your matlab function consider height, or only Latitutde and Longitude? – FSimardGIS Sep 15 '18 at 4:14
• The matlab function is already included in my question and yes it is using height as h. [X Y Z] = llh2XYZ(lat,long,height). GPS doesn't provide height but I made it as 1 meter. – Mour_Ka Sep 15 '18 at 8:01