Main Content

perturb

Apply perturbations to object

Description

example

offsets = perturb(obj) applies the perturbations defined on the object, obj and returns the offset values. You can define perturbations on the object by using the perturbations function.

Examples

collapse all

Define a waypoint trajectory. By default, this trajectory contains two waypoints.

traj = waypointTrajectory
traj = 
  waypointTrajectory with properties:

         SampleRate: 100
    SamplesPerFrame: 1
          Waypoints: [2x3 double]
      TimeOfArrival: [2x1 double]
         Velocities: [2x3 double]
             Course: [2x1 double]
        GroundSpeed: [2x1 double]
          ClimbRate: [2x1 double]
        Orientation: [2x1 quaternion]
          AutoPitch: 0
           AutoBank: 0
     ReferenceFrame: 'NED'

Define perturbations on the Waypoints property and the TimeOfArrival property.

rng(2020);
perturbs1 = perturbations(traj,'Waypoints','Normal',1,1)
perturbs1=2×3 table
       Property          Type            Value       
    _______________    ________    __________________

    "Waypoints"        "Normal"    {[  1]}    {[  1]}
    "TimeOfArrival"    "None"      {[NaN]}    {[NaN]}

perturbs2 = perturbations(traj,'TimeOfArrival','Selection',{[0;1],[0;2]})
perturbs2=2×3 table
       Property           Type                     Value             
    _______________    ___________    _______________________________

    "Waypoints"        "Normal"       {[     1]}    {[            1]}
    "TimeOfArrival"    "Selection"    {1x2 cell}    {[0.5000 0.5000]}

Perturb the trajectory.

offsets = perturb(traj)
offsets=2×1 struct array with fields:
    Property
    Offset
    PerturbedValue

The Waypoints property and the TimeOfArrival property have changed.

traj.Waypoints
ans = 2×3

    1.8674    1.0203    0.7032
    2.3154   -0.3207    0.0999

traj.TimeOfArrival
ans = 2×1

     0
     2

Create an insSensor object.

sensor = insSensor
sensor = 
  insSensor with properties:

           MountingLocation: [0 0 0]            m    
               RollAccuracy: 0.2                deg  
              PitchAccuracy: 0.2                deg  
                YawAccuracy: 1                  deg  
           PositionAccuracy: [1 1 1]            m    
           VelocityAccuracy: 0.05               m/s  
       AccelerationAccuracy: 0                  m/s² 
    AngularVelocityAccuracy: 0                  deg/s
                  TimeInput: 0                       
               RandomStream: 'Global stream'         

Define the perturbation on the RollAccuracy property as three values with an equal possibility each.

values = {0.1 0.2 0.3}
values=1×3 cell array
    {[0.1000]}    {[0.2000]}    {[0.3000]}

probabilities = [1/3 1/3 1/3]
probabilities = 1×3

    0.3333    0.3333    0.3333

perturbations(sensor,'RollAccuracy','Selection',values,probabilities)
ans=7×3 table
            Property                Type                        Value                 
    _________________________    ___________    ______________________________________

    "RollAccuracy"               "Selection"    {1x3 cell}    {[0.3333 0.3333 0.3333]}
    "PitchAccuracy"              "None"         {[   NaN]}    {[                 NaN]}
    "YawAccuracy"                "None"         {[   NaN]}    {[                 NaN]}
    "PositionAccuracy"           "None"         {[   NaN]}    {[                 NaN]}
    "VelocityAccuracy"           "None"         {[   NaN]}    {[                 NaN]}
    "AccelerationAccuracy"       "None"         {[   NaN]}    {[                 NaN]}
    "AngularVelocityAccuracy"    "None"         {[   NaN]}    {[                 NaN]}

Perturb the sensor object using the perturb function.

