Main Content

setMeasurementSizes

Sets the sizes of the measurement and measurement noise

Since R2024b

    Description

    setMeasurementSizes(filter,measurementSize,measurementNoiseSize) sets the expected sizes of the measurement and measurement noise to the values in the measurementSize and measurementNoiseSize input arguments. When working with variable-sized measurements, use this function before passing measurements of new sizes to other object functions such as correct and distance.

    Note

    Only trackerGNN and trackerJPDA support variable-sized measurement, but not for the trackingKF filter.

    example

    Examples

    collapse all

    Create a linear Kalman filter that uses a 3D constant velocity motion model. Initialize the filter with a starting state vector indicating position and velocity.

    KF = trackingKF(MotionModel="3D Constant Velocity" ...
        ,State=[100;0;0;0;0;0]);
    predict(KF,1)

    Predict the state of the filter after 1 second and use the distance function to lock the measurement model.

    distance(KF,[100;0;0])
    ans = 
    3.5360
    

    Display the current measurement model, measurement noise, and state covariance matrix.

    disp(KF.MeasurementModel)
         1     0     0     0     0     0
         0     0     1     0     0     0
         0     0     0     0     1     0
    
    disp(KF.MeasurementNoise)
         1     0     0
         0     1     0
         0     0     1
    
    disp(KF.StateCovariance);
        2.2500    1.5000         0         0         0         0
        1.5000    2.0000         0         0         0         0
             0         0    2.2500    1.5000         0         0
             0         0    1.5000    2.0000         0         0
             0         0         0         0    2.2500    1.5000
             0         0         0         0    1.5000    2.0000
    

    To update the measurement and measurement noise sizes for the filter, use the setMeasurementSizes function.

    setMeasurementSizes(KF,2,2);

    Update the measurement model of the Kalman filter to consider only the position in the x and z directions. Set the measurement noise to 3, which will scalar expand into a 2-by-2 matrix.

    KF.MeasurementModel = [1 0 0 0 0 0; 0 0 1 0 0 0];
    KF.MeasurementNoise = 3;

    Display the updated measurement model and measurement noise.

    disp(KF.MeasurementModel);
         1     0     0     0     0     0
         0     0     1     0     0     0
    
    disp(KF.MeasurementNoise)
         3     0
         0     3
    

    Use the distance function to lock the updated measurement model.

    distance(KF,[100;0])
    ans = 
    3.3165
    

    Correct the filter's state estimation using a new measurement vector with different size and display the updated state covariance matrix.

    correct(KF,[100;0]);
    disp(KF.StateCovariance);
        1.2857    0.8571         0         0         0         0
        0.8571    1.5714         0         0         0         0
             0         0    1.2857    0.8571         0         0
             0         0    0.8571    1.5714         0         0
             0         0         0         0    2.2500    1.5000
             0         0         0         0    1.5000    2.0000
    

    Initialize the constant velocity Extended Kalman Filter (EKF) using an objectDetection object.

    mp = struct('Frame', 'spherical', ...
        'HasElevation', false, 'HasVelocity', false);
    detection = objectDetection(0,[0;100], ...
        'MeasurementParameters',mp);
    filter = initcvekf(detection);

    Predict the state of the filter after 1 second and use the distance function to lock the measurement function.

    predict(filter, 1);
    distance(filter,[0;100],{mp});

    Display the filter's measurement noise and state covariance matrix.

    disp(filter.MeasurementNoise);
         1     0
         0     1
    
    disp(filter.StateCovariance);
       1.0e+03 *
    
        0.1013    0.1005         0         0         0         0
        0.1005    0.1010         0         0         0         0
             0         0    0.1033    0.1005         0         0
             0         0    0.1005    0.1010         0         0
             0         0         0         0    8.3371    0.1005
             0         0         0         0    0.1005    0.1010
    

    To update the filter's measurement and noise sizes, use the setMeasurementSizes function.

    setMeasurementSizes(filter,3,3);

    Set the measurement noise to 2, which will scalar expand into a 3-by-3 matrix. Display the updated measurement noise for verification.

    filter.MeasurementNoise = 2;
    disp(filter.MeasurementNoise);
        2.0000         0         0
             0    2.0000         0
             0         0    2.0000
    

    Use the distance function to lock the updated measurement function.

    distance(filter,[100;0;0]) 
    ans = 
    18.3226
    

    Correct the filter's state estimation using a new measurement vector with different size and display the updated state covariance matrix.

    correct(filter,[100;0;0]);
    disp(filter.StateCovariance);
        1.9613    1.9467         0         0         0         0
        1.9467    3.1768         0         0         0         0
             0         0    1.9620    1.9089         0         0
             0         0    1.9089    5.0777         0         0
             0         0         0         0    1.9995    0.0241
             0         0         0         0    0.0241   99.7888
    

    Input Arguments

    collapse all

    Filter for object tracking, specified as one of these objects:

    Note

    When using setMeasurementSizes with trackingKF, the trackingKF filter must be initialized with the largest possible sizes for measurement and measurement noise.

    Expected size of the measurement, specified as a positive real integer.

    Expected size of the measurement noise, specified as a positive real integer.

    Extended Capabilities

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    Version History

    Introduced in R2024b