From: Danny on
I am trying to learn how to use the sgolayfilt function in MATLAB, and I do not understand the "window length" parameter. Can somebody offer some general guidelines for choosing the proper window length? Should it be close to the length of the vector I am trying to filter? Does it depend if the length of the vector I am filtering is "large" or "small"?

I am receiving some warnings about singular and badly scaled matrices, and it might have something to do with me choosing bad window lengths.

Thank you!
From: Wayne King on
"Danny " <sale.danny(a)gmail.com> wrote in message <hiifcu$k82$1(a)fred.mathworks.com>...
> I am trying to learn how to use the sgolayfilt function in MATLAB, and I do not understand the "window length" parameter. Can somebody offer some general guidelines for choosing the proper window length? Should it be close to the length of the vector I am trying to filter? Does it depend if the length of the vector I am filtering is "large" or "small"?
>
> I am receiving some warnings about singular and badly scaled matrices, and it might have something to do with me choosing bad window lengths.
>
> Thank you!

Hi Danny, are you talking about the frame size argument and how that interacts with the order of the polynomial used in the regression (fitting) process?
Wayne
From: Danny on
Also another question:

Is there anyway to make the endpoints of the filtered vector match the endpoints of the original unfiltered vector? Possibly with the weights?
From: Danny on
> Hi Danny, are you talking about the frame size argument and how that interacts with the order of the polynomial used in the regression (fitting) process?
> Wayne

yes, that is precisely what I am confused about. I have been searching for some background information on the web, but I have not had any luck. Any guidelines that you can provide would be very helpful. Thanks!
From: Wayne King on
"Danny " <sale.danny(a)gmail.com> wrote in message <hiigns$hvk$1(a)fred.mathworks.com>...
> > Hi Danny, are you talking about the frame size argument and how that interacts with the order of the polynomial used in the regression (fitting) process?
> > Wayne
>
> yes, that is precisely what I am confused about. I have been searching for some background information on the web, but I have not had any luck. Any guidelines that you can provide would be very helpful. Thanks!

Hi Danny, It depends on how much smoothing you want to do. The closer the polynomial order gets to the frame size the less smoothing that will occur. Think about trying to fit some noisy signal (data exhibiting abrupt changes in value) with a polynomial. The higher-order polynomial you use, the easier it is to approximate jumps in the signal. If you use a low-order polynomial, then abrupt changes in the signal will not be approximated very well and more smoothing will occur. In general, I think it's best to start with a polynomial order that is fairly low with respect to your frame size.

As an illustration, consider the following:

% Create noisy ECG signal
x = ecg(500)';
x = repmat(x,10,1);
% Noisy ECG signal
x1 = x+0.07*randn(size(x));
plot(x); title('Original ECG Waveform');
figure;
Filt1 = sgolayfilt(x1,1,15);
Filt10 = sgolayfilt(x1,10,15);
plot(Filt10,'r');
hold on;
plot(Filt1,'b','linewidth',2);
legend('Order 10','1st Order');

Hope that helps,
Wayne