SUMO Simulation with Ray Tracing

Introduction

This tutorial demonstrates how to create a realistic vehicular network simulation from real-world maps, perfect for wireless communication researchers who need accurate mobility patterns and propagation environments. We’ll combine:

  • 🚗 SUMO (Simulation of Urban MObility) for vehicle movement generation
  • 📡 Real-world base station data from OpenCellID
  • 📶 MATLAB Ray Tracing (RT) for wireless channel modeling

By the end of this tutorial, you’ll have an elegant simulation environment that accurately models both vehicular mobility and wireless propagation in urban scenarios. The result is a powerful alternative to commercial tools like Wireless InSite, with the flexibility of script-based automation.

MATLAB ray tracing view
Power heat map based on RT results

💡 A word from Chi: The script execution speed slows down drastically as the number of vehicles and base stations (BS) increases. Save your data periodically to avoid losing hours of computation time! Trust me, I learned this the hard way. ☕


Step 1: Setting Up SUMO with OpenStreetMap

SUMO naturally supports loading real-world maps from OpenStreetMap (OSM). Let’s get started:

1.1 Export Your Map Area

  1. Navigate to OpenStreetMap
  2. Click “Export” in the top menu
  3. Click “Manually select a different area” to draw your region of interest
    • Alternatively, input specific longitude and latitude coordinates
  4. Download the .osm file and save it to your workspace
  5. (Optional) If the map looks messy, download JOSM to clean and edit the OSM data

1.2 Install SUMO

If you haven’t installed SUMO yet, follow the official installation guide for your operating system.

Want different vehicle types in your simulation? Create a vehicle type distribution file (*.add.vtype.xml) following the 3GPP TR 37.885 evaluation scenario [1]:

<additional>
    <vTypeDistribution id="typedist1">
        <vType id="vType1" vClass="passenger" length="5" width="2" height="0.75" 
               guiShape="passenger" probability="0.2"/>
        <vType id="vType2" vClass="passenger" length="5" width="2" height="1.6" 
               guiShape="passenger" probability="0.6"/>
        <vType id="vType3" vClass="bus" length="13" width="2.6" height="3" 
               guiShape="bus" probability="0.2"/>
    </vTypeDistribution>
</additional>

This distribution includes:

  • 20% small vehicles (sedan-like, height 0.75m)
  • 60% standard vehicles (SUV-like, height 1.6m)
  • 20% buses (height 3m)

1.4 Generate Network and Traffic

Use the following commands to convert your OSM file and generate vehicle routes:

Convert OSM to SUMO network:

netconvert --osm-files *.osm --output-file *.net.xml \
           --geometry.remove --roundabouts.guess --ramps.guess \
           --junctions.join --tls.join

Parameters explained:

  • --geometry.remove: Simplifies road geometry for faster simulation
  • --roundabouts.guess: Automatically detects and models roundabouts
  • --ramps.guess: Identifies highway on/off ramps
  • --junctions.join: Merges close intersections
  • --tls.join: Groups nearby traffic lights

Generate random vehicle trips:

randomTrips.py -n *.net.xml -e 50 -o *.trips.xml -r *.rou.xml \
               --period 0.2 --additional-file *.add.vtype.xml \
               --fringe-factor 100 \
               --trip-attributes="type=\"typedist1\""

Parameters explained:

  • -e 50: Simulation end time (50 seconds)
  • --period 0.2: Average time between vehicle departures (0.2s = high density)
  • --fringe-factor 100: Prefers trips starting/ending at network edges (more realistic)
  • --trip-attributes: Assigns vehicle types from your distribution

1.5 Create SUMO Configuration

sumo -n *.net.xml -r *.rou.xml --save-configuration *.sumocfg \
     --step-length 0.1 --begin 0 --end 3600

Parameters explained:

  • --step-length 0.1: Simulation time step (0.1s for smooth movement)
  • --begin 0 --end 3600: Simulate for 1 hour (3600 seconds)

1.6 Verify Your Simulation

Launch SUMO GUI to visualize and verify your simulation:

sumo-gui -c *.sumocfg

Press the ▶️ play button and watch your vehicles navigate the city! If everything looks good and you don’t need wireless simulation, congratulations—you’re done! 🎉


Step 2: Extracting Vehicle Positions for MATLAB

To perform ray tracing in MATLAB, we need vehicle positions as receiver locations. SUMO’s Floating Car Data (FCD) output provides exactly that.

2.1 Generate Position Trace

For geographic coordinates (latitude/longitude):

sumo -c *.sumocfg --fcd-output sumoTrace.xml --fcd-output.geo true

For Cartesian coordinates (x, y):

sumo -c *.sumocfg --fcd-output sumoTrace.xml

💡 For ray tracing with real-world maps, use geographic coordinates (--fcd-output.geo true)

2.2 Understanding the Output Format

Your sumoTrace.xml will look like this:

<?xml version="1.0" encoding="UTF-8"?>
<fcd-export xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/fcd_file.xsd">
    <timestep time="0.00">
        <vehicle id="0" x="139.708676" y="35.644965" angle="319.62" 
                 type="3" speed="0.00" pos="13.10" lane="186794816#0_0" slope="0.00"/>
    </timestep>
    <timestep time="0.10">
        <vehicle id="0" x="139.708676" y="35.644965" angle="319.62" 
                 type="3" speed="0.11" pos="13.11" lane="186794816#0_0" slope="0.00"/>
        <vehicle id="1" x="139.692325" y="35.647848" angle="116.45" 
                 type="3" speed="0.00" pos="13.10" lane="-59075772#4_0" slope="0.00"/>
    </timestep>
</fcd-export>

2.3 Parse XML in MATLAB

Now you need to extract vehicle positions from this XML file. Here’s a starting point using MATLAB’s XML parser:

% Read the FCD XML file
tree = xmlread('sumoTrace.xml');
timesteps = tree.getElementsByTagName('timestep');

% Extract positions for each timestep
for i = 0:timesteps.getLength-1
    timestep = timesteps.item(i);
    time = str2double(timestep.getAttribute('time'));
    
    vehicles = timestep.getElementsByTagName('vehicle');
    for j = 0:vehicles.getLength-1
        vehicle = vehicles.item(j);
        vehID = char(vehicle.getAttribute('id'));
        lon = str2double(vehicle.getAttribute('x'));
        lat = str2double(vehicle.getAttribute('y'));
        
        % Store positions for ray tracing
        vpos(str2num(vehID)+1, :, i+1) = [lat, lon];
    end
end

save('vpos.mat', 'vpos');

Step 3: Adding Real-World Base Stations

Let’s place realistic base station (BS) locations using real cellular network data from OpenCellID [2].

3.1 Download Cell Tower Data

  1. Visit OpenCellID Statistics
  2. Click “STAT” in the navigation bar
  3. Enter your country name
  4. Download the CSV file (note: this contains nationwide data, so it’s a large file)

3.2 Filter Base Stations by Geographic Range

Use this MATLAB script to extract BS positions within your simulation area:

clear;
clc;

csv_file = 'opencellid.csv';
% Define your geographic bounding box [lat_min, lon_min, lat_max, lon_max]
% Get these values from your OSM export
range = [35.64537, 139.69228, 35.65719, 139.71022];

bs = bs_pos(csv_file, range);
save('bs.mat', 'bs');

function filtered_data = bs_pos(csv_file, range)
    lat_min = range(1); 
    lon_min = range(2);
    lat_max = range(3); 
    lon_max = range(4);

    % Read the CSV file
    data = readmatrix(csv_file);

    % Extract longitude (column 7) and latitude (column 8)
    longitude = data(:, 7);
    latitude = data(:, 8);

    % Filter data within the specified region
    region_filter = (longitude >= lon_min & longitude <= lon_max) & ...
                    (latitude >= lat_min & latitude <= lat_max);
                
    % Return filtered longitude and latitude
    filtered_data = data(region_filter, 7:8);
end

Step 4: Ray Tracing in MATLAB

Now comes the exciting part—combining everything into a realistic wireless channel simulation!

4.1 Understanding CDL Channel Models

The Clustered Delay Line (CDL) model is a standardized channel model defined by 3GPP for 5G New Radio (NR) systems. It’s excellent for vehicular networks because:

  • Captures realistic multipath propagation in urban environments
  • Models time-varying channels for moving vehicles
  • Supports massive MIMO and beamforming scenarios
  • Validated against extensive measurement campaigns

MATLAB’s ray tracing can customize CDL parameters based on site-specific geometry, giving you the best of both worlds: standardized models with real-world accuracy.

4.2 Set Up Transmitters and Receivers

Follow MATLAB’s CDL Channel Model Customization with Ray Tracing example, but modify it for multiple vehicles and base stations:

% Load positions from previous steps
load(fullfile(loading, 'vpos.mat'));   % Vehicle positions from Step 2
load(fullfile(loading, 'bspos.mat'));  % BS positions from Step 3

% Prepare position arrays
% Note: Check if your data is [lon, lat] or [lat, lon] and adjust accordingly
bsPosition = [bspos(:,2), bspos(:,1)];  % [latitude, longitude]
uePosition = [vpos(:,2), vpos(:,1)];    % [latitude, longitude]

% Create base station sites
bsSite = txsite("Name", "Base station", ...
    "Latitude", bsPosition(:,1), ...
    "Longitude", bsPosition(:,2), ...
    "AntennaAngle", bsArrayOrientation(1:2), ...
    "AntennaHeight", rsu_height, ...  % e.g., 25 meters
    "TransmitterFrequency", fc);      % e.g., 3.5 GHz

% Create vehicle (UE) receiver sites  
ueSite = rxsite("Name", "UE", ...
    "Latitude", uePosition(:,1), ...
    "Longitude", uePosition(:,2), ...
    "AntennaHeight", ueHeight', ...   % e.g., 1.5 meters
    "AntennaAngle", ueArrayOrientation(1:2));

4.3 Visualize Your Setup

Before running the full simulation, verify everything looks correct:

% Initialize or clear site viewer
if exist('viewer','var') && isvalid(viewer)
    clearMap(viewer);
else
    viewer = siteviewer("Basemap", "openstreetmap", ...
                        "Buildings", fullfile(loading,'*.osm'));
end

% Display base stations
show(bsSite);

% Display vehicles
show(ueSite);

% Compute and visualize ray tracing for a specific BS-UE pair
rays = raytrace(bsSite(1), ueSite(1), propModel);
plot(rays{1,1});  % Show propagation paths

Conclusion

This tutorial shows a powerful workflow for realistic vehicular network simulation by combining:

  1. 🗺️ Real-world maps and road networks (OSM + SUMO)
  2. 🚗 Realistic vehicle mobility patterns (SUMO traffic simulation)
  3. 📡 Actual cellular infrastructure locations (OpenCellID)
  4. 📶 Site-specific propagation modeling (MATLAB ray tracing)

Compared to commercial tools like Wireless InSite, this approach offers:

  • Better scripting flexibility for large-scale parametric studies
  • Easy integration with existing MATLAB/Simulink workflows
  • Cost-effective using open-source tools
  • Reproducible results with version-controlled scripts

The main limitation is computational cost—ray tracing scales poorly with the number of links. For large-scale simulations (hundreds of vehicles × dozens of BSs), consider:

  • Using simplified propagation models for initial filtering
  • Parallelizing ray tracing computations across multiple cores
  • Caching results from time to time

Special thanks to my co-worker who introduced me to this method. It has become my go-to approach for vehicular network research! 🚀


References

[1] 3GPP, “Study on Evaluation Methodology of New Vehicle-to-Everything (V2X) Use Cases for LTE and NR,” 3rd Generation Partnership Project (3GPP), Technical Report TR 37.885, Version 15.3.0, Release 15, June 2019.

[2] OpenCellID, “The World’s Largest Open Database of Cell Towers,” https://opencellid.org, Accessed: 2024.




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • UCB Under Gradual Distribution Decay
  • UCB Under Non-stochastic Enviroment
  • UCB Exploration in Sparse Rewarded Bandits
  • MAB: A Introduction