LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Differenze between two consecutive peaks to calculate the period of a signal

Hi deuchi,

 

finally you made it to attach a VI with some data…

 

When correcting the previously mentioned items I get this:

check.png

 

I get each peak in your (noisy) data…

(I also marked the AutoCleanup tool with a red arrow!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 11 of 21
(1,085 Views)

If you can measure the frequency over (say minimum) 5 periodes (better 10 or more) you should give the tone detection vi a try to measure frequency and amplitude 🙂

 

If you need a good result (less disturbed by noise) between each periode (or even less than a periode) you should make yourself familar with the correlation function.

simple tone detection.png

hint : if you only measure one channel you can read the DAQ output as a single wfrm...

tone detection comes with different types and accept single wfrm and wfrm arrays

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 12 of 21
(1,080 Views)

Thank you, GerdW for showing me the problem. Now I can see the red dots finally, it was because I forgot the input. But the data I have is like this, and I only need one peak, the highest in value. Any idea how can I fix this by ''playing'' with the peak detector?

 

Henrik_Volkers, I will try to use that VI.

 

 

0 Kudos
Message 13 of 21
(1,073 Views)

In the help file to peak detection you can read how it works (fit a square function)

so if you increase the points width  you are less sensitive to noise but if you fit too much points, you have a systematic error because you fit a square function to a sine shaped peak.

But works fine if you use about the top 5 % of the sine peak. How many points width that will be depends on you sine freq, and samplerate.

However if you know that you have a sine, the tone detection works much better.

For a single periode a (interative) 4 parameter sine fit (f,amp.,phase,offset) would be my choice.

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 14 of 21
(1,050 Views)

Henrik, 

I read the help file. It says that the value should be no more than about 1/2 of the half-width of the peak. How can I calculate the half width of the peak?

For example, I'm using a sine with frequency 5Hz and samplerate 16k. How can I get the value of my width?

 

 
0 Kudos
Message 15 of 21
(1,030 Views)

May I ask how many years of math classes you alredy had?

one periode are 2pi or 360°

how many samples do you have per periode?

Spoiler
Samples per second divided by number of periodes per second  ..... 16k/5 =3.2k 🙂

The help file tell you to take not more than half width of the pulse,

I recommended to only take the top 10% better 5% of the sine peak.  

Do you remember the arcsin function? 

Lets see,  arcsin(0.95) results to ~71°, make it 70 .. remember sine? 90° it the top, so we want 2 * (90°-70°) = 40° of the 360° . How many samples will that be?

Spoiler
3.2k *40/360 ~ 356 sample 😄

 

 

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 16 of 21
(1,027 Views)

here is the systematic error you make with peak detection on a sine peak:

error of peak detection on a sine.png

 

if you know you have sine use tone detection* or a sine fit

 

*) tone detection with at least 5 better more than 10 periodes

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 21
(1,022 Views)

Just realized I took 0 as the starting point. The half peak width also could be seen as the zero crossings.. so half a periode 😄

 

... result into a 2% to low error 😉

 

BUT migth be not too bad if only the time/position is needed ....

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 18 of 21
(1,020 Views)

Henrik, 

I have had analisis classes during the two years of the university, we didn't do this arguments...

But thank you so much for your detailed example. I think I can get the peaks right for now! Can I ask you a last favor, to please attach the vi you used to show my error?

Thank you again for your patience!

0 Kudos
Message 19 of 21
(1,018 Views)

Basic trigonometry should have been covered before you are allowed to enter university 😉

I was tempted to not post the vi to force you to learn basic math (and some LabVIEW) ... however

Here we go ....

error of peak detection on a sine2.png

 

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 20 of 21
(986 Views)