MATLAB Answers

Using Savitzky-Golay filter in real time simulink model

55 views (last 30 days)
I want to use Savitzky-Golay filter in my simulink model. This function is available in matlab as this outputsignal=sgolayfilt(inputsignal,order of filter,window size);
The way it works is as follows from some reading in the internet: It uses least squares to regress a small window of your data onto a polynomial, then uses the polynomial to estimate the point in the center of the window. Finally the window is shifted forward by one data point and the process repeats. This continues until every point has been optimally adjusted relative to its neighbors. It works great even with noisy samples from non-periodic and non-linear sources.
I am unable to use this function in simulink. Can this be achieved in simulink using a matlab function block?
Note: I would like to generate embedded code with this,hence the need to do it in simulink.


Sign in to comment.

Accepted Answer

Sudarshan Kolar
Sudarshan Kolar on 28 Aug 2017
Hi Vishal,
I am attaching a demo model for your reference. Hope that helps.
1. Since 'sgolayfilt' requires a vector input, the buffer block is used to collect the scalar inputs and present it as a vector to the Matlab Function block.
2. Also, the outputs are displayed using vector scope instead of normal scope.
Regards -Sudarshan


Show 1 older comment
DN on 15 Dec 2018
Sudarshan, I think you are missing the point in your throws an error and question clearly states for code generation
The function 'sgolayfilt' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation.
Function 'MATLAB Function' (#23.33.51), line 3, column 5:
Launch diagnostic report.
Component: MATLAB Function | Category: Coder error
Errors occurred during parsing of MATLAB function 'MATLAB Function'
Have, you considered HDL coder blocks that would be compatible, this will then easily generate into code and can be synthesised ?

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Translated by