Lurker News
Hi everyone!

Shortly after publishing my iOS 4 jailbreak last October[1], I got to work on my next hobby project: a from-scratch homebrew GPS receiver, which can solve the user’s location solely from billions of radio antenna samples.
I took a commodity SDR (alongside the Python standard library and numpy) and built a signal processing pipeline that can detect and track GPS satellites over many minutes, drop and pick up satellites as they come in and out of view, and precisely determine the user’s position and clock inaccuracy.
All told, gypsum can go from a cold start to a fix on the user’s position, and the precise time, in less than a minute of listening to the antenna. I went on a journey of learning how to detect and track satellite signals that are literally too quiet to hear, and I hope that some of the magic comes through in the posts!
After implementing this myself and walking the long road of getting it working, I’m left completely stunned by the brilliance of GPS, across so many axes. I hope you enjoy the read!
On a more personal note, I’ll be starting a new job next week which isn’t as amenable to publishing side projects, and therefore this will be my last publicly-published project for some time. I’ve had great experiences making and sharing projects on here, and I’m really grateful for the positive feedback that’s been shared!
[1]: https://news.ycombinator.com/item?id=37736318

Comments (128) 33 threads

Earlier comments
sizzzzlerz2 replies#
Brilliant! I have no idea what the technical background of the author is but for anyone to tease apart the vast, complex, details of the GPS universe is a massive feat. Coupled with his ability to craft software to both assist his analysis and to implement the final solution, he has created a magnificent project. I've been studying GPS and worked with it professionally for a number of years and I still don't know everything about it. I'm looking forward to digging into the code. Kudos to the author!
AlexanderTheGr8#
"Interestingly, the only thing stopping civilians from using the P code is the knowledge of the value of its chipping sequence. If the formula to generate the P code was publicly known, there’d be nothing stopping civilian GPS receivers from locking on to it, with the exact same techniques as are used for the C/A code."

I didn't finish reading the whole thing but was curious. Is there any way of brute forcing it or some other trick to get the chipping sequence to get the P code for more precise GPS?

codyd51#
I am really grateful for this nice comment, thank you! As a self taught programmer with no background in RF or EE, this project was definitely a stretch for me and involved lots of (sometimes frustrating) learning and experimentation. Looking back, I'm really glad for it, as it feels as though I've unlocked RF as a domain that I now understand a lot more tangibly and can use as a sort of tool. It reminds me of the things I love about computers themselves!
tylerchr2 replies#
Super impressive. Can’t agree more with the author that GPS is a stunningly clever engineering achievement.

For those interested in the story of the development of GPS, I found “GPS Declassified” by Richard Easton to be an engaging retelling.

pomian#
a great book to read, much better than you would expect, about Hedy Lamarr, is Richard Rhodes book: "Hedy's Folly."
codyd51#
Thank you very much!
OmarShehata5 replies#
Amazing! I also had exactly the same experience that led me to research this a few years ago, realizing that:

- GPS works even in airplane mode (while on a literal airplane) - It works without cell service, or wifi, or anything - The United States of America controls the GPS constellation, and they can (and have!) turned off GPS off certain regions at will when necessary (which has prompted other countries to launch their own GNSS constellations) - GPS satellites don't send down a location, they only send down time
I think it's a really fun exercise to do this with data you receive on your phone. Your phone has a direct link to satellite.
(side note: I recently learned the basic principles of star navigation, and while it is a completely different mechanism, it also relies very much on keeping accurate time, which I thought was a fun symmetry!)

jeffbee6 replies#
A person would have to have a quite flawed mental model of what GPS is to form the belief that it would stop working without data service, wouldn't they?
outworlder#
Most people have quite flawed mental models of how things work.
nix0n2 replies#
There's a difference between GPS vs A-GPS (Assisted GPS)[0][1].

Since A-GPS uses the cell tower to get the list of satellites in view, the GPS on some cellphones will keep working when cell service is lost but won't start working if cell service is unavailable.
I think this means my Samsung doesn't actually have GPS, since fallback to unassisted GPS has never worked for me (yes, I've tried waiting far longer than 15 minutes).
Maybe you can excuse a mental model that doesn't make the GPS vs A-GPS distinction, since A-GPS is often sold as GPS.
[0]https://en.wikipedia.org/wiki/Assisted_GNSS [1]https://news.ycombinator.com/item?id=40042686

