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: 

Nonlinear Curve Fit with a sinusoid from oscilloscope

Solved!
Go to solution

Hello, I was trying to performe a nonlinear curve fit of a sinusoid that I get from my oscilloscope. I thought it was kind of simple, I looked at some of the examples and I read some related topics on this forum (this is the closest one to my goal in my opinion: http://forums.ni.com/t5/forums/v3_1/forumtopicpage/board-id/170/thread-id/789317/page/1 ) however it did not work.

My goal is basically to reconstruct a sinusoidal curve when the signal is not completely visible in the display (or let's say to calculate my maximum/minimum value and the zero-crossing.

I attach a VI with three versions of the same 10GHz signal, the first one where the signal is completely visible, the second one where it's out of scale in the X axis (not the whole period is visible) and the 3rd one where the Y axis (amplitude) is out of scale.

 

I hope you can help me! Thanks!

Thank you!

0 Kudos
Message 1 of 10
(3,555 Views)
  • You probably want to use four parameters (amplitude, frequency, phase, offset) except for the first dataset.
  • You need to clean up the last dataset to eliminate the values that are dozens of order of magnitude higher. (10e35!)
  • Your initial guesses need to be much better (there is an infinite number of local minima of almost equally good solutions consisting of alias frequencies.

Here's an example for the first dataset:

 

 

 

And here it is for the second dataset (after adding a fourth parameter):

 

 

 

I would also recommend a VI model. Formula strings are relatively inefficient.

 

Download All
0 Kudos
Message 2 of 10
(3,527 Views)

And here's the last one (after cleaning up the data). Make sure to use a continuous x-ramp to simulate the guess and best fit.

 

0 Kudos
Message 3 of 10
(3,520 Views)

Can you please attach the VI that did that? I have LabView 2015.. Thank you so much!

0 Kudos
Message 4 of 10
(3,514 Views)

@cassaniti wrote:

Can you please attach the VI that did that?


Did what?

You can clean up the third dataset e.g. as follows:

 (this retains only data points where y is between -1 and 1)

 

 

Sorry, it is 3am here. I need to sleep now.

0 Kudos
Message 5 of 10
(3,508 Views)

This works fine for the first and the second case, but for the third one it doesn't. What am I doing wrong? How do I create a VI model to increase efficency?

0 Kudos
Message 6 of 10
(3,503 Views)
Solution
Accepted by topic author cassaniti

You turned the entire LabVIEW program into Gibberish.

  • Why are you filtering so specifically instead of using my suggestion?
  • For the fit, you need to use the filtered x and y, and not the ramp data for x.
  • Why are you no longer showing the guess?
  • You still need to use the model to generate the best fit without missing data.

 

Try this...

 

Download All
0 Kudos
Message 7 of 10
(3,478 Views)

Thanks a lot! I am filtering so specifically because those are the values that my oscilloscope gives me when the values are out of scale, while I might have a signal with (useful) values greater than 1V. And you're right, I was confused between the use of the ramp and the use of the guess.

Anyway I was wondering if with the VI Model the guess would be faster, because the fit takes a couple of seconds and I'm using this approach in order to reduce the whole time needed to run a complex algorithm..

0 Kudos
Message 8 of 10
(3,463 Views)

Pl post this VI in  2012 version

Ajay Shankar
0 Kudos
Message 9 of 10
(2,932 Views)

@AjayShankar wrote:

Pl post this VI in  2012 version


Here's a downconversion to 2012.

 

(And yes, the VI is just a very rough draft. For significantly better performance, it should be rewritten using a VI model and analytical partial derivatives. Also, the filtering loop could use an "in range & coerce" to remove other blatant outliers.)

0 Kudos
Message 10 of 10
(2,923 Views)