Generate radar detections for driving scenario
The radarDetectionGenerator
System object™ generates detections from a radar sensor mounted on an ego vehicle. All
detections are referenced to the coordinate system of the ego vehicle. You can use the
radarDetectionGenerator
object in a scenario containing actors and
trajectories, which you can create by using a drivingScenario
object. The object can simulate real detections with added
random noise and also generate false alarm detections. In addition, you can use the
radarDetectionGenerator
object to create input to a multiObjectTracker
. When building scenarios using the Driving Scenario
Designer app, the radar sensors mounted on the ego vehicle are output as
radarDetectionGenerator
objects.
To generate radar detections:
Create the radarDetectionGenerator
object and set its properties.
Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects?.
creates a radar detection generator object with default property values.sensor
= radarDetectionGenerator
sets properties using one or more
name-value pairs. For example,
sensor
= radarDetectionGenerator(Name,Value
)radarDetectionGenerator('DetectionCoordinates','Sensor
Cartesian','MaxRange',200)
creates a radar detection generator
that reports detections in the sensor Cartesian coordinate system and has a
maximum detection range of 200 meters. Enclose each property name in
quotes.
Unless otherwise indicated, properties are nontunable, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
release
function unlocks them.
If a property is tunable, you can change its value at any time.
For more information on changing property values, see System Design in MATLAB Using System Objects.
SensorIndex
— Unique sensor identifierUnique sensor identifier, specified as a positive integer. This property distinguishes detections that come from different sensors in a multisensor system.
Example: 5
Data Types: double
UpdateInterval
— Required time interval between sensor updates0.1
(default) | positive real scalarRequired time interval between sensor updates, specified as a positive
real scalar. The drivingScenario
object calls
the radar detection generator at regular time intervals. The radar detector
generates new detections at intervals defined by the
UpdateInterval
property. The value of the
UpdateInterval
property must be an integer multiple
of the simulation time interval. Updates requested from the sensor between
update intervals contain no detections. Units are in seconds.
Example: 5
Data Types: double
SensorLocation
— Sensor location[3.4 0]
(default) | [x y]
vectorLocation of the radar sensor center, specified as an [x
y]
vector. The SensorLocation
and
Height
properties define the coordinates of the
radar sensor with respect to the ego vehicle coordinate system. The default
value corresponds to a radar mounted at the center of the front grill of a
sedan. Units are in meters.
Example: [4 0.1]
Data Types: double
Height
— Radar sensor height above ground plane0.2
(default) | positive real scalarRadar sensor height above the ground plane, specified as a positive real
scalar. The height is defined with respect to the vehicle ground plane. The
SensorLocation
and Height
properties define the coordinates of the radar sensor with respect to the
ego vehicle coordinate system. The default value corresponds to a radar
mounted at the center of the front grill of a sedan. Units are in
meters.
Example: 0.3
Data Types: double
Yaw
— Yaw angle of sensor0
(default) | real scalarYaw angle of radar sensor, specified as a real scalar. The yaw angle is the angle between the center line of the ego vehicle and the downrange axis of the radar sensor. A positive yaw angle corresponds to a clockwise rotation when looking in the positive direction of the z-axis of the ego vehicle coordinate system. Units are in degrees.
Example: -4
Data Types: double
Pitch
— Pitch angle of sensor0
(default) | real scalarPitch angle of sensor, specified as a real scalar. The pitch angle is the angle between the downrange axis of the radar sensor and the x-y plane of the ego vehicle coordinate system. A positive pitch angle corresponds to a clockwise rotation when looking in the positive direction of the y-axis of the ego vehicle coordinate system. Units are in degrees.
Example: 3
Data Types: double
Roll
— Roll angle of sensor0
(default) | real scalarRoll angle of the radar sensor, specified as a real scalar. The roll angle is the angle of rotation of the downrange axis of the radar around the x-axis of the ego vehicle coordinate system. A positive roll angle corresponds to a clockwise rotation when looking in the positive direction of the x-axis of the coordinate system. Units are in degrees.
Example: -4
Data Types: double
FieldOfView
— Azimuth and elevation fields of view of radar sensor[20 5]
| real-valued 1-by-2 vector of positive valuesAzimuth and elevation fields of view of radar sensor, specified as a
real-valued 1-by-2 vector of positive values, [azfov
elfov]
. The field of view defines the angular extent spanned
by the sensor. Each component must lie in the interval (0,180]. Targets
outside of the field of view of the radar are not detected. Units are in
degrees.
Example: [14 7]
Data Types: double
MaxRange
— Maximum detection range150
| positive real scalarMaximum detection range, specified as a positive real scalar. The radar cannot detect a target beyond this range. Units are in meters.
Example: 200
Data Types: double
RangeRateLimits
— Minimum and maximum detection range rates[-100 100]
| real-valued 1-by-2 vectorMinimum and maximum detection range rates, specified as a real-valued 1-by-2 vector. The radar cannot detect a target out this range rate interval. Units are in meters per second.
Example: [-20 100]
To enable this property, set the HasRangeRate
property to true
.
Data Types: double
DetectionProbability
— Probability of detecting a target0.9
| positive real scalar less than or equal to 1Probability of detecting a target, specified as a positive real scalar
less than or equal to one. This quantity defines the probability of
detecting target that has a radar cross-section,
ReferenceRCS
, at the reference detection range,
ReferenceRange
.
FalseAlarmRate
— False alarm rate1e-6
(default) | positive real scalarFalse alarm rate within a radar resolution cell, specified as a positive real scalar in the range [10–7,10–3]. Units are dimensionless.
Example: 1e-5
Data Types: double
ReferenceRange
— Reference range for given probability of detection100
(default) | positive real scalarReference range for a given probability of detection, specified as a
positive real scalar. The reference range is the range when a target having
a radar cross-section specified by ReferenceRCS
is
detected with a probability of specified by
DetectionProbability
. Units are in meters.
Data Types: double
ReferenceRCS
— Reference radar cross-section for given probability of detection0
(default) | nonnegative real scalarReference radar cross-section (RCS) for given probability of detection,
specified as a nonnegative real scalar. The reference RCS is the value at
which a target is detected with probability specified by
DetectionProbability
. Units are in dBsm.
Data Types: double
RadarLoopGain
— Radar loop gainThis property is read-only.
Radar loop gain, specified as a real scalar. Radar loop gain is related to the reported signal-to-noise ratio of the radar, SNR, the target radar cross section, RCS, and target range, R by
SNR = RadarLoopGain + RCS - 40*log10(R)
RadarLoopGain
depends on the
DetectionProbability
,
ReferenceRange
, ReferenceRCS
,
and FalseAlarmRate
property values. Units are in
dB.
Data Types: double
AzimuthResolution
— Azimuth resolution of radar4
(default) | positive real scalarAzimuth resolution of the radar, specified as a positive real scalar. The azimuth resolution defines the minimum separation in azimuth angle at which the radar can distinguish two targets. The azimuth resolution is typically the 3dB-downpoint in azimuth angle beamwidth of the radar. Units are in degrees.
Data Types: double
ElevationResolution
— Elevation resolution of radar10
(default) | positive real scalarElevation resolution of the radar, specified as a positive real scalar. The elevation resolution defines the minimum separation in elevation angle at which the radar can distinguish two targets. The elevation resolution is typically the 3dB-downpoint in elevation angle beamwidth of the radar. Units are in degrees.
To enable this property, set the HasElevation
property to true
.
Data Types: double
RangeResolution
— Range resolution of radar2.5
(default) | positive real scalarRange resolution of the radar, specified as a positive real scalar. The range resolution defines the minimum separation in range at which the radar can distinguish between two targets. Units are in meters.
Data Types: double
RangeRateResolution
— Range rate resolution of radar0.5
(default) | positive real scalarRange rate resolution of the radar, specified as a positive real scalar. The range rate resolution defines the minimum separation in range rate at which the radar can distinguish between two targets. Units are in meters per second.
To enable this property, set the HasRangeRate
property to true
.
Data Types: double
AzimuthBiasFraction
— Azimuth bias fraction0.1
(default) | nonnegative real scalarAzimuth bias fraction of the radar, specified as a nonnegative real
scalar. The azimuth bias is expressed as a fraction of the azimuth
resolution specified in AzimuthResolution
. Units are
dimensionless.
Data Types: double
ElevationBiasFraction
— Elevation bias fraction0.1
(default) | nonnegative real scalarElevation bias fraction of the radar, specified as a nonnegative real
scalar. Elevation bias is expressed as a fraction of the elevation
resolution specified in ElevationResolution
. Units are
dimensionless.
To enable this property, set the HasElevation
property to true
.
Data Types: double
RangeBiasFraction
— Range bias fraction0.05
(default) | nonnegative real scalarRange bias fraction of the radar, specified as a nonnegative real scalar.
Range bias is expressed as a fraction of the range resolution specified in
RangeResolution
. Units are dimensionless.
Data Types: double
RangeRateBiasFraction
— Range rate bias fraction0.05
(default) | nonnegative real scalarRange rate bias fraction of the radar, specified as a nonnegative real
scalar. Range rate bias is expressed as a fraction of the range rate
resolution specified in RangeRateResolution
. Units are
dimensionless.
To enable this property, set the HasRangeRate
property to true
.
Data Types: double
HasElevation
— Enable radar to measure elevationfalse
(default) | true
Enable the radar to measure target elevation angles, specified as
false
or true
. Set this property
to true
to model a radar sensor that can estimate target
elevation. Set this property to false
to model a radar
sensor that cannot measure elevation.
Data Types: logical
HasRangeRate
— Enable radar to measure range ratefalse
(default) | true
Enable the radar to measure target range rates, specified as
false
or true
. Set this property
to true
to model a radar sensor which can estimate target
range rate. Set this property to false
to model a radar
sensor that cannot measure range rate.
Data Types: logical
HasNoise
— Enable adding noise to radar sensor measurementstrue
(default) | false
Enable adding noise to radar sensor measurements, specified as
true
or false
. Set this property
to true
to add noise to the radar measurements.
Otherwise, the measurements have no noise. Even if you set
HasNoise
to false
, the object
still computes the MeasurementNoise
property of each
detection.
Data Types: logical
HasFalseAlarms
— Enable creating false alarm radar detectionstrue
(default) | false
Enable reporting false alarm radar measurements, specified as
true
or false
. Set this property
to true
to report false alarms. Otherwise, only actual
detections are reported.
Data Types: logical
HasOcclusion
— Enable line-of-sight occlusiontrue
(default) | false
Enable line-of-sight occlusion, specified as true
or
false
. To generate detections only from objects for
which the radar has a direct line of sight, set this property to
true
. For example, with this property enabled, the
radar does not generate a detection for a vehicle that is behind another
vehicle and blocked from view.
Data Types: logical
MaxNumDetectionsSource
— Source of maximum number of detections reported 'Auto'
(default) | 'Property'
Source of maximum number of detections reported by the sensor, specified
as 'Auto'
or 'Property'
. When this
property is set to 'Auto'
, the sensor reports all
detections. When this property is set to 'Property'
, the
sensor reports no more than the number of detections specified by the
MaxNumDetections
property.
Data Types: char
| string
MaxNumDetections
— Maximum number of reported detections50
(default) | positive integerMaximum number of detections reported by the sensor, specified as a positive integer. Detections are reported in order of distance to the sensor until the maximum number is reached.
To enable this property, set the
MaxNumDetectionsSource
property to
'Property'
.
Data Types: double
DetectionCoordinates
— Coordinate system of reported detections'Ego Cartesian'
(default) | 'Sensor Cartesian'
| 'Sensor Spherical'
Coordinate system of reported detections, specified as one of these values:
'Ego Cartesian'
— Detections are
reported in the ego vehicle Cartesian coordinate system.
'Sensor Cartesian'
— Detections are
reported in the sensor Cartesian coordinate system.
'Sensor Spherical'
— Detections are
reported in a spherical coordinate system. This coordinate
system is centered at the radar and aligned with the orientation
of the radar on the ego vehicle.
Data Types: char
| string
ActorProfiles
— Actor profilesActor profiles, specified as structure or as an array of structures. Each structure contains the physical and radar characteristics of an actor.
If ActorProfiles
is a single structure, all actors passed into the radarDetectionGenerator
object use this profile.
If ActorProfiles
is an array, each actor passed into the object must have a unique actor profile.
To generate an array of structures for your driving scenario, use the actorProfiles
function. The table shows the valid structure fields. If you do not specify a field, the fields are set to their default values. If no actors are passed into the object, then the ActorID
field is not included.
Field | Description |
---|---|
ActorID | Scenario-defined actor identifier, specified as a positive integer. |
ClassID | Classification identifier, specified as a
nonnegative integer. 0 is
reserved for an object of an unknown or unassigned
class. |
Length | Length of actor, specified as a positive
real scalar. The default is
4.7 . Units are in
meters. |
Width | Width of actor, specified as a positive
real scalar. The default is
1.8 . Units are in
meters. |
Height | Height of actor, specified as a positive
real scalar. The default is
1.4 . Units are in
meters. |
OriginOffset | Offset of actor's rotational center from
its geometric center, specified as an
[x,y,
z] real-valued vector. The
rotational center, or origin, is located at the
bottom center of the actor. For vehicles, the
rotational center is the point on the ground
beneath the center of the rear axle. The default
is [0 0 0] . Units are in
meters. |
RCSPattern | Radar cross-section pattern of actor,
specified as a
numel(RCSElevationAngles) -by-numel(RCSAzimuthAngles)
real-valued matrix. The default is [10
10; 10 10] . Units are in decibels per
square meter. |
RCSAzimuthAngles | Azimuth angles corresponding to rows of
RCSPattern , specified as a
vector of real values in the range [–180, 180].
The default is [-180 180] .
Units are in degrees. |
RCSElevationAngles | Elevation angles corresponding to rows of
RCSPattern , specified as a
vector of real values in the range [–90, 90]. The
default is [-90 90] . Units are
in degrees. |
For full definitions of the structure fields, see the actor
and vehicle
functions.
[
also returns the number of valid detections reported,
dets
,numValidDets
]
= sensor(actors
,time
)numValidDets
.
[
also returns a logical value, dets
,numValidDets
,isValidTime
]
= sensor(actors
,time
)isValidTime
, indicating that
the UpdateInterval
time has elapsed.
actors
— Scenario actor posesScenario actor poses, specified as a structure or structure array.
Each structure corresponds to an actor. You can generate these
structures using the actorPoses
function.
You can also create these structures manually.
Field | Description |
---|---|
ActorID | Scenario-defined actor identifier, specified as a positive integer. |
Position | Position of actor, specified as a real-valued vector of the form [x, y, z]. Units are in meters. |
Velocity | Velocity (v) of actor in the x-, y-, and z-direction, specified as a real-valued vector of the form [vx, vy, vz]. Units are in meters per second. |
Roll | Roll angle of actor, specified as a real-valued scalar. Units are in degrees. |
Pitch | Pitch angle of actor, specified as a real-valued scalar. Units are in degrees. |
Yaw | Yaw angle of actor, specified as a real-valued scalar. Units are in degrees. |
AngularVelocity | Angular velocity (ω) of actor in the x-, y-, and z-direction, specified as a real-valued vector of the form [ωx, ωy, ωz]. Units are in degrees per second. |
For full definitions of the structure fields, see the actor
and vehicle
functions.
time
— Current simulation timeCurrent simulation time, specified as a nonnegative real scalar. The
drivingScenario
object
calls the radar detection generator at regular time intervals. The radar
detector generates new detections at intervals defined by the
UpdateInterval
property. The value of the
UpdateInterval
property must be an integer
multiple of the simulation time interval. Updates requested from the
sensor between update intervals contain no detections. Units are in
seconds.
Example: 10.5
Data Types: double
dets
— Radar sensor detectionsobjectDetection
objectsRadar sensor detections, returned as a cell array of objectDetection
objects.
Each object contains these fields:
Property | Definition |
---|---|
Time | Measurement time |
Measurement | Object measurements |
MeasurementNoise | Measurement noise covariance matrix |
SensorIndex | Unique ID of the sensor |
ObjectClassID | Object classification |
ObjectAttributes | Additional information passed to tracker |
MeasurementParameters | Parameters used by initialization functions of nonlinear Kalman tracking filters |
For Cartesian coordinates, Measurement
,
MeasurementNoise
, and
MeasurementParameters
are reported in the
coordinate system specified by the
DetectionCoordinates
property of the radarDetectionGenerator
.
For spherical coordinates, Measurement
and
MeasurementNoise
are reported in the spherical
coordinate system based on the sensor Cartesian coordinate system.
MeasurementParameters
are reported in sensor
Cartesian coordinates.
Measurement
DetectionCoordinates Property | Measurement and Measurement Noise Coordinates | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
'Ego Cartesian' |
Coordinate Dependence on HasRangeRate
| |||||||||||||||
'Sensor Cartesian' | ||||||||||||||||
'Sensor Spherical' |
Coordinate Dependence on HasRangeRate and HasElevation
|
MeasurementParameters
Parameter | Definition |
---|---|
Frame | Enumerated type indicating the frame used to
report measurements. When Frame
is set to 'rectangular' ,
detections are reported in Cartesian coordinates.
When Frame is set
'spherical' , detections are
reported in spherical coordinates. |
OriginPosition | 3-D vector offset of the sensor origin from the
ego vehicle origin. The vector is derived from the
SensorLocation and
Height properties specified
in the radarDetectionGenerator . |
Orientation | Orientation of the vision sensor coordinate
system with respect to the ego vehicle coordinate
system. The orientation is derived from the
Yaw ,
Pitch , and
Roll properties of the
radarDetectionGenerator . |
HasVelocity | Indicates whether measurements contain velocity or range rate components. |
HasElevation | Indicates whether measurements contain elevation components. |
ObjectAttributes
Attribute | Definition |
---|---|
TargetIndex | Identifier of the actor,
ActorID , that generated the
detection. For false alarms, this value is
negative. |
SNR | Detection signal-to-noise ratio in dB. |
numValidDets
— Number of detectionsNumber of detections, returned as a nonnegative integer.
When the MaxNumDetectionsSource
property is set to 'Auto'
,
numValidDets
is set to the length
of dets
.
When the MaxNumDetectionsSource
property is set to 'Property'
,
dets
is a cell array with length
determined by the MaxNumDetections
property. No more than MaxNumDetections
number of detections are returned. If the number of
detections is fewer than
MaxNumDetections
, the first
numValidDets
elements of
dets
hold valid detections. The
remaining elements of dets
are set to
the default value.
Data Types: double
isValidTime
— Valid detection time0
| 1
Valid detection time, returned as 0
or
1
. isValidTime
is
0
when detection updates are requested at times
that are between update intervals specified by
UpdateInterval
.
Data Types: logical
To use an object function, specify the
System object as the first input argument. For
example, to release system resources of a System object named obj
, use
this syntax:
release(obj)
Generate detections using a forward-facing automotive radar mounted on an ego vehicle. Assume that there are three targets:
Vehicle 1 is in the center lane, directly in front of the ego vehicle, and driving at the same speed.
Vehicle 2 is in the left lane and driving faster than the ego vehicle by 12 kilometers per hour.
Vehicle 3 is in the right lane and driving slower than the ego vehicle by 5 kilometers per hour.
All positions, velocities, and measurements are relative to the ego vehicle. Run the simulation for ten steps.
dt = 0.1; pos1 = [150 0 0]; pos2 = [160 10 0]; pos3 = [130 -10 0]; vel1 = [0 0 0]; vel2 = [12*1000/3600 0 0]; vel3 = [-5*1000/3600 0 0]; car1 = struct('ActorID',1,'Position',pos1,'Velocity',vel1); car2 = struct('ActorID',2,'Position',pos2,'Velocity',vel2); car3 = struct('ActorID',3,'Position',pos3,'Velocity',vel3);
Create an automotive radar sensor that is offset from the ego vehicle. By default, the sensor location is at (3.4,0) meters from the vehicle center and 0.2 meters above the ground plane. Turn off the range rate computation so that the radar sensor measures position only.
radar = radarDetectionGenerator('DetectionCoordinates','Sensor Cartesian', ... 'MaxRange',200,'RangeResolution',10,'AzimuthResolution',10, ... 'FieldOfView',[40 15],'UpdateInterval',dt,'HasRangeRate',false); tracker = multiObjectTracker('FilterInitializationFcn',@initcvkf, ... 'ConfirmationThreshold',[3 4],'DeletionThreshold',[6 6]);
Generate detections with the radar from the non-ego vehicles. The output detections form a cell array and can be passed directly in to the multiObjectTracker
.
simTime = 0;
nsteps = 10;
for k = 1:nsteps
dets = radar([car1 car2 car3],simTime);
[confirmedTracks,tentativeTracks,allTracks] = updateTracks(tracker,dets,simTime);
Move the cars one time step and update the multi-object tracker.
simTime = simTime + dt;
car1.Position = car1.Position + dt*car1.Velocity;
car2.Position = car2.Position + dt*car2.Velocity;
car3.Position = car3.Position + dt*car3.Velocity;
end
Use birdsEyePlot
to create an overhead view of the detections. Plot the sensor coverage area. Extract the X and Y positions of the targets by converting the Measurement
fields of the cell array into a MATLAB array. Display the detections on the bird's-eye plot.
BEplot = birdsEyePlot('XLim',[0 220],'YLim',[-75 75]); caPlotter = coverageAreaPlotter(BEplot,'DisplayName','Radar coverage area'); plotCoverageArea(caPlotter,radar.SensorLocation,radar.MaxRange, ... radar.Yaw,radar.FieldOfView(1)) detPlotter = detectionPlotter(BEplot,'DisplayName','Radar detections'); detPos = cellfun(@(d)d.Measurement(1:2),dets,'UniformOutput',false); detPos = cell2mat(detPos')'; if ~isempty(detPos) plotDetection(detPlotter,detPos) end
Model the effects of occlusion when generating radar detections from a radarDetectionGenerator
System object™.
Create two cars. Position the first car 40 meters away from the sensor. Position the second car 10 meters directly behind the first car.
car1 = struct('ActorID',1,'Position',[40 0 0]); car2 = struct('ActorID',2,'Position',[50 0 0]);
Create a radar detection generator System object, radarSensor
, with default values. Use the System object to generate detections.
radarSensor = radarDetectionGenerator;
simTime = 0; % start of simulation
[dets,numValidDets] = radarSensor([car1 car2],simTime);
Display the coverage area of the radar detection generator on a bird's-eye plot.
bep = birdsEyePlot('XLim',[0 60],'YLim',[-15 15]); caPlotter = coverageAreaPlotter(bep,'DisplayName', ... 'Radar coverage area'); plotCoverageArea(caPlotter,radarSensor.SensorLocation, ... radarSensor.MaxRange,radarSensor.Yaw, ... radarSensor.FieldOfView(1));
Extract the (X,Y) positions of the targets by converting the (X,Y) values of the Measurement
field of the cell array into a MATLAB array. Then, display the detections.
if numValidDets > 0 detPlotter = detectionPlotter(bep,'DisplayName','Radar detections'); detPos = cellfun(@(d)d.Measurement(1:2),dets,'UniformOutput',false); detPos = cell2mat(detPos')'; plotDetection(detPlotter,detPos) end
By default, the radar detection generator excludes targets that are occluded by other objects. Therefore, the radar detects the nearest target but not the target directly behind it. To include the occluded target in the detections, release the radar detection generator, disable line-of-sight occlusion, and generate detections again. Display the detections.
release(radarSensor) radarSensor.HasOcclusion = false; [detsNoOcclusion,numValidDets] = radarSensor([car1 car2],simTime); if numValidDets > 0 detPos = cellfun(@(d)d.Measurement(1:2),detsNoOcclusion,'UniformOutput',false); detPos = cell2mat(detPos')'; plotDetection(detPlotter, detPos) end
Release the radar detection generator.
release(radarSensor)
Usage notes and limitations:
See System Objects in MATLAB Code Generation (MATLAB Coder).
drivingScenario
| lidarPointCloudGenerator
| multiObjectTracker
| objectDetection
| visionDetectionGenerator
You have a modified version of this example. Do you want to open this example with your edits?