{"id":18266065,"url":"https://github.com/javierantoran/gps-stack-sim","last_synced_at":"2025-08-01T07:45:40.575Z","repository":{"id":115854916,"uuid":"86990993","full_name":"JavierAntoran/gps-stack-sim","owner":"JavierAntoran","description":"Simulation of the full GPS stack, from satellites' transmission to position calculation at receivers","archived":false,"fork":false,"pushed_at":"2019-01-17T11:25:20.000Z","size":6659,"stargazers_count":61,"open_issues_count":3,"forks_count":22,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-04T21:40:21.719Z","etag":null,"topics":["delay","delay-compensation","doppler-compensation","ecef","ephemeris","gold-sequence","gps","gps-library","gps-location","gps-stack","matlab","position-calculation","receiver-position","signal","sv-position","toolkit"],"latest_commit_sha":null,"homepage":"","language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JavierAntoran.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-02T14:19:06.000Z","updated_at":"2025-03-27T18:57:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"52eadf85-fcd6-4eab-a950-45b747f0e7f3","html_url":"https://github.com/JavierAntoran/gps-stack-sim","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JavierAntoran/gps-stack-sim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JavierAntoran%2Fgps-stack-sim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JavierAntoran%2Fgps-stack-sim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JavierAntoran%2Fgps-stack-sim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JavierAntoran%2Fgps-stack-sim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JavierAntoran","download_url":"https://codeload.github.com/JavierAntoran/gps-stack-sim/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JavierAntoran%2Fgps-stack-sim/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264703209,"owners_count":23651919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["delay","delay-compensation","doppler-compensation","ecef","ephemeris","gold-sequence","gps","gps-library","gps-location","gps-stack","matlab","position-calculation","receiver-position","signal","sv-position","toolkit"],"created_at":"2024-11-05T11:21:34.978Z","updated_at":"2025-07-11T01:09:57.641Z","avatar_url":"https://github.com/JavierAntoran.png","language":"MATLAB","readme":"# gps-stack-sim\n\nToolkit which allows for the simulation of GPS C/A code transmission and receiver acquisition and position calculation. \n\nA full listing of provided functions can be found [here](#provided-functions). We include scripts which demonstrate following high level functionality: \n\n* [SV position calculation](#calculating-sv-position-and-visible-sv)\n* [Signal transmission, error/delay compensation and lock on](#signal-transmission-from-sv-receiver-delay-compensation-and-lock-on)\n* [Plotting a trajectory on a map](#plotting-a-trajectory-on-a-map)\n\nThe [scripts/plots_demo.m](https://github.com/JavierAntoran/gps-stack-sim/blob/master/scripts/plots_demo.m) script generates most of the plots included in this README file.\n\nA set of Ephemeris and Almanac files are included in the [files](https://github.com/JavierAntoran/gps-stack-sim/tree/master/files) directory. An explanation of the information included in these files and how to download updated versions is also included.\n\n**Before running, add the /lib folder and sub-folders to the MATLAB path. Also add the /files folder if you want to use the provided world map, Ephemeris files and Almanacs.**\n\n## Calculating SV position and visible SV\n\n[scripts/sv_view.m](https://github.com/JavierAntoran/gps-stack-sim/blob/master/scripts/sv_view.m) reads an Ephemeris file and calculates the position of all Space Vehicles (SVs). It then calculates which ones are visible from a certain point on earth with a certain visibility angle. We provide an [image](https://github.com/JavierAntoran/gps-stack-sim/blob/master/files/land_ocean_ice_2048.png) of the earth's surface which is superimposed on a ellipsoidal model of earth. A valid ephemeris file is required. A vision elevation angle of 30 degrees is assumed in the following image.\n\n\u003cimg src=\"images/vis_sv_angle.png\" width=\"600\" height=\"320\" /\u003e\nIn this example, our receiver is located in Zaragoza, Spain.\n\n## Signal transmission from SV, receiver error/delay compensation and lock on\n\nGiven valid user position (ECEF), almanac and ephemeris files, the [scripts/stack_simulation.m](https://github.com/JavierAntoran/gps-stack-sim/blob/master/scripts/stack_simulation.m) script simulates the C/A code transmission, the channel, the acquisition procedure (warm start) and the receiver's position calculation. This is done using the visible SV from the receiver's position assuming a vision angle of 30 degrees.\n\nC/A codes are transmitted using BPSK at 1575.42 MHz. All operations are done at base band as simulating signals on the L2 band is very resource intensive.\n\n### Transmitted signal\n\nWe generate the Gold codes for every SV and multiply it with a 50 Hz navigation message. The signal is then modulated using BPSK. \n\nWe plot the transmitted signal from SV1 in time. The carrier frequency is 1575.42 MHz. Simulating this signal is very memory intensive. In the following plot, the carrier frequency has been reduced by a factor of 100. \n\u003cimg src=\"images/time_signal.png\" width=\"280\" height=\"200\" /\u003e\n\nIn the frequency domain:\n\n\u003cimg src=\"images/spectral_density.png\" width=\"300\" height=\"200\" /\u003e\n\n### Channel modeling\nWe consider propagation delay, tropospheric delay, ionospheric delay, clock error and delay introduced by relativistic effects. SV1's signal is shown in base band in the following plot before and after passing through the channel. Its autocorrelation and power spectrum density (PSD) are also shown.\n\u003cimg src=\"images/tx_signal.png\" width=\"700\" height=\"280\" /\u003e\n\n\n### Acquisition and position recovery\n\nThe receiver starts of by searching for visible SV. This is done through a C/A code search in time and phase. The latter is necessary due to Doppler shift. The search procedure is done by correlation:\n\u003cimg src=\"images/code_phase_search.png\" width=\"400\" height=\"240\" /\u003e\n\nTracking is done with a delay lock loop (DLL) / phase lock loop (PLL) (Not implemented).  \n\nOnce SV have been found, clock correction is applied to compensate for relativistic effects and receiver position is recovered using least squares. Since tropospheric and ionospheric delays depend on receiver position, this operation is done iteratively. Dilution of precision (DOP) values are calculated.\n\nThe following plot shows the convergence of receiver position and pseudoranges from the receiver to each SV.\n\u003cimg src=\"images/xyz_sv_acq.png\" width=\"600\" height=\"220\" /\u003e\n\nThe following plot shows the convergence of the calculated value for each of the sources of error we model.\n\u003cimg src=\"images/errors_SV.png\" width=\"300\" height=\"220\" /\u003e\n\n\n\n## Plotting a trajectory on a map\n\nThe script [CSVmap.m](https://github.com/JavierAntoran/gps-stack-sim/blob/master/maps/CSVmap.m) plots a trajectory, given as ECEF (x, y, z) coordinates, on a map in ETRS89 UTM coordinates. The following files are required but not provided: A .csv file with the trajectory, a map file in any format and a corresponding .tfw file.\n\n\u003cimg src=\"images/trajectory.png\" width=\"300\" height=\"220\" /\u003e\n\n## Provided functions\n\nAll functions can be found under the [/lib](https://github.com/JavierAntoran/gps-stack-sim/tree/master/lib) directory. It contains the following subdirectories with the following functions. \n\n*Note that this README is a work in progress and not all subdirectories and functions are listed.*\n\n### GEO\n\n[ enu ] = ecef2enu( xyz, tmat ) % Convert Earth-centered Earth-Fixed to Local east, north, up (ENU)\n\n[ azel ] = enu2azel( enu ) % Convert Eeast-North-Up to Azimuth + Elevation\n\n[x, y, z] = lla2xyz( fi, lambda, h, a, e2 ) % Convert geodetic latitude, longitude, altitude (LLA) coordinates to XYZ\n\n[ lat, lon, alt ] = xyz2lla( x, y, z, a, e2 ) % Vonvert earth-centered earth-fixed (ECEF) cartesian coordinates to latitude, longitude, and altitude\n\n[ t ] = ltcmat( llh ) % Compute the intermediate matrix for LLH to ECEF\n\n[ dist ] = ECEFrange( SVx, SVy, SVz, gx, gy, gz ) % Calculates distance between observer and SV\n\n### RINEX\n\n[EPH ,header] = read_rinex_nav( filename, sv_IDs) % Reads an ephemerides file and get the information of the requested space vehicles.\n\n[ gps_week, gps_seconds ] = cal2gpstime(varargin) % Calculates GPS seconds from UTC\n\n[ dt ] = gpst2utc( week_number, reference_time, leap_seconds ) % Calculates UTC from GPS seconds\n\n[sat_xyz, orbit_parameters] = eph2ecef(eph ,tsv) % Compute sv orbits and sv position in ECEF for the specified time (tsv) from ephemerides\n\n### TC Lib\n\n[sCA] = CA_gen(pulseLength, SV_vec) % Generates C/A codes for all SVs\n\n[ modulator ] = generate_doppler( f_vec, L ) % generates a matrix to shift CA codes in frequency\n\n[delay_CA, cicles, prop_delay, sat_clock_offset, sat_clock_rel, iono_T, trop_T_equiv] = gps_channel(head, eph, time, Rpos, sCA, L) % Get TX channel including tropo, iono, clock error and relativistic clock\n\n### OTHERS\n\n[ vis_sv ] = visible_sv( satp, rcv_lla, e_mask ) % Search for visible SV given an observation position and elevation\n\n[ f ] = plot_orbits( sat_xyz, orbit_parameters, earth_surface_image, varargin) % Plots SV orbits around the globe\n\n\n## Resources \n\n* Some of our functions use code from the **GPS Navigation Toolbox** by Moein Mehrtash https://es.mathworks.com/matlabcentral/fileexchange/41364-gps-navigation-toolbox?focused=3785211\u0026tab=function\n* We use the **Convert Cartesian (ECEF) Coordinates to to lat, lon, alt** script by Michael Kleder https://es.mathworks.com/matlabcentral/fileexchange/7941-convert-cartesian-ecef-coordinates-to-lat-lon-alt \n* Compilation of GPS toolboxes: https://www.ngs.noaa.gov/gps-toolbox/\n\n----------------------------------------------\n\n* GPS Almanacs can be obtained from: https://www.navcen.uscg.gov/?pageName=gpsAlmanacs \n* GPS Ephemeris data can be downloaded from: https://cddis.nasa.gov/Data_and_Derived_Products/GNSS/broadcast_ephemeris_data.html#GPShourly \n\n----------------------------------------------\n* Many functions were based on this book: Global Positioning System: Theory and Applications, edited by B.Parkinson,J.Spilker\n* Very useful slides on GPS by MIT ocw: https://ocw.mit.edu/courses/earth-atmospheric-and-planetary-sciences/12-540-principles-of-the-global-positioning-system-spring-2012/lecture-notes/MIT12_540S12_lec7.pdf\n* More information on coordinate systems: http://www.dirsig.org/docs/new/coordinates.html\n\n----------------------------------------------\n\n* Ionospheric model we use: KLOBUCHAR, Ionospheric Time-Delay Algorithm for Single-Frequency GPS Users (1987), https://ieeexplore.ieee.org/document/4104345?section=abstract \n* Tropospheric model: H. S. Hopfield Two-quartic tropospheric refractivity profile for correcting satellite data (1969) https://agupubs.onlinelibrary.wiley.com/doi/abs/10.1029/JC074i018p04487\n* Iterative LS for solving 4d positioning equation: Yuheng He, Approximate Iterative Least Squares Algorithms for GPS Positioning (2010) https://www.computer.org/csdl/proceedings/isspit/2010/9992/00/05711784.pdf  \n----------------------------------------------\n\n* It turns out that if you code something similar to this project in C you can spoof real GPS receivers 😁: https://github.com/osqzss/gps-sdr-sim\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavierantoran%2Fgps-stack-sim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjavierantoran%2Fgps-stack-sim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavierantoran%2Fgps-stack-sim/lists"}