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

1 visualización (últimos 30 días)
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 comentario
Daniel Pollard
Daniel Pollard el 7 de En. de 2021
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.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 7 de En. de 2021
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 comentarios
Daniel Pollard
Daniel Pollard el 7 de En. de 2021
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 el 7 de En. de 2021
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.

Iniciar sesión para comentar.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by