smooth
Description
smooth(
smooths the trajectory data
in the input trajectory
)Trajectory
object trajectory
using a Savitzky-Golay filter.
smooth(
specifies options using one or more name-value arguments. For example,
trajectory
,Name=Value
)Method="movmedian"
smooths the trajectory using the moving median
filter.
returns a smoothed trajectory object smoothedTrajectory
= smooth(___)smoothedTrajectory
using any
combination of input arguments from previous syntaxes.
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.
Examples
Smooth Trajectory in Trajectory Object
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);
Plot the trajectory object.
plot(traj)
title("GPS Trajectory")
Smooth the trajectory in the trajectory object.
smoothedTrajectory1 = smooth(traj)
smoothedTrajectory1 = 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 smoothed trajectory.
plot(smoothedTrajectory1)
title("Smoothed Trajectory Using Savitzky-Golay Filter")
Smooth the trajectory using the moving average filter.
smooth(traj,Method="movmean")
Plot the trajectory smoothed by the moving average filter.
plot(traj)
title("Smoothed Trajectory Using Moving Average Filter")
Input Arguments
trajectory
— Trajectory with timestamps and waypoints
Trajectory
object
Trajectory with timestamps and waypoints, specified as a Trajectory
object.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: smooth(trajectory,Method="movmedian")
smooths the trajectory
using the moving median filter.
Method
— Smoothing method
"sgolay"
(default) | "movmean"
| "movmedian"
| "gaussian"
| "lowess"
| "loess"
| "rlowess"
| "rloess"
| "custom"
Smoothing method, specified as one of these options:
"sgolay"
— Savitzky-Golay filter, which smooths according to a quadratic polynomial fitted over each window. This method can be more effective than other methods when the data varies rapidly."movmean"
— Moving average filter, useful for reducing periodic trends in data."movmedian"
— Moving median filter, useful for reducing periodic trends in data when the data contains outliers."gaussian"
— Gaussian-weighted average filter."lowess"
— Window-based linear regression filter. This method can be computationally expensive, but results in fewer discontinuities than other methods."loess"
— Window-based quadratic regression filter. This method is slightly more computationally expensive than"lowess"
."rlowess"
— Window based robust linear regression filter. This method is a more computationally expensive version of the"lowess"
method, but it is more robust to outliers."rloess"
— Window-based robust quadratic regression filter. This method is a more computationally expensive version of the"loess"
method, but it is more robust to outliers."custom"
— Specify a custom filter. When you use"custom"
, you must specify a custom function by using theSmoothingFcn
name-value argument.
SmoothingFactor
— Window size factor
0.25
(default) | scalar in range [0, 1]
Window size factor, specified as a scalar in the range [0, 1]. Generally, the
value of SmoothingFactor
adjusts the level of smoothing by scaling
the window size that the smooth
function determines from the
entries in the input trajectory object trajectory
. Values near 0
produce smaller moving window sizes, resulting in less smoothing. Values near 1
produce larger moving window sizes, resulting in more smoothing. In some cases,
depending on the entries that smooth
uses to determine the window
size, the value of SmoothingFactor
might not have a significant
impact on the window size.
Degree
— Savitzky-Golay degree
2
(default) | nonnegative integer
Savitzky-Golay degree, specified as a nonnegative integer. To use this name-value
argument, you must specify Method
as "sgolay"
.
The value of Degree
corresponds to the degree of the polynomial in
the Savitzky-Golay filter that fits the data within each window.
The value of Degree
must be less than the window size for
uniform sample points. For nonuniform sample points, the value must be less than the
maximum number of points in any window.
SmoothingFcn
— Custom smoothing function
function handle
Custom smoothing function, specified as a function handle.
The function must support this syntax:
smoothedWaypoints = smoothingFunction(waypoints),
The
waypoints
input argument is specified as a real-valued N-by-3 matrix. N is the number of waypoints. Each row represents the x-, y-, and z-coordinates of a waypoint.The
smoothedWaypoints
output argument is returned as a real-valued N-by-3 matrix. N is the number of waypoints. Each row represents the x-, y-, and z-coordinates of a waypoint.
Note
You must set the Method
name-value argument to
"custom"
to use the SmoothingFcn
name-value argument.
Output Arguments
smoothedTrajectory
— Smoothed trajectory
Trajectory
object
Smoothed trajectory, returned as a Trajectory
object.
Version History
Introduced in R2024b
See Also
GPSData
| Trajectory
| CameraData
| LidarData
| recordedSensorData
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)