## Cubic smoothing sline for trajectory approximation

### Mauro Magni (view profile)

on 30 Sep 2019
Latest activity Commented on by Mauro Magni

### Mauro Magni (view profile)

on 4 Oct 2019
How does it work the csaps function and its variations ?
I need simpler explanations and examples if it's what I need for approximation of multiple trajectories in order to get a single nominal one.
Thks

### Raunak Gupta (view profile)

on 3 Oct 2019

Hi,
The Cubic Smoothing Sline is used for fitting a curve to the noisy data. As it is mentioned that there are multiple trajectories involved, I am assuming all represent the same path but with noise in each trajectory. Cubic Smoothing Spline will give a cubic polynomial between successive datapoints based on weightage given to error measure and roughness measure parameter.
I would suggest taking the mean of all datapoints across the trajectories so that only one trajectory remains. Then this trajectory’s path may be calculated with csaps. You may find the following minimum working example helpful.
% Lets assume we have 7 trajectories with 100 datapoints each.
% For example datapoints can be generated using randn
trajectories = randn(100,7);
% Taking mean across the trajectories (that is 2nd dimension) will give a single trajectory
trajectory = mean(trajectories,2);
p = 0.1; % define the error measure weightage (Give path matching closely with datapoint for high value of p)
% p must be between 0 and 1.
x_data = linspace(1,100,100); % Just to have 2D sense of trajectories
path = csaps(x_data,trajectory,p);
fnplt(path); % show the path
% Here path is a structure which contains the polynomial coefficient between each successive pair of datapoint.

Mauro Magni

### Mauro Magni (view profile)

on 4 Oct 2019
I really want to thank you for your help Mr Gupta.