Main Content

synchronize

Synchronize sensor data with reference sensor information

Since R2024b

Description

synchronize(sensorDataObj,refSensorData) synchronizes data in the input sensor data object sensorDataObj with reference to the timestamps in the input reference sensor object refSensorData.

example

synchronize(sensorDataObj,NewTimestamps=newTimestamps) resamples data in the input sensor data object sensorDataObj with reference to the specified new timestamps newTimestamps.

example

synchronize(sensorDataObj,SampleTime=dt) resamples data in the input sensor data object sensorDataObj with a specified regularly spaced sample time, dt.

example

synchronize(sensorDataObj,SampleRate=Fs) resamples data in the input sensor data object sensorDataObj with the specified sample rate Fs.

example

synchronize(___,Method=method) resamples data in the input sensor data object sensorDataObj using the specified synchronization method method in addition to any combination of input arguments from previous syntaxes.

sensorDataSynchronized = synchronize(___) returns a synchronized sensor data object sensorDataSynchronized.

Note

This function requires the Scenario Builder for Automated Driving Toolbox™ support package. You can install the Scenario Builder for Automated Driving Toolbox support package from the Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

example

Examples

collapse all

Load recorded GPS data into the workspace. The data contains GPS information recorded from two sensors as the structures qComGPS and uBloxGPS.

load("comma_gps_data.mat")

Initialize a GPSData object using information from the loaded GPS data qComGPS.

qcomGPSData = scenariobuilder.GPSData(qComGPS.Timestamps,qComGPS.Lat,qComGPS.Long,qComGPS.Alt,Name="qcomGPS")
qcomGPSData = 
  GPSData with properties:

          Name: "qcomGPS"

    NumSamples: 28
      Duration: 57.9996
    SampleRate: 0.4828
    SampleTime: 2.1481
    Timestamps: [28×1 double]

      Latitude: [28×1 double]
     Longitude: [28×1 double]
      Altitude: [28×1 double]

    Attributes: []

Initialize another GPSData object using information from the loaded GPS data uBloxGPS.

ubloxGPSData = scenariobuilder.GPSData(uBloxGPS.Timestamps,uBloxGPS.Lat,uBloxGPS.Long,uBloxGPS.alt,Name = "ubloxGPS")
ubloxGPSData = 
  GPSData with properties:

          Name: "ubloxGPS"

    NumSamples: 599
      Duration: 59.8830
    SampleRate: 10.0028
    SampleTime: 0.1001
    Timestamps: [599×1 double]

      Latitude: [599×1 double]
     Longitude: [599×1 double]
      Altitude: [599×1 double]

    Attributes: []

Synchronize the qComGPS sensor data with the uBloxGPS sensor data.

synchronize(qcomGPSData,ubloxGPSData)

Display the qComGPS data that has been synchronized with the uBloxGPS GPS data. Observe that the synchronized qComGPS sensor data contains the same number of samples as uBloxGPS sensor data.

disp(qcomGPSData)
  GPSData with properties:

          Name: "qcomGPS"

    NumSamples: 599
      Duration: 59.8830
    SampleRate: 10.0028
    SampleTime: 0.1001
    Timestamps: [599×1 double]

      Latitude: [599×1 double]
     Longitude: [599×1 double]
      Altitude: [599×1 double]

    Attributes: []

Load recorded GPS data into the workspace.

load("recordedGPSData.mat")

Initialize a GPSData object using information from the loaded GPS data.

gpsData = scenariobuilder.GPSData(timestamps,latitudes,longitudes,altitudes)
gpsData = 
  GPSData with properties:

          Name: ''

    NumSamples: 392
      Duration: 19.5498
    SampleRate: 20.0513
    SampleTime: 0.0500
    Timestamps: [392×1 double]

      Latitude: [392×1 single]
     Longitude: [392×1 single]
      Altitude: [392×1 single]

    Attributes: []

Specify the new timestamps to which to resample the data.

newTimestamps = linspace(gpsData.Timestamps(1),gpsData.Timestamps(end),100);

Resample the data using the new timestamps.

synchronize(gpsData,NewTimestamps=newTimestamps)

Display the resampled GPS data. Observe that the number of samples in the resampled GPS sensor data matched the number of specified new timestamps.

disp(gpsData)
  GPSData with properties:

          Name: ''

    NumSamples: 100
      Duration: 19.5498
    SampleRate: 5.1151
    SampleTime: 0.1975
    Timestamps: [100×1 double]

      Latitude: [100×1 single]
     Longitude: [100×1 single]
      Altitude: [100×1 single]

    Attributes: []

Load recorded GPS data into the workspace.

load("recordedGPSData.mat")

Initialize a GPSData object using information from the loaded GPS data.

gpsData = scenariobuilder.GPSData(timestamps,latitudes,longitudes,altitudes)
gpsData = 
  GPSData with properties:

          Name: ''

    NumSamples: 392
      Duration: 19.5498
    SampleRate: 20.0513
    SampleTime: 0.0500
    Timestamps: [392×1 double]

      Latitude: [392×1 single]
     Longitude: [392×1 single]
      Altitude: [392×1 single]

    Attributes: []

Specify a sample time to use to uniformly sample the GPS data.

