# cvmeas

## Syntax

## Description

returns the measurement for a constant-velocity Kalman filter motion model in
rectangular coordinates. The `measurement`

= cvmeas(`state`

)`state`

argument specifies the
current state of the tracking filter.

also specifies the measurement coordinate system, `measurement`

= cvmeas(`state`

,`frame`

)`frame`

.

also specifies the sensor position, `measurement`

= cvmeas(`state`

,`frame`

,`sensorpos`

)`sensorpos`

.

also
specifies the sensor velocity, `measurement`

= cvmeas(`state`

,`frame`

,`sensorpos`

,`sensorvel`

)`sensorvel`

.

specifies the measurement parameters,
`measurement`

= cvmeas(`state`

,`measurementParameters`

)`measurementParameters`

.

`[`

returns the measurement bounds, used by a tracking filter (`measurement`

,`bounds`

] = cvmeas(___)`trackingEKF`

or `trackingUKF`

) in residual calculations. See the
`HasMeasurementWrapping`

of the filter object for more
details.

## Examples

### Create Measurement from Constant-Velocity Object in Rectangular Frame

Define the state of an object in 2-D constant-velocity motion. The state is the position and velocity in both dimensions. The measurements are in rectangular coordinates.

state = [1;10;2;20]; measurement = cvmeas(state)

`measurement = `*3×1*
1
2
0

The *z*-component of the measurement is zero.

### Create Measurement from Constant Velocity Object in Spherical Frame

Define the state of an object in 2-D constant-velocity motion. The state is the position and velocity in each spatial dimension. The measurements are in spherical coordinates.

```
state = [1;10;2;20];
measurement = cvmeas(state,'spherical')
```

`measurement = `*4×1*
63.4349
0
2.2361
22.3607

The elevation of the measurement is zero and the range rate is positive. These results indicate that the object is moving away from the sensor.

### Create Measurement from Constant-Velocity Object in Translated Spherical Frame

Define the state of an object in 2-D constant-velocity motion. The state consists of position and velocity in each spatial dimension. The measurements are in spherical coordinates with respect to a frame located at *(20;40;0)* meters.

```
state = [1;10;2;20];
measurement = cvmeas(state,'spherical',[20;40;0])
```

`measurement = `*4×1*
-116.5651
0
42.4853
-22.3607

The elevation of the measurement is zero and the range rate is negative. These results indicate that the object is moving toward the sensor.

### Create Measurement from Constant-Velocity Object Using Measurement Parameters

Define the state of an object in 2-D constant-velocity motion. The state consists of position and velocity in each spatial dimension. The measurements are in spherical coordinates with respect to a frame located at *(20;40;0)* meters.

```
state2d = [1;10;2;20];
frame = 'spherical';
sensorpos = [20;40;0];
sensorvel = [0;5;0];
laxes = eye(3);
measurement = cvmeas(state2d,frame,sensorpos,sensorvel,laxes)
```

`measurement = `*4×1*
-116.5651
0
42.4853
-17.8885

The elevation of the measurement is zero and the range rate is negative. These results indicate that the object is moving toward the sensor.

Put the measurement parameters in a structure and use the alternative syntax.

measparm = struct('Frame',frame,'OriginPosition',sensorpos,'OriginVelocity',sensorvel, ... 'Orientation',laxes); measurement = cvmeas(state2d,measparm)

`measurement = `*4×1*
-116.5651
0
42.4853
-17.8885

### Display Residual Wrapping Bounds for `cvmeas`

Specify a 2-D state and specify a measurement structure such that the function outputs azimuth, range, and range-rate measurements.

state = [10 1 10 1]'; % [x vx y vy]' mp = struct("Frame","Spherical", ... "HasAzimuth",true, ... "HasElevation",false, ... "HasRange",true, ... "HasVelocity",false);

Output the measurement and wrapping bounds using the `cvmeas`

function.

[measure,bounds] = cvmeas(state,mp)

`measure = `*2×1*
45.0000
14.1421

`bounds = `*2×2*
-180 180
-Inf Inf

## Input Arguments

`state`

— Kalman filter state vector

real-valued *2D*-by-*N* matrix

Kalman filter state vector for constant-velocity motion, specified as a
real-valued *2D*-by-*N* matrix.
*D* is the number of spatial degrees of freedom of
motion and *N* is the number states. The
`state`

is expected to be Cartesian state. For each
spatial degree of motion, the state vector, as a column of the
`state`

