Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Hello,
Could anyone help me with fitting a Gaussian curve to the signals, please?
In the attached worksheet, the function "plane1(k,x1,y1,d,taw)" detects the ultrasonic pressure filed amplitude on two microphones placed on the right and left side of the emitter. The peak of each signal is used to estimate the time of flight (TOF). For more accurate estimation of TOF, I use genfit to fit a Gaussian curve to the signals.
However, the output of the fitting process (result(Data,taw)) does not look right and it sensitively depends on the scanned time range. In the current example, the signals time range do not exceed more than 0.01 s but the Gaussian fit works only when the time range is scanned up to 0.2 s. Is there something wrong?
Any suggestion would be highly appreciated,
Payman
Solved! Go to Solution.
Looks like there is a problem with your gradient vector ff
If you simply replace it by the function to fit
you get a pretty nice fit
Here is the error in your derivative
Thank you very much, Werner, a great help!
My worksheet is now running much smoother.
I ran the worksheet for a wide range of "taw". For some cases, the regression didn't converge and successful fit achieved by increasing the scanning resolution. I understand the point that increasing the resolution may lead to a better fit but I still don't understand the role of the scanning range which is, in this case, should be much larger than the signal's duration.
Do you think it is a normal behavior for the fitting routine?
Not sure what you mean by increasing the scanning resolution and which scanning range should be larger than the signal duration.
Can you provide an example which fails?
Often its just a matter of providing better guess values but I understand that this is a problem when we are talking about automatic batch processing of a larger number of data files.
Hi Werner,
By the resolution, I mean the NN parameter in "plane1(k,x1,y1,d,taw)". Two failure examples are when taw=0.02 and 0.088 that the regression do not converge when NN=100. When NN is increased to 300 then successful fit can be achieved (Please see the attached worksheet).
How would that relate to your original question?
I never looked at the rest of your file and also did not care about your function "plane1". I have no idea what exactly you are doing there.
I simply concentrated on the data matrix "data" and the function type you wanted to fit and noticed that one of your derivatives was wrong and that was the reason "genfit" did not find a satisfactory fit.
I had not looked where "data" would stem from and thought it was measured data.
Whats wrong with your "plane1" ?
I just gave it a try and it seems to be a matter of guess values.
I am not sure how you derive those guess values from Data and tau, but given better initial guesses genfit finds a fit even when NN is 100.
EDIT: I had a closer look at the data you generate.
If NN=100 there are only 5 (!) values of the 100 in the second data column greater than 10^-100.
Guess most are considered to be numerically zero and there is no wonder that no fit can be found.
If NN = 300 there are at least 15 values greater than 10^-100.
maybe you can apply some scaling or even better, zoom in and generate more data where the peak is, not so many useless zero data.
Thank you so much. I now see the two main sources of error in my worksheet. I think the signal with most zero components corresponds to the null of the ultrasonic pulse in that particular direction.
Thanks again for the time you considered on my worksheet.
Payman