dt = 0.01; % Units are in seconds

Resample the GPS data with uniform sample times.

gpsDataResampled = synchronize(gpsData,SampleTime=dt);

Display the resampled GPS data. Observe that, because the sample time is shorter over the same duration, the resampled GPS data contains significantly more samples.

disp(gpsDataResampled)
  GPSData with properties:

          Name: ''

    NumSamples: 1957
      Duration: 19.5600
    SampleRate: 100.0511
    SampleTime: 0.0100
    Timestamps: [1957×1 double]

      Latitude: [1957×1 single]
     Longitude: [1957×1 single]
      Altitude: [1957×1 single]

    Attributes: []

Load recorded GPS data into the workspace.

load("recordedGPSData.mat","X","Y","Z","timestamps")

Create a Trajectory object by using the loaded timestamps and xyz-coordinates.

traj = scenariobuilder.Trajectory(timestamps,X,Y,Z)
traj = 
  Trajectory with properties:

               Name: ''

         NumSamples: 392
           Duration: 19.5498
         SampleRate: 20.0513
         SampleTime: 0.0500
         Timestamps: [392×1 double]

           Position: [392×3 double]
        Orientation: [392×3 double]
           Velocity: [392×3 double]
             Course: [392×1 double]
        GroundSpeed: [392×1 double]
       Acceleration: [392×3 double]
    AngularVelocity: [392×3 double]

        LocalOrigin: [0 0 0]
         TimeOrigin: 0

         Attributes: []

Plot the trajectory.

plot(traj)

Specify a sample rate to use to uniformly sample the trajectory data.

Fs = 5; % Units are in hertz

Resample the trajectory data with the specified sample rate.

synchronize(traj,SampleRate=Fs)

Display the resampled trajectory object. Observe that, because the sample rate is lower over the same duration, the resampled trajectory object contains fewer samples.

disp(traj)
  Trajectory with properties:

               Name: ''

         NumSamples: 100
           Duration: 19.8000
         SampleRate: 5.0505
         SampleTime: 0.2000
         Timestamps: [100×1 double]

           Position: [100×3 double]
        Orientation: [100×3 double]
           Velocity: [100×3 double]
             Course: [100×1 double]
        GroundSpeed: [100×1 double]
       Acceleration: [100×3 double]
    AngularVelocity: [100×3 double]

        LocalOrigin: [0 0 0]
         TimeOrigin: 0

         Attributes: []

Plot the resampled trajectory.

plot(traj)

Input Arguments

collapse all

Sensor data, specified as a GPSData object, Trajectory object, CameraData object, or a LidarData object.

Reference sensor data, specified as a GPSData object, Trajectory object, CameraData object, or a LidarData object.

New timestamps of the sensor data, specified as an N-element numeric column vector, an N-element datetime array, or an N-element duration array. N is the number of timestamps. The data type of the newTimestamps value and the data type of the Timestamps property of the input sensor data object sensorDataObj must be the same. If you specify an N-element numeric column vector, units must be in seconds.

For accurate synchronization, specify values of newTimestamps in the range of the timestamps in the input sensor data object sensorDataObj.

Data Types: double

Sample time in seconds, specified as a positive scalar, a datetime scalar, or a duration scalar. The data type of the dt value and the data type of the Timestamps property of the input sensor data object sensorDataObj must be the same. If you specify a positive scalar, units must be in seconds.

The function resamples the data with the specified regularly spaced sample time dt over the range of timestamps in the input sensor data object sensorDataObj.

Data Types: double

Sample rate in hertz (Hz), specified as a positive scalar. Fs specifies the number of samples per second.

The function resamples the data with the specified sample rate Fs over the range of timestamps in the input sensor data object sensorDataObj.

Data Types: double

Method for resampling the sensor data, specified as a character vector or string scalar.

Specify one of these methods.

Method

Description

"linear"

Use linear interpolation.

Note

If the input sensorDataObj is a GPSData object or a Trajectory object, the default method is set to "linear".

"spline"

Use piecewise cubic spline interpolation.

"pchip"

Use shape-preserving piecewise cubic interpolation.

"makima"

Use modified Akima cubic Hermite interpolation.

"nearest"

Copy data from the nearest neighbor in the input sensor data.

Note

If the input sensorDataObj is a CameraData object or a LidarData object, the default method is set to "nearest".

"previous"

Copy data from the nearest preceding neighbor in the input sensor data.

"next"

Copy data from the nearest following neighbor in the input sensor data.

"fillwithmissing"

Fill gaps in the output with missing data indicators (for example, NaN for numeric variables).

Output Arguments

collapse all

Synchronized sensor data, returned as a GPSData object, Trajectory object, CameraData object, or a LidarData object.

References

[1] Akima, Hiroshi. “A New Method of Interpolation and Smooth Curve Fitting Based on Local Procedures.” Journal of the ACM 17, no. 4 (October 1970): 589–602. https://doi.org/10.1145/321607.321609.

[2] Akima, Hiroshi. “A Method of Bivariate Interpolation and Smooth Surface Fitting Based on Local Procedures.” Communications of the ACM 17, no. 1 (January 1974): 18–20. https://doi.org/10.1145/360767.360779.

Version History

Introduced in R2024b