How do I find out what specifically is causing the error "Matrix is close to singular or badly scaled" in the sgolay function?

1 次查看(过去 30 天)
I'm using the sgolay function from the Signal Processing toolbox to calculate some derivatives. The function is inside a loop as I feed it different parameters;
[~,g] = sgolay(poly_order, window_length).
However, it seems like for all or almost all of the iterations, I'm getting the warning
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.820809e-39.
> In sgolay (line 114)
where RCOND is not quite the same value each time. Line 114 in the function is
G = Q/R';.
I have a basic understanding of the error; the / command computes an inverse of a matrix, and the matrix cannot easily be inverted. However, I don't know what I can do differently to remove this warning. Can anyone help?

回答(1 个)

Image Analyst
Image Analyst 2021-1-7
What are the poly_order and window_length you're using? I can see that if window_length is less than poly_order + 1, then you would have a problem. For example, you can't fit a parabola (order 2) with only 1 or 2 points. You'd need at least 3 and preferably more.
  2 个评论
Daniel Pollard
Daniel Pollard 2021-1-7
It iterates over different values of those variables. For example, most recently I ran it with poly_order = [2, 3, 4, ..., 30, 31], and window_length = 51. You have to use a window length greater than the polynomial order or it throws an error and stops running.
Image Analyst
Image Analyst 2021-1-7
Yes, like I said.
But the other problem is that if you're trying to fit a 31 order polynomial -- have you ever seen what happens when the polynomial order gets real high? You get all kinds of humps and instabilities between training points. I have no doubt that a polynomial like x^31 would cause problems. You shouldn't go more than about 3 or 4.
Attach your data if you need more help.

请先登录,再进行评论。

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by