Problems with calculating Second derivative and SG smoothing
3 views (last 30 days)
Show older comments
Hi,
I am relatively new to Matlab and have encountered some problems with generating the same results as I got using another programme (Origin 8.6). The problem lies between calculating the second derivative and the S-Golay smoothing.
Currently I use the following code for the differentiation and smoothing:
TwoDerv = diff(Data(:,2),2);
TwoDervSG = sgolayfilt(TwoDerv, 2, 17)
This code generates data that looks like the following:

The previous programme I used created data that looked like this (when usng the same parameters):

I have tried varying the smoothing window, and still do not get the correct results. it appears to be smoothing correctly in the x axis, but incorrectly in the y axis.
Any help would be appreciated. Thanks,
Liberty
1 Comment
Azzi Abdelmalek
on 21 Jan 2013
Edited: Azzi Abdelmalek
on 21 Jan 2013
Liberty, the png format is not allowed, use instead, jpg format for your images.
Answers (2)
Thorsten
on 21 Jan 2013
Edited: Thorsten
on 21 Jan 2013
diff(x, 2) is just one way to numerically approximate the derivative. Origin may use a different method.
The result by Origin is obviously more smooth, so may be Origin has combined taking the derivative with some smoothing operation. What is striking are the y values that can only be smaller for a smoother signal, but are actually larger in Origin figure (or is there a 10-<number> scaling factor of the y-axis missing in the Origin figure)?
Shashank Prasanna
on 21 Jan 2013
Liberty, to answer the more general question of approximating derivatives, there are numbers of ways and the simplest as Thorsten mentioned as well would be to take successive difference as you have done above. A more popular method used extensively is called Automatic Differentiation. Although I haven't used this particular implementation, you can try it out:
That said there is probably no way to compare results definitively unless we can find out what Origin is doing and repeat the same in MATLAB.
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!