Thank you Cristophe for your comments and your link for the Savitzky-Golay smoothing ,

Here is a simple code using lsq-splin() on your example data I played with. Nothing spectacular - just followed the Scilab Help, but I hope someone will find it useful.

Regards,
Radovan

//-----------------------
xd=Xinit;  yd=Yinit;
a=min(xd);  b=max(xd);

n  =  20;  // change the number for better smoothing
x  =  linspace(a,b,n)';

// use spline
[y,  d]  =  lsq_splin(xd,  yd,  x);

// plot - points, smoothing line
ys  =  interp(xd,  x,  y,  d);
scf(1001);
plot2d(xd,[yd  ys],style=[-2  5],  ...
       leg="gausian peek@smoothing curve")
p=get("hdl"); p.children.thickness = 3; xtitle("smoothing curve")
show_window()
// plot derivatives
scf(1002);
plot2d(x,d,style=5,leg="derivatives")
p=get("hdl"); p.children.thickness = 3; xtitle("derivatives")
show_window()
//end


On 3/24/2014 9:41 AM, Dang, Christophe wrote:
Hello,

De la part de Samuel Enibe
Envoyé : samedi 22 mars 2014 19:01

May I know the best way to determine dy/dx for the data set.
The best way is the way that gives you accurate results in the minimal time.

If you have an analytical model, the best is to fit it and then derive the 
function, with numdiff().

You can otherwise perform a Savitzky-Golay smoothing, which also gives you the 
derivative, see e.g.
https://commons.wikimedia.org/wiki/File:Savitzky-golay_pic_gaussien_bruite.svg?uselang=en

If you excpect a very low noise, then you can assume the points are at their 
"exact" position. Then, if you suppose the second derivative is small, you can 
use a simple slope calculation such as

yprime = diff(y)./diff(x)
plot(x(1, $-1), yprime)

which is the fastest method, but also the most sensitive to noise.

If the second deriative is not negligible, you may use the spline interpolation 
proposed by Radovan, but you may just use the step

yprime = splin(x, y)
plot(x, yprime)

Best regards.




---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com

<<attachment: fig1.png>>

<<attachment: fig2a.png>>

<<attachment: fig2b.png>>

_______________________________________________
users mailing list
[email protected]
http://lists.scilab.org/mailman/listinfo/users

Reply via email to