seba_dos1#
> I think this means my Samsung doesn't actually have GPS

Usually this just means that it has a weak antenna or catches too much noise, which isn't as much of an issue when assisted. It will probably work just fine unassisted under perfect conditions, but struggles otherwise. Apparently it's pretty common for modern phones, but there are exceptions.

RF_Savage#
One samsung phone I had problems per software in getting a gps lock in it's last years of use.

Fancier software would sit there forever trying to get lock, but more primitive one's could get a lock and after that the fancier ones could as well.
This meant I got to "boot" the lock by hamgps first and then I could switch to maps and other software.

AnarchismIsCool#
Mostly in the same way the average person would assume "Hacker News" is anything but a place for SV investment bros to hang out and become rabid Libertarians.

Functionally on most devices losing network coverage renders GPS useless. I keep telling people to download OsmAnd if they want to be able to view maps on a plane or get home from their hike outside cell range. Google maps will try to cache maps to some degree nowadays but it tends to be very flakey and it seems to be very easy to accidentally get it to drop its cache when you're outside cell coverage.

myself2482 replies#
One of the interview questions where I work (we do automotive electronics) is "Explain how GPS works." It's directly relevant to the job, but it's also a neat opportunity to see how someone sizes up their audience, manages time and assumptions, etc.

All those things are neat, but mostly what I've learned is that quite a lot of people, otherwise apparently reasonably smart and competent and toting a whole stack of prestigious degrees, have ghastly flaws in their mental model of what GPS is.

jeffbee#
I personally blame the rabid Libertarians that the other guy mentioned. Tons of people think that what GPS does is sends your location to the Air Force, which is a bit backwards (and doesn't pencil out in terms of either energy balance for the mobile station or channel capacity for the satellites). They think this because that's how people casually write about it (the FBI was tracking me over GPS, or whatever).
mikewarot#
If you think that's bad.... try asking someone where they think electricity comes from.
OmarShehata#
absolutely, and most people do! I encourage you to go around asking your friends and family this question (without judgement, and see if you can prod them along to the right answer on their own!) i think the world is better when the average person has a more accurate understanding of the tools they use

(and contrary to popular belief, I think the average person is interested in understanding this, they're more motivated to understand things that actually matter to them, that are in their hands every day. A lot just have an emotional aversion to math due to bad school experiences, but they are genuinely curious)

globalise83#
I can tell you with high confidence that a very large number of people have no mental model of what GPS is at all.
kube-system1 reply#
> - GPS works even in airplane mode (while on a literal airplane) - It works without cell service, or wifi, or anything

Maybe this is a conception that some people have when their first experiences of using GPS was on a smartphone?
But my first couple GPS receivers were standalone devices without any sort of data connection, so it seems obvious to me that GPS doesn't require data.

simplyluke#
A < 30 year old today almost certainly had a modern smartphone with mapping when they learned to drive, entirely skipping the era of garmin and similar GPS devices in cars.

My only exposure to GPS without data came from outdoor sports where GPS watches and PLBs are common, as are offline mapping applications. I don't think it's obvious to most casual users of GPS technology today that it is entirely independent from data connectivity.

duskwuff1 reply#
> GPS satellites don't send down a location, they only send down time

The GPS almanac data they transmit is effectively location. It's not literally location, but the P code isn't literally time either.
> and they can (and have!) turned off GPS off certain regions at will when necessary
As I understand it, those capabilities are no longer present in newer (possibly all active?) GPS satellites.

myself248#
What the satellites are sending is effectively THEIR orbit, not YOUR location, I think is the point.
seba_dos1#
> GPS satellites don't send down a location, they only send down time

They do send a location - to be more exact, they send rough locations of all satellites in the constellation (almanac) and precise location of themselves (ephemeris). Devices like mobile phones, however, usually get that data from other sources because it's much faster than listening to data over GPS.

withinboredom#
> The United States of America controls the GPS constellation

Heh, but they aren't the only global positioning system out there (nor the most accurate). EU, China, India, and Russia all have their own.

wglb#
> Have you ever noticed that your Maps app still works during a flight?

Yes, and I use that to take pictures of features below my as we fly from one place to the other.
If you have a iPhone, when you land, those pictures will be associated with the place you were when the photo was shot. This enables you to locate those curious features you happen to see.

Load more comments