Main Content


Merge detections into clustered detections



clusteredDetections = mergeDetections(detections,clusterIndex) merges detections sharing the same cluster labels. By default, the function merges detections in the same cluster using a Gaussian mixture merging algorithm. The function assumes that all detections in the same cluster share the same Time, SensorIndex, ObjectClassID, MeasurementParameters, and ObjectAttributes properties or fields.

clusteredDetections = mergeDetections(___,MergingFcn=mergeFcn) specifies the function used to merge the detections in addition to the input arguments from the previous syntax.


collapse all

Generate two clusters of detections with two false alarms.

rng(2021) % For repeatable results
x1 = [5; 5; 0] + randn(3,4); % Four detections in cluster one
x2 = [5; -5; 0] + randn(3,4); % Four detections in cluster two
xFalse = 30*randn(3,2); % Two false alarms
x = [x1 x2 xFalse];

Format these detections into a cell array of objectDetection objects.

detections = repmat({objectDetection(0,[0; 0; 0])},10,1);
for i = 1:10
    detections{i}.Measurement = x(:,i);

Define the cluster indices according to the previously defined scenario. You can typically obtain the cluster indices by applying a clustering algorithm on the detections.

clusterIndex = [1; 1; 1; 1; 2; 2; 2; 2; 3; 4];

Use the mergeDetections function to merge the detections.

clusteredDetections = mergeDetections(detections,clusterIndex);

Visualize the results in a theater plot.

% Create a theaterPlot object.
tp = theaterPlot;

% Create two detection plotters, one for unclustered detections and one for
% clustered detections.
detPlotterUn = detectionPlotter(tp,DisplayName="Unclustered Detections", ...
detPlotterC = detectionPlotter(tp,DisplayName="Clustered Detections", ...

% Concatenate measurements and covariances for unclustered detections
detArray = [detections{:}];
xUn = horzcat(detArray.Measurement)';
PUn = cat(3,detArray.MeasurementNoise);

% Concatenate measurements and covariance for clustered detections
clusteredDetArray = [clusteredDetections{:}];
xC = horzcat(clusteredDetArray.Measurement)';
PC = cat(3,clusteredDetArray.MeasurementNoise);

% Plot all unclustered and clustered detections

Input Arguments

collapse all

Object detections, specified as an N-element array of objectDetection (Sensor Fusion and Tracking Toolbox) objects, N-element cell array of objectDetection objects, or an N-element array of structures whose field names are the same as the property names of the objectDetection object. N is the number of detections. You can create detections directly, or you can obtain detections from the outputs of sensor objects such as fusionRadarSensor (Sensor Fusion and Tracking Toolbox), irSensor (Sensor Fusion and Tracking Toolbox), and sonarSensor (Sensor Fusion and Tracking Toolbox).

Cluster indices, specified as an N-element vector of positive integers, where N is the number of detections specified in the detections input. Each element is the cluster index of the corresponding detection in the detections input. For example, if clusterIndex(i)=k, then the ith detection from the detections input belongs to cluster k.

Function to merge detections, specified as a function handle. The function must use this syntax:

  detectionOut = mergeFcn(detectionsIn) 

  • detectionsIn is specified as a cell array of objectDetection (Sensor Fusion and Tracking Toolbox) objects (in the same cluster).

  • detectionOut is returned as an objectDetection object.

Example: @mergeFcn

Output Arguments

collapse all

Clustered detections, returned as an M-element cell array of objectDetection (Sensor Fusion and Tracking Toolbox) objects, where M is the number of unique cluster indices specified in the clusterIndex input.

Introduced in R2021b