From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Non-linear curve fitting problem: the matrix is singular

Dear all community members,
I'm a new Labview user and I'm finding an issue difficult to understand for someone not very skilled... I've attached the main VIs I'm using.

I have to fit two sets of data with a phase modulated sine function, in particular one of the two signal is supposed to have a frequency which is twice the frequency of the other.

I've prepared a model function PM-sine-model which is written in the form f(t)=A+B*sin(C*t+D*cos(E*t+F)+G) which at a first step can be easily reduced to a sine function f(t)=A+B*sin(C*t+G) fixing D=0. I'm using this model with the Constrained non-linear fit VI sending for the two sets of data the time array, some guess parameters and also fixing some boundaries thanks to a pre-elaboration of the arrays of signals (envelope removed, average shifted to zero and amplitude normalized to +/-1): A is fixed to 0, B is fixed to 1, D at a first stage is fixed to 0 (and also E and F). Thus only C and G are the two free parameters for the optimization algorithm.

Unfortunately, even if the guess parameters provides two sine function which almost fit the data when the Fit button is pressed the Vi stops due to an error related to the singularity of the matrix difficult for me to understand.

Looking on other posts I've seen that this may be related to different scaling factors between the parameters, but I've already rescaled the time axis and normalized the datasets so the order of magnitude of the parameters is similar. Also I try starting with reasonable guess parameters and imposing reasonable boundaries to my opinion.

Do you have any suggestions?

If there is a "simple" error done by me I say sorry in advance!

 

Best regards.

Download All
0 Kudos
Message 1 of 8
(1,068 Views)

Can you "save for previous"? I don't have LabVIEW 2021 here.

 

0 Kudos
Message 2 of 8
(1,056 Views)

Dear altenbach,
Thank you for your answer.

I've saved the VIs for previous versions (LV2012), are you able to open it now?

 

Best regards.

Download All
0 Kudos
Message 3 of 8
(1,053 Views)

The model is still in 2021.

0 Kudos
Message 4 of 8
(1,041 Views)

Sorry, try with the new uploade VIs.

Download All
0 Kudos
Message 5 of 8
(1,037 Views)

Sorry, but one basic issue is that you don't even have a wait in your toplevel loop.

 

  • Do you have a link to a website that explains the experiment and theory?
  • You have two separate fits. Are the two datasets related and shouldn't you do a global fit of both traces?
  • Obviously, you have a clear change in frequency across each trace (fastest in the center), so the inner component should not be zero.
  • Constraining a phase to +/- pi is a bad idea. What if your starting point is near the edge and the correct value is folded right across the limit. It will never be able to get there.
  • Not sure why you use sin and cos, both are the same, differing only in phase.
  • Fitting periodic signals require very good starting values, else you might fit for an alias frequency or get trapped in local minima instead.
  • Have you looked at the covariance and parameter correlations?
  • ...
0 Kudos
Message 6 of 8
(978 Views)

Dear altenbach,

-> You are right, I've added a "wait" in the loop.
-> The two original signals are two interferometric signal obtained from optical michelson interferometers at two different laser wavelengths, one the second harmonic of the first. They measure the same object displacement on the same time scale, thus as you supposed the next step should be to fit the two signals with a global fit imposing the constraint of the two frequencies (one to be twice the other). Actually, at a first stage I'm interessed in fitting with a "sinusoidal-like" function one of the signals. From basic theory an ideal interferometric signal is cosine function, but due to the moving mirror hysteresis it can be modeled as a phase-modulated cosine function (as you also noticed in your third point). So at the begininng I've implemented the model as a phase-modulated sine (switch it to a cosine seemed to me just a matter of phase shift). The thing is that even simplyfing the model making it a sine function fixing to zero the "central" parameters of the guess array the VI crashes or it stops to a local minimum, even if the central part of the signal if very close to a sine or cosine function. Any suggestions would be very helpful.

-> You are right, I've changed the costraints to +/- 2pi. Also on this side do you have any suggestions?

-> Is there an easy way to understand when the starting parameters are "good" to avoid stopping in a local minima?

-> Most probably there is a correlation between the parameters which makes the VI crash, but if the signal is close to a sine or cosine function and I use only two parameters (frequency and phase) of a sine function with a guess that seems "reasonable" it is difficult for me to understand why they should be correlated.

Otherwise, let's change the perspective of the problem: if you have to fit the same data of the VI knowing that they should be a "cosine" function probably modulated in phase or in frequency, how do you proceed? Is there a way to fit such data unambiguously?

Any suggestion is warmly welcome, even by  changing the VIs themselves.

 

Thanks in advance.

Download All
0 Kudos
Message 7 of 8
(969 Views)

Using linear sine fitting methods? 

 

Search points: IEEE-STD-1057

 

P. Händel, Evaluation of a standardized sine wave fit algorithm, 2000 
IEEE Nordic Signal Processing Symposium, Kolmården, Sweden, 13-15 June 
2000, pp. 453-456, 
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.35.3486

 

I found this one helpful:https://www.ippt.pan.pl/repository/open/o3063.pdf

I extended the matrix (14) to do a LMSE fit on n correlated frequencies in two (+x)  channels

 

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 8 of 8
(935 Views)