version 1.8.0.0 (3.68 KB) by
Darin Koblick

Transform ECI position, velocity and acceleration to ECEF position, velocity & acceleration.

Convert Pseudo Earth Fixed Inertial Coordinates to ECEF Coordinates. This function has been vectorized for speed.

Example Function Call:

>> [r_ECEF v_ECEF a_ECEF] = ECItoECEF(JD,r_ECI,v_ECI,a_ECI);

Where:

JD is the Julian Date vector [1 x N] (units are in days)

r_ECI is the position vector [3 x N] (any units are permitted)

v_ECI is the velocity vector [3 x N] (any units are permitted)

a_ECI is the acceleration vector [3 x N] (any units are permitted)

Darin Koblick (2021). Convert ECI to ECEF Coordinates (https://www.mathworks.com/matlabcentral/fileexchange/28233-convert-eci-to-ecef-coordinates), MATLAB Central File Exchange. Retrieved .

Created with
R2007b

Compatible with any release

**Inspired by:**
Julian Date to Greenwich Mean Sidereal Time

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!Create scripts with code, output, and formatted text in a single executable document.

Darin KoblickNutation and precession effects are dependent upon your coordinate reference frame assumptions. There are multiple systems classified under ECI such as : true equator, mean equinox (TEME), true of date (TOD), and pseudo earth fixed (PEF). Since this routine does not include nutation about the +Z axis, it's not going to give identical results to those ECI to ECEF conversions using TEME or TOD assumptions. Assume this routine will convert ECI PEF to ECEF.

Haim ShyldkrotHi,

The definition of the ECI coordinates frame given in the documentation is most probably wrong.

It says:

"The x-axis points outward in the Earth's equatorial plane exactly at the Sun. ..."

Since the Earth rotates about the Sun, the Earth centered coordinates frame as defined above has to rotate one revolution per year to follow the the Sun direction which means that ECI is not inertial.

Could someone provide the correct definition of ECI in the Aerospace package? Is it ICRF, J2000, or some other system?

Darin, saying that TEME and TEME are ECEF is wrong. ECEF is fixed to the Earth (a coordinate system in which its topography has no motion) whereas, TEME and TOD are approximate inertial frames.

Yuval PoratHi,

I agree with Manu from Feb 2015 and Drake from 2012.

The simplistic rotation around Z axis is wrong. The effects of nutation and precession should also be included.

Did some one find a solution how to fix this?

Zhenhua JingLuis GarcíaHi,

I'm new using matlab software. Does anybody knows why if i put inputs as 1x3 vector, the programme gives me outputs as 3x3 matrix each one?

DmitriyThe conversion from ECEF to ECI is similar to ECI-ECEF conversion, but transformation matrices should be transposed.

sabari sadoes anyone knows the way to transform ecef to eci?

SulavHello,

Is this program good for converting a vector in ECI frame to a vector in ECEF frame? ( Not a position vector )

An NguyenGraeme RamseyYou can generate the ECI to ECEF 3X3 transformation matrix using the built-in MATLAB command dcmeci2ecef

Xun PanYaguang YangHi Darin,

I ran the program and see the following error message. May I miss something?

Undefined command/function 'bsxfun'.

Error in ==> ECItoECEF>MultiDimMatrixMultiply at 71

C = sum(bsxfun(@times,A,repmat(permute(B',[3 2 1]),[size(A,2) 1 1])),2);

Error in ==> ECItoECEF at 62

r_ECEF = squeeze(MultiDimMatrixMultiply(T3D(THETA),r_ECI));

Error in ==> spacecraft_orbit at 40

[r_ECEF v_ECEF a_ECEF] = ECItoECEF(jdv,rOrbit,vOrbit,aOrbit);

Thanks!

ManuI think the routine is wrong. As mentioned by drake in 2012, there needs to be a precession matrix to go from J2000 to current epoch of ECEF, and that involves a change of the z-axis. The routine computes the new position through a simple rotation around the z-axis. I have compared the results from this routine to conversions using other algorithms (in particular JPL NAIF SPICE routines) and I find differences of ~ 20 km in x, y and z coordinates for times in the year 2015. I am not sure where the differences come from, but the absence of precession is likely the problem.

Darin KoblickChad,

The two code lines you are referencing are trying to find the midnight that occurs before the provided Julian Date.

As written, the first check will be true if the Julian date occurs after midnight and 12+ hours before the time.

As written, the second check will be true if the Julian date occurs after midnight and less than 12 hours before the time.

If both checks are true, the code will use the last midnight that occurred. This is the desired functionality.

Because I am rounding down on the Julian date and subtracting a half day, there is no possible way that jd could be less than jdMin.

-Darin

Chad HawesChad HawesDarin,

In your JD2GMST function, I have a question related to the following two lines:

jd0(jd>jdMin) = jdMin(jd>jdMin);

jd0(jd>jdMax) = jdMax(jd>jdMax);

This appears to be limiting the Julian day between a lower bound and an upper bound. Don't you want the first line to be:

jd0(jd<jdMin) = jdMin(jd<jdMin);

Otherwise, it would appear that no actual lower bounding occurs...

Chad

João CarneiroDarin,

I have been importing some ECI data from the OrbitTools C++ library and have stumbled upon some weird behavior.

In MATLAB I am using your functions to transform ECI to ECEF and then using the MATLAB function, ecef2geodetic to transform into normal azimuth/elevation/height coordinate space.

The weird behavior is that despite having smooth ECI data (smooth as in no jumps in the data) as inputs, I am getting discontinuous ECEF data (graph for r_ECEF(1,:) and r_ECEF(2,:) looks like saw). This is happening for GOES-8 and GOES-15 satellite data.

What is weirder is that on a macro scale (ignoring variations, including the sudden discontinuities), the position of the satellite in the mapa mundi seems to be correct.

Darin KoblickDrake,

J2000 is factored into the ECI to ECEF conversion routine through the call to JD2GAST.m (converts Julian Date to Greenwhich Apparent Sidereal Time). In order to do this, the effects of nutation are considered, and depend on the correct number of Julian centuries since J2000.

drakeDear Darin,

It seems that this code considers the rotaion about Z-axis, or the earth's rotation axis only. However, the most commonly used ECI frame is J2000 which is defined at 1 January 2000, so I believe the effects of precession and nutation should be considered in the conversion between ECI(J2000) and ECEF.

Please let me know your opinion.

Darin KoblickJohan,

You are correct, thank you for spotting that mistake. I should have left everything in degrees since the mean obliquity of the ecliptic is referenced directly in the final computation.

The new parameters for the mean obliquity should be:

EPSILONm = 23.439291-0.0130111.*T - 1.64E-07.*(T.^2) + 5.04E-07.*(T.^3);

This corresponds to the estimates contained in Vallado, Fundamentals of Astrodynamics and Applications, Second edition, (EQ 3-53). 2001.

Thank you again for double checking my work.

JohanThis function is great.

Although i think i found a mistake in your JD2GAST file.

When calculating the EPSILONm shouldn't the first number be 84381.448 and not 84381448 to make sure EPSILONm is calculate in arcseconds.

Shouldn't you convert EPSILONm from arcseconds to degrees like you did with dPSI and dEPSILON?

Darin KoblickThe following ECI coordinate information

rECI = [-2392.11241452386

-17078.1233608647

19945.4195944851];

vECI = [3.27682054057320

-1.79903293168245

-1.11948244495650];

t = 2453937.82777778;

Will yield an ECEF position and velocity of

rECEF = [-15615.6915464865

-7322.85945823539

19943.173494021];

vECEF = [-0.253618011215938

-2.5887912909949

-1.1194824449565];

This was obtained using the routines provided by CelesTrak found from http://www.celestrak.com/software/vallado-sw.asp

The ECItoECEF.m routine I posted on the FileExchange comes very close to this with the following vectors:

rECF = [ -15618.7911316673

-7310.12058163083

19945.4195944851];

vECF = [-0.253618011215938

-2.5887912909949

-1.1194824449565];

The problem is your ECEF position and velocity vectors do not correspond to each other.

A very easy way to check this is to compute the magnitude of your position vectors.

The magnitude of the first ECI position vector you have provided is: 26,366.726420485 km

The magnitude of the ECEF solution should be exactly the same as the magnitude in the ECI reference frame.

The magnitude of your ECEF position vector is 31,124.2960748149 km.

Hopefully this solves your problem.

Muhammad ShaikhI am only posting here first five values of each of the vectors you asked for. They are actually long arrays of more than 1000 values.

GPS XYZ Position in ECI:

-0.239211241452386 -1.707812336086469 1.994541959448508

-0.238883560243254 -1.707992218920763 1.994429990702043

-0.238555873840528 -1.708172064621368 1.994317978585847

-0.238228182457349 -1.708351873071436 1.994205923172916

-0.237900485894857 -1.708531644380220 1.994093824395386

GPS XYZ Velocity in ECI:

3.276820540573197 -1.799032931682451 -1.119482444956503

3.276872512702608 -1.798661610033275 -1.119916159551723

3.276924413465574 -1.798290250160732 -1.120349848764825

3.276976242828717 -1.797918852306742 -1.120783512313681

3.277028000823877 -1.797547416246293 -1.121217150461423

GPS XYZ Position in ECEF:

2.486257771277870 -0.525992080845330 1.796962071713202

2.486219408921021 -0.526173379273422 1.796962071713202

2.486181033343849 -0.526354674903637 1.796962071713202

2.486142644546566 -0.526535967734976 1.796962071713202

2.486104242529370 -0.526717257766510 1.796962071713202

GPS XYZ Velocity in ECEF:

-1.932463623657266 -1.485322200484253 -1.119482444956503

-1.933172003035996 -1.485054282646371 -1.119916159551723

-1.933880318496407 -1.484786276830892 -1.120349848764825

-1.934588569639623 -1.484518183130969 -1.120783512313681

-1.935296756821210 -1.484250001479990 -1.121217150461423

Juliandate Vector:

2.453937827777778

2.453937827789352

2.453937827800926

2.453937827812500

2.453937827824074

Darin KoblickThe MATLAB function juliandate.m should be fine. Can you please post the epoch, the position/velocity vector in ECI coordinates, and your ECF solution?

Muhammad ShaikhThanks Darin for your reply.

I am using matlab function 'juliandate' to convert my time to julian date format. I have searched whether it is a J2000 format but could not find anything on Mathworks page. Can you please help me for this as well.

Darin KoblickCheck to make sure your time vector is in J2000 format, not Unix Time (epoch should be starting 01/01/2000 12:00:00).

Muhammad ShaikhI am having some problems in calculating ECEF data. In my calculations, the satellite positions are calculated at the wrong side of Earth (globe) in the same plan they are now being calculated. Can you guide me for this please? Note, the data I am giving to the function is verified and I can easily say that my calculations can wrong, the data can't be. Please help.

Martin FuchsMaybe something like this but I am not sure ???

if (~isempty(a_ECEF) && (~isempty(r_ECEF)) a_ECI = MultiDimMatrixTranspose(T3D(THETA))*a_ECEF' + 2*MultiDimMatrixTranspose(Tdot3D(THETA,omega_e))*v_ECEF' + MultiDimMatrixTranspose(Tdotdot3D(THETA,omega_e))*r_ECEF'; else a_ECI = []; end

function Tdot = Tdotdot3D(THETA,omega_e)

Tdot = zeros([3 3 length(THETA)]);

Tdot(1,1,:) = -omega_e^2.*cosd(THETA);

Tdot(1,2,:) = -omega_e^2.*sind(THETA);

Tdot(2,1,:) = -Tdot(1,2,:);

Tdot(2,2,:) = Tdot(1,1,:);

Martin FuchsCould you also provide accelerations ?

Syed Zohaib AliHi Darin

Now its working fine. I was passing JD argument in a wrong way.

Thanks

Zohaib

Darin KoblickSyed,

Send me your test case and I will take a look at it.

Thanks,

-Darin

Syed Zohaib AliHi

I am facing problem in converting 1441 values of position and velocity vectors from ECI to ECEF. It seems that function works fine. When 93 out of 1441 values were passed to the function it gave values for x,y & z components which I thought are correct but when 186 out of 1441 values were passed to the function, the initial 93 x & y values were different from the one that I got by passing only 93 values, z components were the same. similarly when more values were passed the x&y were different except the z-component.

can you please guide what could be the problem?

lin yue7ate9Excellent function - fast, and I verified a limited number of test cases. Thank you!

IsmailOk .. now it works fine !

Thanks Darin !

Darin KoblickIsmail,

You are more than likely using the wrong dimensions for r_ECI.

This is specified in my input requirements as [3 x N].

Try:

r_ECI = [10.7148713368681e+003; ...

-7.10368453661470e+003; ...

-22.0702973475812e+003]

In other words, transpose the r_ECI input for the correct answer.

IsmailHello,

Is it normal to obtain six values in the r_ECEF and v_ECEF matrices instead of just 3 ?

** Example **

******************************

r_ECI

10.7148713368681e+003 -7.10368453661470e+003 -22.0702973475812e+003

JD

2.45215900000000e+006

r_ECEF

-7.72362036417280e+003 5.12056195755438e+003 15.9089729291096e+003

-13.0369714274984e+003 8.64317726477505e+003 26.8533169340802e+003

10.7148713368681e+003 -7.10368453661470e+003 -22.0702973475812e+003

v_ECEF

-3.39040857672452e+000 86.2958941276462e-003 1.16863824970067e+000

-3.55490372276425e+000 -1.29159124693780e+000 -2.49278765365527e+000

3.38461399614162e+000 754.648420343670e-003 1.09531334972829e+000

******************************