rng(2020)
perturb(sensor);
sensor
sensor = 
  insSensor with properties:

           MountingLocation: [0 0 0]            m    
               RollAccuracy: 0.5                deg  
              PitchAccuracy: 0.2                deg  
                YawAccuracy: 1                  deg  
           PositionAccuracy: [1 1 1]            m    
           VelocityAccuracy: 0.05               m/s  
       AccelerationAccuracy: 0                  m/s² 
    AngularVelocityAccuracy: 0                  deg/s
                  TimeInput: 0                       
               RandomStream: 'Global stream'         

The RollAccuracy is perturbed to 0.5 deg.

Create an imuSensor object and show its perturbable properties.

imu = imuSensor;
perturbations(imu)
ans=17×3 table
                   Property                    Type           Value       
    ______________________________________    ______    __________________

    "Accelerometer.MeasurementRange"          "None"    {[NaN]}    {[NaN]}
    "Accelerometer.Resolution"                "None"    {[NaN]}    {[NaN]}
    "Accelerometer.ConstantBias"              "None"    {[NaN]}    {[NaN]}
    "Accelerometer.NoiseDensity"              "None"    {[NaN]}    {[NaN]}
    "Accelerometer.BiasInstability"           "None"    {[NaN]}    {[NaN]}
    "Accelerometer.RandomWalk"                "None"    {[NaN]}    {[NaN]}
    "Accelerometer.TemperatureBias"           "None"    {[NaN]}    {[NaN]}
    "Accelerometer.TemperatureScaleFactor"    "None"    {[NaN]}    {[NaN]}
    "Gyroscope.MeasurementRange"              "None"    {[NaN]}    {[NaN]}
    "Gyroscope.Resolution"                    "None"    {[NaN]}    {[NaN]}
    "Gyroscope.ConstantBias"                  "None"    {[NaN]}    {[NaN]}
    "Gyroscope.NoiseDensity"                  "None"    {[NaN]}    {[NaN]}
    "Gyroscope.BiasInstability"               "None"    {[NaN]}    {[NaN]}
    "Gyroscope.RandomWalk"                    "None"    {[NaN]}    {[NaN]}
    "Gyroscope.TemperatureBias"               "None"    {[NaN]}    {[NaN]}
    "Gyroscope.TemperatureScaleFactor"        "None"    {[NaN]}    {[NaN]}
      ⋮

Specify the perturbation for the NoiseDensity property of the accelerometer as a uniform distribution.

perturbations(imu,'Accelerometer.NoiseDensity', ...
    'Uniform',1e-5,1e-3);

Specify the perturbation for the RandomWalk property of the gyroscope as a truncated normal distribution.

 perts = perturbations(imu,'Gyroscope.RandomWalk', ...
    'TruncatedNormal',2,1e-5,0,Inf);

Load prerecorded IMU data.

load imuSensorData.mat 
numSamples = size(orientations);

Simulate the imuSensor three times with different perturbation realizations.

rng(2021); % For repeatable results
numRuns = 3;
colors = ['b' 'r' 'g'];
for idx = 1:numRuns

    % Clone IMU to maintain original values
    imuCopy = clone(imu);

    % Perturb noise values
    offsets = perturb(imuCopy);

    % Obtain the measurements 
    [accelReadings,gyroReadings] = imuCopy(accelerations,angularVelocities,orientations);
    
    % Plot the results
    plot(times,gyroReadings(:,3),colors(idx));
    hold on;
end
xlabel('Time (s)')
ylabel('Z-Component of Gyro Readings (rad/s)')
legend("First Pass","Second Pass","Third Pass");
hold off

Figure contains an axes object. The axes object contains 3 objects of type line. These objects represent First Pass, Second Pass, Third Pass.

Input Arguments

collapse all

Output Arguments

collapse all

Property offsets, returned as an array of structures. Each structure contains these fields:

Field NameDescription
PropertyName of perturbed property
OffsetOffset values applied in the perturbation
PerturbedValueProperty values after the perturbation

Introduced in R2020b