MATLAB Code (GPS and Galileo Receiver) Part 1

Structure of the Code

The generic one-channel receiver is shown in Figure 5.1. The actual data flow and the MATLAB functions used by the software receiver are depicted in Figure A.1.

Below we mention a short description of the single structures of the receiver and the variables that conduct the behavior of the software receiver.

First, a small section (few ms) at the start of the data file is read and is passed to the acquisition M-file. The acquisition M-file looks for any presence of GPS signals. It estimates the frequency and the C/A code phase for every present GPS signal. The results are stored in the structure acqResults.

Next, the function preRun reads the acquisition results and initializes all software channels. If the number of available satellites is less than the number of channels, the unused channels are disabled. The same function also clears all processing results from possible previous runs. Thus, it prepares a clean environment for the following run.

After initialization of channels, a block of signal samples is read from the recorded file and is passed to the tracking function track. The tracking function tracks signals for all enabled channels, detects bit boundaries, stores bits of the navigation data, and decodes the data. Decoded ephemerides are stored in the structure eph. Tracking results (outputs from correlators, discriminators, etc.) are stored in the structure trackResults. In settings one may specify for how long the tracking should proceed.


After the tracking is finished, the function postNavigation is launched to process the signal. It identifies the start of a subframe, determines the signal trans-mission time, and estimates all pseudoranges.

GNSS software receiver flow diagram.

FIGURE A.1. GNSS software receiver flow diagram.

Then the M-file computes ECEF coordinates of the software antenna and the ECEF coordinates are converted to a specified coordinate system, say UTM or WGS84. Finally, the results of acquisition, tracking, and positioning are plotted.

The settings Structure

All variables common to all receiver blocks, and block-specific variables are stored in one structure named settings. This approach enables a centralized and flexible management of the software. For instance, sampling frequency-based parameters are used by many files—from acquisition to pseudorange computation. Once the parameters are updated in the variable settings, all files will use the changed values.

One more advantage is that the function parameter list does not depend on how many parameters the function actually is using. Changes inside the function will not affect the calling function code. The most commonly used variables are

IFfrequency Intermediate frequency of the GPS signal, Hz

samplingFrequency Frequency at which the GPS signal is sampled, Hz

msToProcess This variable is set to 37,000 to ensure all five 6-s subframes are processed and included in the output, the first 1000 ms can be excluded for any transient response

processBlockSize Size of the block to be processed by the tracking function

numberOfChannels Sets the number of channels of the software receiver.

The function init Settings creates the structure settings. The very first time this function is executed by the script init. The function should be executed every time variables are changed. An experienced user might change some of the variables directly in the settings structure. However, care must be taken as some variables have internal dependencies and are recomputed automatically. So it is safest to change variables in the function init Settings, which must be re-executed afterward.

The block-dependent variables are described in the following sections.

Acquisition Function

The function acquisition employs the parallel code phase search acquisition algorithm described in Section 6.4. The purpose is to find signal parameters for all available satellites in a few-ms-long data record. The implementation is based on the block diagram shown in Figure 6.8. The flow diagram for the actual code is shown in Figure A.2.

The acquisition function looks for a GPS signal in frequency steps of 0.5 kHz. For each frequency step, a parallel code search is performed. The correlation results are saved and the function proceeds with the next frequency step. Thus, the function steps through all frequency bands (user-defined Doppler space). Next the function looks for a maximum correlation value (correlation peak) in results from all frequency bins. After the peak is detected, the function looks for the second-highest correlation peak in the same frequency bin of the highest peak. Then the ratio of the two peaks is used for the signal detection rule. The ratio is compared to the value preset in the receiver variable acq_threshold.

The detector does not depend on sampling frequency and therefore is not dependent on the size of peak and noise level.

 Flow diagram of the parallel code phase acquisition algorithm.

FIGURE A.2. Flow diagram of the parallel code phase acquisition algorithm.

If the value of the peak ratio is larger than a specified value, the fine carrier frequency is found via a postcorrelation FFT approach. This must be done to help the PLL in the tracking loop to start tracking the signal. A frequency accuracy of 0.5 kHz is too coarse for the PPL to start tracking.

The function parameters are an initial data record, a table with pregenerated C/A codes, and the settings structure. The list of acquisition-specific variables contained in the structure settings is acq_satelliteList A set of satellite PRNs can be specified. Acquisition will be performed only for the specified satellites. An empty list (default) starts a search for all available satellites 1-32.

GNSS tracking flow diagram.

FIGURE A.3. GNSS tracking flow diagram.

acq_searchBand Specifies the frequency band in which to search for satellite signals, kHz integer. It is centered around the IF. While searching for available signals the acquisition function uses steps of 0.5 kHz.

acq_threshold Determines the threshold of the signal detector.

The output is an array structure acqResults containing search results for all satellites specified in acq_satelliteList. If a satellite signal is detected, the field signalDetected is set to 1 for that particular satellite.

Next post:

Previous post: