Export trackingArchitecture
to Simulink
This example shows how to define a trackingArchitecture
object and export it to Simulink.
Introduction
In this example, you create an architecture that includes multiple detection-level multi-object trackers and a track fuser. You create an architecture using the trackingArchitecture
object in MATLAB and, export it to a Subsystem (Simulink) in a Simulink model using the exportToSimulink
object function of the trackingArchitecture
object. You connect the architecture to a tracking scenario, execute the tracking architecture, and evaluate the tracking performance using the trackOSPAMetric
block in Simulink.
Create architecture and export it to Simulink
You create a tracking architecture that has two trackers and a track-to-track fuser. The first tracker accepts detections from a single sensor. The second tracker accepts detections from two sensors. The architecture also has a track fuser to fuse tracks from both trackers and output the fused tracks. You implement the first and second trackers using the trackerGNN
and trackerJPDA
objects respectively. You implement the track-to-track fuser using the trackFuser
object.
% Define tracking architecture. ta = trackingArchitecture(ArchitectureName="TrackingSystem"); % Create a sensor-level tracker. sensorTracker = trackerGNN(TrackerIndex=1, ... FilterInitializationFcn=@initcvekf, ... AssignmentThreshold=50, ... ConfirmationThreshold=[2 3], ... DeletionThreshold=[5,5]); addTracker(ta,sensorTracker,SensorIndices=1,ToOutput=false,Name="Sensor Tracker"); % Create another tracker that accepts detections from two sensors. tracker = trackerJPDA(TrackerIndex=2, ... AssignmentThreshold=50, ... ConfirmationThreshold=[2 3], ... TrackLogic="History"); addTracker(ta,tracker,SensorIndices=[2,3],ToOutput=false,Name="Tracker"); % Define the track fuser. fuser = trackFuser(FuserIndex=3, ... % Identify fuser. MaxNumSources=2, ... StateFusion="Cross"); % Fuser accepts tracks from 2 sources. addTrackFuser(ta,fuser,Name="Track Fuser");
Display the summary of the architecture.
summary(ta)
ans=3×4 table
System ArchitectureInputs FuserInputs ArchitectureOutput
_____________________ __________________ __________________ __________________
{'T1:Sensor Tracker'} {'1' } {'Not applicable'} {0x0 double}
{'T2:Tracker' } {'2 3' } {'Not applicable'} {0x0 double}
{'F3:Track Fuser' } {0x0 char} {'1 2' } {[ 1]}
Visualize the architecture in a MATLAB figure.
show(ta); f = gcf; f.Position = [680 153 915 825];
Export the architecture to Simulink.
model = exportToSimulink(ta);
The exportToSimulink
object function exports trackingArchitecture
as a Subsystem (Simulink) in Simulink. The subsystem has input ports for each architecture input and prediction time, as well as an output port for the architecture output.
You can open the exported subsystem by double-clicking it and visualize the contained blocks. For each tracker or track fuser in the architecture, the subsystem contains an equivalent block. The block parameters are also configured equivalently as the properties of the tracker or track fuser object. Notice that the subsystem contains two additional blocks: the Detection Concatenation block and the Track Concatenation block. A Detection Concatenation block is required when a tracker has more than one input source. Similarly, a Track Concatenation block is required when a track fuser has more than one input source. Once exported, the model becomes independent from the trackingArchitecture
object.
You can connect inputs to the tracking architecture subsystem and simulate the model to run the architecture. You use the helperSetupArchitectureModel f
unction to connect the inputs to the architecture and configure the rest of the model.
helperSetupArchitectureModel(ta,model)
In the configured model, the Tracking Scenario Reader block reads a trackingScenario
object from the MATLAB workspace and generates simulation data in Simulink.
Note that the block generates detections from all the sensors present in the scenario in a single Simulink Bus Capabilities (Simulink), while the architecture subsystem requires a detection bus input from each sensor separately. You use a helper block, Helper Detection Selector, to separate detections from each sensor into a separate output bus. The helper block is implemented using the MATLAB System (Simulink) block, and is defined in the HelperDetectionSelector
class, saved in the example folder. The architecture subsystem accepts detections and prediction time as inputs and generates tracks as output.
You use the Optimal Subpattern Assignment Metric block to evaluate the performance of the tracking architecture. The OSPA metric evaluates the performance of a tracking system through a scalar cost value, obtained by combining different error components. A lower OSPA value means better tracking. See trackOSPAMetric
for more details. You use the Scope (Simulink) block to visualize the OSPA metric results.
% Simulate the model
sim(model);
In the figure above, notice that the OSPA metric goes down after a few steps. The initial value of OSPA metric is higher because of establishment delay for each track.
close_system(model,0);
Summary
In this example you learned how to define a tracking architecture and export it to a Simulink model. You also learned how to evaluate the performance of an architecture using the OSPA metric in Simulink.