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

조회 수: 6 (최근 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
Daniel Pollard
Daniel Pollard 2021년 1월 7일
If anyone sees this, I have discovered the command
warnings off;
which basically does what I wanted, but obviously that doesn't exactly solve the problem.

댓글을 달려면 로그인하십시오.

답변 (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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by