matrix, takes the form shown in this
table.

Spatial Dimensions | State Vector Structure |
---|---|

1-D | `[x;vx]` |

2-D | `[x;vx;y;vy]` |

3-D | `[x;vx;y;vy;z;vz]` |

For example, `x`

represents the
*x*-coordinate and `vx`

represents the
velocity in the *x*-direction. If the motion model is 1-D,
values along the *y* and *z* axes are
assumed to be zero. If the motion model is 2-D, values along the
*z* axis are assumed to be zero. Position coordinates
are in meters and velocity coordinates are in meters/sec.

**Example: **`[5;.1;0;-.2;-3;.05]`

**Data Types: **`single`

| `double`

`frame`

— Measurement output frame

`'rectangular'`

(default) | `'spherical'`

Measurement output frame, specified as `'rectangular'`

or
`'spherical'`

. When the frame is `'rectangular'`

,
a measurement consists of *x*, *y*, and
*z* Cartesian coordinates. When specified as
`'spherical'`

, a measurement consists of azimuth, elevation,
range, and range rate.

**Data Types: **`char`

`sensorpos`

— Sensor position

`[0;0;0]`

(default) | real-valued 3-by-1 column vector

Sensor position with respect to the navigation frame, specified as a real-valued 3-by-1 column vector. Units are in meters.

**Data Types: **`double`

`sensorvel`

— Sensor velocity

`[0;0;0]`

(default) | real-valued 3-by-1 column vector

Sensor velocity with respect to the navigation frame, specified as a real-valued 3-by-1 column vector. Units are in m/s.

**Data Types: **`double`

`laxes`

— Local sensor coordinate axes

`[1,0,0;0,1,0;0,0,1]`

(default) | 3-by-3 orthogonal matrix

Local sensor coordinate axes, specified as a 3-by-3 orthogonal matrix. Each column specifies
the direction of the local *x*-, *y*-, and
*z*-axes, respectively, with respect to the navigation frame. That
is, the matrix is the rotation matrix from the global frame to the sensor frame.

**Data Types: **`double`

`measurementParameters`

— Measurement parameters

structure | array of structure

Measurement parameters, specified as a structure or an array of structures. The fields of the structure are:

Field | Description | Example |
---|---|---|

`Frame` | Frame used to report measurements, specified as one of these values: `'Rectangular'` — Detections are reported in rectangular coordinates.`'Spherical'` — Detections are reported in spherical coordinates.
| `'spherical'` |

`OriginPosition` | Position offset of the origin of the frame relative to the parent frame, specified as an `[x y z]` real-valued vector. | `[0 0 0]` |

`OriginVelocity` | Velocity offset of the origin of the frame relative to the parent frame, specified as a `[vx vy vz]` real-valued vector. | `[0 0 0]` |

`Orientation` | Frame rotation matrix, specified as a 3-by-3 real-valued orthonormal matrix. | `[1 0 0; 0 1 0; 0 0 1]` |

`HasAzimuth` | Logical scalar indicating if azimuth is included in the measurement. This
field is not relevant when the | `1` |

`HasElevation` | Logical scalar indicating if elevation information is included in the measurement. For
measurements reported in a rectangular frame, and if
`HasElevation` is false, the reported measurements assume 0
degrees of elevation. | `1` |

`HasRange` | Logical scalar indicating if range is included in the measurement. This
field is not relevant when the | `1` |

`HasVelocity` | Logical scalar indicating if the reported detections include velocity measurements. For a
measurement reported in the rectangular frame, if `HasVelocity`
is `false` , the measurements are reported as ```
[x y
z]
``` . If `HasVelocity` is `true` ,
the measurement is reported as `[x y z vx vy vz]` . For a
measurement reported in the spherical frame, if `HasVelocity`
is `true` , the measurement contains range-rate
information. | `1` |

`IsParentToChild` | Logical scalar indicating if `Orientation` performs a frame rotation from the parent coordinate frame to the child coordinate frame. When `IsParentToChild` is `false` , then `Orientation` performs a frame rotation from the child coordinate frame to the parent coordinate frame. | `0` |

If you only want to perform one coordinate transformation, such as a transformation from the body frame to the sensor frame, you only need to specify a measurement parameter structure. If you want to perform multiple coordinate transformations, you need to specify an array of measurement parameter structures. To learn how to perform multiple transformations, see the Convert Detections to objectDetection Format (Sensor Fusion and Tracking Toolbox) example.

