Smooth a curve using sgolayfilt

20 views (last 30 days)
navan on 31 May 2015
Commented: Image Analyst on 5 Jun 2015
I would like to smoothen my curve using Savitzky-Golay filtering.That is y = sgolayfilt(x,k,f,w,dim)
1)Can anyone say what is (x,k,f,w,dim) indicates in sgolayfilt smoothing ? (I read the matlab link but didn't understand) (<>)
I appreciate an answer with an example.
2)My matrix dimension is very big (200000*100),is there any other smoothing method, which someone can use in a simple way
Image Analyst
Image Analyst on 31 May 2015
What does that mean? The meaning is that that expression is a function call to smooth x. k is the polynomial order, and f is the window width. You can ignore the other two. Did you see my answer? Just play around with the parameters and learn how their values affect the output signal.

Sign in to comment.

Answers (2)

Jan on 31 May 2015
Edited: Jan on 31 May 2015
Your matrix is not "very big" because it matchs in the memory of modern computers without any problems.
The documentation of sgolayfilt is exhaustive. The statement that you did not understand it does not allow to be more precise at any specific point. I'm very sure that you do understand e.g. the first argument, which is simply the input signal. So it would be much more efficient, if you ask a specific question. Repeating the text of the documentation in other words does not seem to be useful. But let me try it:
x: Your signal
k: Order of the polynomial used for smothing, e.g. for 2 a parabola is used.
f: number of points used to fit the local polynomial
w: Optional, used for weighting
dim: If your data is a matrix, you can smooth over the 1st or 2nd dimension
The Savitzki-Goplay filter uses f neighboring elements and fit a polynomial of order k to these points. Then the point at the center of the f pointa is replaced by the value of the polynomial of this point. Therefore the smoothing is stronger for higher f and smaller k.
Example: k=1, f=21: A straight line is fit to neighboring 21 points in a least-square sense. Then the 11th point is replaced by the center of this line. This is performed for each point, except for the margins, where you cannot find 21 neighboring points and a weaker smothing must be applied.
The weighting w can be applied to modify the fit, e.g. to consider the points near to the center with a higher priority.
You will find many other locations in the net where this filtering is explained with examples and animations etc. Simply ask your favorite internet search engine.
  1 Comment
Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh on 5 Jun 2015
Quite a comprehensive explanation.

Sign in to comment.

Image Analyst
Image Analyst on 31 May 2015
Image Analyst
Image Analyst on 5 Jun 2015
I agree. Also nice would be a button on code blocks in the answers where we could click it and all the code in the code block would go into the clipboard, and then we could simply go to MATLAB and paste it in. It would make it easier to test code that people posted.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!