Main Content

Ship Tracking Using AIS Signals

This example shows you how to track ships by processing Automatic Identification System (AIS) signals using MATLAB® and Communications Toolbox™. You can either use captured signals or receive signals in real time using the RTL-SDR Radio. The example can show the tracked ships on a map, if you have the Mapping Toolbox™.

Required Hardware and Software

To run this example using captured signals, you need the Communications Toolbox™.

To receive signals in real time, you also need an RTL-SDR radio and the corresponding Communications Toolbox Support Package for RTL-SDR Radio support package Add-On.

For a full list of Communications Toolbox supported SDR platforms, refer to Supported Hardware section of Software Defined Radio (SDR) discovery page.


In marine transportation, vessel traffic services use AIS as a component of the overall marine traffic monitoring system. AIS performs the following functions:

  • Transmit vessel identifier, position, course, and speed.

  • Receive and process specified interrogating calls.

  • Operate continuously while under way or at anchor.

Specifications of AIS:

  • Transmit Frequency Range: 156.025 MHz-162.025 MHz

  • Modulation Scheme: Gaussian frequency shift keying

  • Bit Rate: 9600 bits/sec

  • Transmit Bandwidth Time Product: 0.4

  • Receive Bandwidth Time Product: 0.5

  • Modulation Index: 0.5

AIS transmission packets contain these fields:

  • Training Sequence: 24-bit sequence of alternating zeros and ones (0101...).

  • Start Flag: 8-bit sequence, 01111110.

  • Data: The data portion is 168 bits long in the default transmission packet.

  • Frame Check Sequence(FCS): Uses the cyclic redundancy check (CRC) 16-bit polynomial to calculate the checksum.

  • End Flag: Identical to the start flag.

  • Buffer: The buffer is normally 24 bits long to account for bit stuffing (maximum 4 bits), distance delay (14 bits) and synchronization jitter (6 bits).

This figure shows the AIS packet format

Run the Example

You can open the example by selecting the Open script button. The default configuration runs for a duration of 10 seconds, uses signal data from a captured data file, and outputs to a text file. To provide input values from the command line, you must change cmdlineInput to 1, then you will be prompted to enter the following information when you run the example:

  1. Reception duration in seconds,

  2. Signal source (Captured data file or RTL-SDR radio),

  3. Optional output methods (map, text file, or both).

The example shows the information on the detected ships in a tabular form as shown in the following figure.

If you have the Mapping Toolbox licensed, you can also observe AIS tracking of ships on a map.

Receiver Structure

The following block diagram summarizes the receiver code structure. The processing has three main parts: Signal Source, Physical Layer and Data Viewer.

Signal Source

Specify the signal source as "File" or "RTL-SDR".

  1. ''File'': Uses the comm.BasebandFileReader to read a file that contains a previous signal captured over-the-air.

  2. ''RTL-SDR'': Uses the RTL-SDR radio to receive a live signal.

The code uses a signal symbol rate of 9600 Hz and 24 samples per symbol.

If you assign ''RTL-SDR'' as the signal source, the example searches your computer for the RTL-SDR radio at radio address '0' and uses it as the signal source.

Physical Layer

The baseband samples received from the signal source are processed by the physical layer (PHY) to produce packets that contain the ship position information and raw message bytes. This figure shows the PHY processing components.

  • Packet Search: Searches for the strongest burst in the received signal by dividing into multiple windows.

  • DC Offset Removal: Removes DC offset from the detected signal.

  • Frequency Compensation: Estimates and compensates for the carrier frequency offset.

  • Matched Filtering: Performs filtering with Gaussian pulse generated as per AIS specifications.

  • Synchronization and Demodulation: Performs timing synchronization by correlating the received signal with known preamble and demodulates to produce bits.

  • AIS Bit Parser: Detects the Start Flag and End Flags, then performs CRC detection. If CRC is successful, then the ship information is decoded.

There are 64 specific message types in AIS. Ship position information is included in 11 of the message types. This example decodes all 11 of the message types that contain position information.

As seen in the earlier figure, ship ID, latitude, longitude, date, and time are displayed by this example. Messages contain additional information that can be decoded as described in [ 1 ].

Data Viewer

The data viewer shows the received messages on a graphical user interface (GUI). As data is captured, the application lists information decoded from these messages in a tabular form.

Example Code

The example steps are described below. To see the detailed operations look at the code run in the helper functions called by the example. For the option to change default settings, set cmdlineInput to 1.

cmdlineInput = 0;
if cmdlineInput
    % Request user input from the command-line for application parameters
    userInput = helperAISUserInput;
% Calculate AIS parameters based on the user input
[aisParam,sigSrc] = helperAISConfig(userInput);

% Create the data viewer object and configure based on user input
viewer = helperAISViewer('LogFileName',userInput.LogFilename, ...

% Launch map based on user input
if userInput.LaunchMap

% Log data based on user input
if userInput.LogData

% Start the viewer and initialize radio time
radioTime = 0;

% Main loop for capturing and decoding the AIS samples
while radioTime < userInput.Duration
    if aisParam.isSourceRadio       % For RTL-SDR
        [rcv,~,lost,~] = sigSrc();
        lostFlag = logical(lost);
    else                            % For baseband file
        rcv = sigSrc();
        lostFlag = uint32(0);

    % Recover the information by decoding AIS samples
    [info, pkt] = helperAISRxPhy(rcv,aisParam);

    % View decoded information on viewer
    update(viewer, info, pkt, lostFlag);

    % Update radio time
    radioTime = radioTime + aisParam.FrameDuration;

% Stop the viewer and release the signal source

Further Exploration

You can also type AISExampleApp in the MATLAB Command Window or click the link to use the AISExampleApp user interface to explore AIS signals. The app interface allows you to select the signal source and change the duration.

You can explore following functions and System objects for details of the physical layer implementation:

Selected Bibliography

  1. Recommendation ITU-R M.1371-5, Technical characteristics for an automatic identification system using time division multiple access in the VHF maritime mobile frequency band.