LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I want my spectrum analysis VI run faster

Like mcduff said, if you have a clean well-defined signal, you can identify a key characteristic (such as a zero-crossing or possibly some other threshold crossing) that occurs on every cycle.  Then some combination of hardware / software can deal with this in the *time domain*, resulting in both high frequency resolution and pretty-much real time response.

 

Specifically for the 0.1 mHz you mention, that translates as the ability to discriminate one ten-thousandth of a cycle per sec.  So the ability to discriminate a *time-domain* phenomenon is based on a time resolution that's at least 10000 times finer than the frequency of interest.   If it were 100 Hz (0.01 sec per cycle), you'd need to resolve something like a zero-crossing time down to the 10e-6 = 1 microsec level.  With a clean signal, that's pretty do-able.

 

Summary: because you led off these two threads with freq domain analysis, most responses and comments assumed there was a good reason for it.  It now sounds to me like you really should be focused on *time domain* analysis because your signal's pretty clean and you need precision frequency measurements in near-real-time.  Presumably, the freq can drift a little bit and you want to see such things ASAP.

 

 

-Kevin P

 

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 11 of 17
(857 Views)

@Bob_Schor wrote:

@mcduff wrote:

I keep wondering and searching what algorithm is in the some of special frequency measurement device(which can rapidly gives you the current value of frequency with extremly high resolution).


Depends on your signal. Assume you have a clean sinusoidal signal, you can count zero-crossings to get the frequency. Assume you have a clean square wave signal, you can count the rising or falling transitions to determine the frequency accurately and fast.


Assume two "perfect square waves", one of 1 Hz and the other of 1.01 Hz.  Start them off in phase and count the rising transitions.  They will remain the same for 99 seconds (being 1, 2, 3, ... 99), but the last second the faster one will register 2 counts (to go to 101) while the slower one registers only 1 (to go to 100).

 

Bob Schor


Could not edit my previous reply, think I understand now.

 

Count was a bad choice of words, measure the period between rising/falling etc should have been stated to be clearer.

 

mcduff

0 Kudos
Message 12 of 17
(847 Views)

to measure the line frequency with 1mHz resolution you don't need 1ks (or 100s for 10mHz) 🙂

the trick is a sine fit. Or use tone detection vi.

here

I posted a vi (and more on tone detection vi) that uses the soundcard to measure the line frequency. Try it 🙂  A coarse prefiltering of the line voltage helps with a bandpass (or lowpass) helps. I abused a headphone plugged into the mic input and grapped the line noise near a transformer (old style powersupply). Worked suprisingly well.

Remember that the crystal in the soundcard isn't that well ... since you have two channels you can track the pps signal from a ~10 bucks GPS module and use a GPS disciplined soundcard 😄

 

 

 

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 ǝɥʇ'


Message 13 of 17
(840 Views)

here are some pics:

https://forums.ni.com/t5/Multifunction-DAQ/capture-electric-frequency-using-a-computer/m-p/1099383#M...

 

hint: IF you had searched the forum for these topics you migth have found it by your own....

 

OMG that post are from 2010 !

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 14 of 17
(832 Views)

As usual, Henrik, you are right -- if you have a clean signal and a "reasonable" (and don't ask me what that means!) number of data points, and you use a "curve-fit" algorithm where frequency can vary smoothly (as opposed to doing Fourier Analysis, where the "analysis" frequency is closely related to the sampling frequency), you can do a very close fit.  But such (non-linear) fitting is typically slow compared to a Fast Fourier Transform, and the last word in the OP's title is "faster" ...

 

Bob Schor

 

P.S. -- I should mention that Henrik's solution didn't even occur to me, I was so focused on the FFT-ness of the question ...

P.P.S. -- The above comments also apply to McDuff's "corrected" solution.  But if we didn't have to worry about Noise, a whole lot of things would be simpler.  I think the idea is that one can fit in the Time domain (using convolution) or frequency domain (using two FFTs, multiplication, and an inverse FFT), and for many "real" problems, the frequency domain is faster, but imposes these restraints on the parameters in and parameters out.

0 Kudos
Message 15 of 17
(821 Views)

@Bob_Schor wrote:

As usual, Henrik, you are right -- if you have a clean signal and a "reasonable" (and don't ask me what that means!) number of data points, and you use a "curve-fit" algorithm where frequency can vary smoothly (as opposed to doing Fourier Analysis, where the "analysis" frequency is closely related to the sampling frequency), you can do a very close fit.  But such (non-linear) fitting is typically slow compared to a Fast Fourier Transform, and the last word in the OP's title is "faster" ...

 

Bob Schor

 

P.S. -- I should mention that Henrik's solution didn't even occur to me, I was so focused on the FFT-ness of the question ...

P.P.S. -- The above comments also apply to McDuff's "corrected" solution.  But if we didn't have to worry about Noise, a whole lot of things would be simpler.  I think the idea is that one can fit in the Time domain (using convolution) or frequency domain (using two FFTs, multiplication, and an inverse FFT), and for many "real" problems, the frequency domain is faster, but imposes these restraints on the parameters in and parameters out.


@Hendrik

Your solution is nice, but it does not fit a sinusoidal signal, it uses a FFT, and 2s of data to get the frequency along with a Hanning window. If you dig into the subVIs it uses the 3 dominant frequency bins to determine the "exact" frequency. The subVIs are hard to follow since they are using sequence structures!(These are NI's code!) Me thinks the exact frequency fit will depend on the amount of data you collect, or maybe better words would be the uncertainty in the frequency fit, as someone wise said measurements without uncertainties are useless.

 

@Bob

Count was a bad word, but if I want to nitpick,

Simple Square Wave

Sign[Sin[2 pi 1 0]] = 0 at 1 Hz at 0 s

Sign[Sin[2 pi 1.01 0]] = 0 at 1.01 Hz at  0 s

 

Sign[Sin[2 pi 1 1]] = 0 at 1 Hz at 1 s

Sign[Sin[2 pi 1.01 1]] = 1 at 1.01 Hz at 1 s

 

So in 1 s I would count 2 rising transitions for a 1.01Hz square wave, and only 1 rising transition for a 1 Hz wave Smiley Wink

 

mcduff

0 Kudos
Message 16 of 17
(815 Views)

In the first post already nearly 9 years ago, I already mentioned that a linear sine approximation method (SAM) should beat the FFT aproach of the tone detection.

AND YES ... a measurement needs a MUB!

 

One thing in common for tone detection and a SAM: THD in the signal is no problem 🙂  just noise.  You simply use all samples for the measurement of one frequency (and amplitude and phase)

 

ANd yes I updated every 2 s but no reused data and I sitll would  claim <20mHz 🙂 

and still room for improvements. That was Q&D  lab fun 😄

 

You can do tests with analytical data (mix up some sines (base +THD+Noise, ratios from real measurements) and do a little MonteCarlo ...

 

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 ǝɥʇ'


Message 17 of 17
(809 Views)