**Data Types: **`struct`

## Output Arguments

`measurement`

— Measurement vector

real-valued *M*-by-*N* matrix

Measurement vector, returned as an *M*-by-*N*
matrix. *M* is the dimension of the measurement and
*N*, the number of measurement, is the same as the number of
states. The form of each measurement depends upon which syntax you use.

When the syntax does not use the

`measurementParameters`

argument, the measurement vector is`[x,y,z]`

when the`frame`

input argument is set to`'rectangular'`

and`[az;el;r;rr]`

when the`frame`

is set to`'spherical'`

.When the syntax uses the

`measurementParameters`

argument, the size of the measurement vector depends on the values of the`frame`

,`HasVelocity`

, and`HasElevation`

fields in the`measurementParameters`

structure.frame measurement `'spherical'`

Specifies the azimuth angle,

*az*, elevation angle,*el*, range,*r*, and range rate,*rr*, of the object with respect to the local ego vehicle coordinate system. Positive values for range rate indicate that an object is moving away from the sensor.**Spherical measurements****HasElevation**false true **HasVelocity**false `[az;r]`

`[az;el;r]`

true `[az;r;rr]`

`[az;el;r;rr]`

Angle units are in degrees, range units are in meters, and range rate units are in m/s.

`'rectangular'`

Specifies the Cartesian position and velocity coordinates of the tracked object with respect to the ego vehicle coordinate system.

**Rectangular measurements****HasVelocity**false `[x;y;y]`

true `[x;y;z;vx;vy;vz]`

Position units are in meters and velocity units are in m/s.

**Data Types: **`double`

`bounds`

— Measurement residual wrapping bounds

*M*-by-2 real-valued matrix

Measurement residual wrapping bounds, returned as an *M*-by-2 real-valued matrix, where *M* is the dimension of the measurement. Each row of the matrix corresponds to the lower and upper bounds for the specific dimension in the `measurement`

output.

The function returns different bound values based on the `frame`

input.

If the

`frame`

input is specified as`'Rectangular'`

, each row of the matrix is`[-Inf Inf]`

, indicating the filter does not wrap the measurement residual in the filter.

If the

`frame`

input is specified as`'Spherical'`

, the returned`bounds`

contains the bounds for specific measurement dimension based on the following:When

`HasAzimuth`

=`true`

, the matrix includes a row of`[-180 180]`

, indicating the filter wraps the azimuth residual in the range of`[-180 180]`

in degrees.When

`HasElevation`

=`true`

, the matrix includes a row of`[-90 90]`

, indicating the filter wraps the elevation residual in the range of`[-90 90]`

in degrees.When

`HasRange`

=`true`

, the matrix includes a row of`[-Inf Inf]`

, indicating the filter does not wrap the range residual.When

`HasVelocity`

=`true`

, the matrix includes a row of`[-Inf Inf]`

, indicating the filter does not wrap the range rate residual.

If you specify any of the options as `false`

, the returned
`bounds`

does not contain the corresponding row. For example, if
`HasAzimuth`

= `true`

, `HasElevation`

=
`false`

, `HasRange`

= `true`

,
`HasVelocity`

= `true`

, then `bounds`

is returned as

-180 180 -Inf Inf -Inf Inf

The filter wraps the measuring residuals based on this equation:

$${x}_{wrap}=mod(x-\frac{a-b}{2},b-a)+\frac{a-b}{2}$$

where *x* is the residual to wrap, *a* is
the lower bound, *b* is the upper bound, *mod* is the
modules after division function, and *x*_{wrap} is the
wrapped residual.

**Data Types: **`single`

| `double`

## More About

### Azimuth and Elevation Angle Definitions

Define the azimuth and elevation angles used in the toolbox.

The *azimuth angle* of a vector is the
angle between the *x*-axis and its orthogonal projection
onto the *xy* plane. The angle is positive in going
from the *x* axis toward the *y* axis.
Azimuth angles lie between –180 and 180 degrees. The *elevation
angle* is the angle between the vector and its orthogonal
projection onto the *xy*-plane. The angle is positive
when going toward the positive *z*-axis from the *xy* plane.

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

## Version History

**Introduced in R2021a**

## See Also

### Functions

`constacc`

|`constaccjac`

|`cameas`

|`cameasjac`

|`constturn`

|`constturnjac`

|`ctmeas`

|`ctmeasjac`

|`constvel`

|`constveljac`

|`cvmeasjac`

### Objects

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)