MATLAB: [Using the fit funcion type smoothingspline] How to get the peaks of a fiting curve found by the command ‘fit’

curve fiteliminate noise signalfindpeakssmoothingspline

Hello everybody. I'm new in MATLAB and I have a problem. I have a table (100 row x 2 col) of data and this data have some noise. To eliminate the noise I use the fit function like that:
f = fit(X_axis,Y_axis,'smoothingspline','SmoothingParam',0.9999907449908739);
I can plot the curve fit using this
plot(f,X_axis,Y_axis)
Now I need to get the peaks of the resulting curve fit. I try the function 'findpeaks(f)' but it doesn't work.
Has somebody a idea to solve this problem? Thank you all,

Best Answer

Data=load('Held_Roll_T15_D147_BK2Y90_a2_1.txt');
X=Data(:,1);
Y=Data(:,2);
[X_axis,Index]=unique(X,'rows');
X_axis(end)- X_axis(end-1);
Y_axis=Y(Index);
figure()
f = fit(X_axis,Y_axis,'smoothingspline','SmoothingParam',0.9999907449908739);
%
y = f(X_axis) ;
plot(X_axis,Y_axis,'.b')
hold on
plot(X_axis,y,'r') ;
legend({'data'; 'fit'})
% Find peaks
[pks,idx] = findpeaks(y);
figure
hold on
plot(X_axis,y,'r') ;
plot(X_axis(idx),y(idx),'V')
legend({'fit', 'peaks'}) ;