Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Error in calculating the Doppler Factor #128

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"bugs": {
"url": "https://github.com/shashwatak/satellite-js/issues"
},
"dependencies": {},
"devDependencies": {
"@babel/cli": "^7.20.7",
"@babel/core": "^7.20.12",
Expand All @@ -60,7 +59,7 @@
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"glob": "^8.0.3",
"jest": "^29.3.1",
"jest": "^29.7.0",
"prepend-file": "^2.0.1",
"raise-version": "^0.5.0",
"rimraf": "^3.0.2",
Expand Down
16 changes: 8 additions & 8 deletions src/dopplerFactor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default function dopplerFactor(location, position, velocity) {
const mfactor = 7.292115E-5;
const earthRotation = 7.292115E-5;
const c = 299792.458; // Speed of light in km/s

const range = {
Expand All @@ -10,16 +10,16 @@ export default function dopplerFactor(location, position, velocity) {
range.w = Math.sqrt(range.x ** 2 + range.y ** 2 + range.z ** 2);

const rangeVel = {
x: velocity.x + mfactor * location.y,
y: velocity.y - mfactor * location.x,
x: velocity.x + earthRotation * location.y,
y: velocity.y - earthRotation * location.x,
z: velocity.z,
};

function sign(value) {
return value >= 0 ? 1 : -1;
}

const rangeRate = (range.x * rangeVel.x + range.y * rangeVel.y + range.z * rangeVel.z) / range.w;

return (1 + (rangeRate / c) * sign(rangeRate));
// Negative range rate means the satellite is moving towards the observer and
// its frequency is shifted higher because 1 minus a negative range rate is
// positive. If the range rate is positive, the satellite is moving away from
// the observer and its frequency is shifted lower.
return 1 - rangeRate / c;
}
3 changes: 2 additions & 1 deletion test/dopplerFactor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('Doppler factor', () => {
expect(dopFactor).toBeCloseTo(1, numDigits);
});

// Object moving away from observer
it('special case', () => {
const observerEcf = {
x: earthRadius,
Expand All @@ -65,7 +66,7 @@ describe('Doppler factor', () => {
z: 0,
};
const dopFactor = dopplerFactor(observerEcf, positionEcf, velocityEcf);
expect(dopFactor).toBeCloseTo(1.0000107847789212, numDigits);
expect(dopFactor).toBeCloseTo(0.9999892152210788, numDigits);
});

it('calculated from a negative range rate', () => {
Expand Down