# LabVIEW

cancel
Showing results for
Did you mean:

## Re: Sine-fit algorithm

Try this quick draft. (sorry, I did not triple check for units, etc.)

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 11 of 17
(2,008 Views)

## Re: Sine-fit algorithm

Thanks,

I correct my mistake and use your example and the sine-fitting works. The algorithm works fine (good convergence) but it's long (6 seconds to find the solution). It exist solutions or options to speed up the algorithm (and maybe lost in precision) ?

Regards,

Benjamin

Remarks : just a little mistake in "Test sine-fittingMOD2 Folder.zip". It calculate 1/Fsample instead of Fsample, so the value of frequency found by the FFT analysis doesn't works (but in my sample data, Fsample = 1, so there is no difference ! ).

Message 12 of 17
(1,983 Views)

## Re: Sine-fit algorithm

@benj wrote:

I correct my mistake and use your example and the sine-fitting works. The algorithm works fine (good convergence) but it's long (6 seconds to find the solution). It exist solutions or options to speed up the algorithm (and maybe lost in precision) ?

It executes pretty fast on my computer, but you hopefully noticed that the initial estimates from the "detect single tone" would be equally good for all practical purpose. Use those and forget about the nonlinear fitting. It does not add any real value in this case.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 13 of 17
(1,978 Views)

## Re: Sine-fit algorithm

Hi,

I don't want only an estimation of the frequency but I need to fit my data in order to have information about residual rms error between observation-data and fit-data to calculate ENOB (effective number of bits). So, it'is possible to speed-up the fitting alogritm ?

Regards,

Benjamin

Message 14 of 17
(1,961 Views)

## Re: Sine-fit algorithm

In my demo I already show how to calculate the function from the outputs of extract single tone (using call by reference node).

Now use this as the best fit and you can calculate your RMS error (and anyting else) by comparing to the raw data.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 15 of 17
(1,958 Views)

## Re: Sine-fit algorithm

@altenbach wrote:

Try this quick draft. (sorry, I did not triple check for units, etc.)

A bit old post, but anyway, dear @altenbach, thanks for posting this example. On my laptop with i7-6700 and LV2019 the function "Extract Single Tone Information VI" executes for about 2ms for 16k input samples. This is more than 2 orders of magnitude faster than non-linear curve fit (~260ms). For 1.6k data length I get less than 1ms. This is exactly what I need, I will try this on cRIO NI-9035 and hopefully it work for my real-time application.

Message 16 of 17
(240 Views)

## Re: Sine-fit algorithm

Of course extract single tone would be much faster than any iterative fitting procedure, especially if export mode=none (you can look inside to see what it does!). Depending on the needs, a simple FFT followed by R(max), might be sufficient and even faster. 😄

Fitting to a sine function is not the same as extracting a single tone. Giving reasonable initial guesses, fitting will continue to work even if the data consists of only a partial period, so the use case is very different.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 17 of 17
(233 Views)