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: 

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

Hello guys, I'm doing a program (for my research activity) which it's supposed to calculate the distance between two peaks of a signal (in order to find the period) while the window is scrolling. I'm new to labview actually and I read all the previous discussions of this topic but I can't seem to find a solution. Here I am attaching the vis so can you please help? 

Thank you in advance. 

0 Kudos
Message 1 of 21
(2,970 Views)

Hi Deuchi,

 

I assume this code is not working how you want, but can you explain what you expect and what you observe? I see you calculating a difference in peak location outside of the while loop, so this will only run once when your program stops. If you want this to run as you acquire your signal you need to put it inside your loop.

0 Kudos
Message 2 of 21
(2,934 Views)

I expect the time difference between two peaks, I acquired a sinus signal of 1hz so I expect the distance between the peaks to be 1, and to stay like that. I tried to put it inside the loop but the difference keeps changing and I don't know why... 

I put the second one outside the loop because I thought I could get a difference between peaks once the cycle stopped. But I keep getting strange values like very very small numbers.

0 Kudos
Message 3 of 21
(2,931 Views)

Can you save the VI with data in the indicators so we can see your data? Once you collect the data, you can either copy the indicator, then make it a constant, or set the value as default.

0 Kudos
Message 4 of 21
(2,919 Views)

I'm attaching the VI along with the datas I screenshoted. I think it works the way I did the code. The only problem I am having are the peaks because it seems my VI is taking a lot of peaks for a period, and I just want one, and in the second graph they don't seem to appair at all. 

Download All
0 Kudos
Message 5 of 21
(2,889 Views)

Hi deuchi,

 

you failed in including data in your graphs, so we cannot try to analyze your data…

 

3 simple steps:

Run your VI to show some data in the graphs, then stop it.

Edit menu -> make current values default

Save the VI and attach it here!

 

(I also prefer a 4th step: use AutoCleanup before saving!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 21
(2,883 Views)

Ah sorry, I'm new to labview so I didn't know what to do. I did what you told me so I will attach the VI here. Thank you.

0 Kudos
Message 7 of 21
(2,880 Views)

Hi deuchi,

 

it's the same VI as before, your "Analog waveform" still shows no data…

 

Comments on the VI:

Your (obs 2010) PeakDetector is missing it's input data.

You still don't use AutoCleanup.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 21
(2,875 Views)

Sorry again.. I hope it works this time. I still don't know how to do the AutoCleanup though.  

I attached the width in the peak detector. 

Thank you for your patience!

0 Kudos
Message 9 of 21
(2,872 Views)

My problem is that I get a lot of values (the time positions) for the same peak, and another problem is that it doesn't show all the values of other peaks in other time. 

I want to build an array to store all the positions in time, in order to make the difference between the first member and the one after. 

 

0 Kudos
Message 10 of 21
(2,867 Views)