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?

  • 1
    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, 2018 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, 2018 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, 2018 at 8:01

1 Answer 1


I think the difference here may be caused by a missing height info in one of your points. From what I checked, your coordinates in your example refer to an area at a height of about 500 meters.

If I remove this 500 m height info, I get an offset of 311m in X, 60m in Y and 387m in Z. So this could be a potential explanation for you discrepancy.

  • that was correct once I changed the height to 500 m, the displacements is around 4 meters on latitude, 1 on longitude and 2 meters altitude.
    – Mour_Ka
    Sep 15, 2018 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.