I am looking at the Savitzky-Golay (SGOLAY) filters to try and remove anomalous spikes from experimental data. To do so, I need to ignore the anomalous point and want to use a Savitzky-Golay filter to approximate the new point value. I found that the function rejected any weighting vector that had a zero element. Looking at the code, I do not understand why this restriction is necessary. Is this just an overly strict error message or does the algorithm break down in some way if a zero weighting is given to a point? If I remove the error checking that checks for zeros in the SGOLAY and SGOLAYFILT functions, the results seem reasonable. Is there any reason why the error checking on line 45 of SGOLAYFILT is: if min(W) <= 0, error('All the elements of the weight vector must be greater than zero.'), end instead of: if min(W) < 0, error('All the elements of the weight vector must be greater than zero.'), end (Note the replacement of "<=" with "<")
Kshitij Singh answered .
2025-11-20
[b,g]=sgolay(3,5,[1,0,0,0,1]);
you will run into matrix singularity issues as indicated by the following warning messages:
Warning: Matrix is singular to working precision. (Type "warning off MATLAB:singularMatrix" to suppress this warning.) > In I:\1186207\sgolay.m at line 59 Warning: Matrix is singular to working precision. (Type "warning off MATLAB:singularMatrix" to suppress this warning.) > In I:\1186207\sgolay.m at line 59
A = C'*D*C