Using Savitzky-Golay filter in real time simulink model

50 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.

Accepted Answer

Sudarshan Kolar
Sudarshan Kolar on 28 Aug 2017
Hi Vishal,
I am attaching a demo model for your reference. Hope that helps.
Note:
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
  4 Comments
DN
DN on 15 Dec 2018
Sudarshan, I think you are missing the point in your answer....it throws an error and question clearly states for code generation
Error:
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:
"sgolayfilt(u,3,11)"
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)

Community Treasure Hunt

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

Start Hunting!