From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, 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: 

peak counting

Solved!
Go to solution

Hi!

 

I think this is very simple question and might be easy solution but I cannot find it. I have square wave and I'm counting peaks (max and min) and summarize them with add function. This structure is inside while loop so when another iteration takes place it automatically deletes former values and begins counting all over again. I would like program to count peaks until I press stop.

 

I have attached program and the mention structure is in the bottom part of it.

 

Thanks for all the help!

 

Jure

0 Kudos
Message 1 of 9
(3,567 Views)

At 1387 KB, I don't want to open your VI, but I can suggest a few things.

 

Look into Peak Detector.vi or Peak Detector PtByPt.vi

 

Another way since charts have a History, you can read the History (which is an array) with a Property Node and get the array min/max. If you are getting the min/max over a very large dataset, you'll need to store the min/max values into another array, then at the end of the acquisition, perform a min/max on those value. This is necessary because the History length is finite, defaulting to 1024 samples. The same issue occurs with Peak Detector PtByPt.vi - the amount of data you can analyze is finite, and/or constantly overwritten, so storing data into shift registers is inevitably something you have to "get good at" to do this kind of thing on large datasets (i.e. long acquisitions or very fast sampling).

 

All of this assumes you are looking for amplitudes. You did say Square Wave so maybe you meant period?

Richard






0 Kudos
Message 2 of 9
(3,539 Views)

Hi Jure!

 

As far as I understand, what you would like to do is sum the 'count' and 'count 2' in consecutive runs of the lower while loop.

 

You can accomplish this by using shift registers to store values between loop iterations.

 

If you have further questions, don't hesitate to ask 😉

Best regards,
Jano
0 Kudos
Message 3 of 9
(3,526 Views)

Thanks for answers!

 

I would like to use shift registers, but on example given you can only use it with for loop? I tried to use them by adding another for loop inside while loop but again, it doesn't remember previus values. Can it be used with for loop? If I use shift register on while loop, final value stays blank...

0 Kudos
Message 4 of 9
(3,521 Views)

Hi,

 

you can use a shift register with while loop as well - simply drag a wire from the 'x + y' to the edge of the while loop, right click the tunel and select "replace with shift register". Just don't forget to initialize the shift register with 0 at the start of your application. I created a cut down version of your code just to show you the way to do it.

Best regards,
Jano
0 Kudos
Message 5 of 9
(3,517 Views)

Thank you very much! I have added shift registers and everything is workking fine except for some reason it count 10x as much? It shows 1 + 1, but it counts 20, 40, 60,....?

0 Kudos
Message 6 of 9
(3,511 Views)

You are welcome 🙂

 

I reviewed your code. My assumption is, that it counts every edge, however you are running the loop as fast as the system allows it to and so you simply cannot see every update. If you want to verify this, put a wait function inside the loop - then you should see individual increments as well.

Best regards,
Jano
0 Kudos
Message 7 of 9
(3,499 Views)

You are right! It goes much faster than I tought. Thanks for all the help, much apreciated!

0 Kudos
Message 8 of 9
(3,496 Views)
Solution
Accepted by topic author koli99

I'm glad that I could have helped.

 

If you have more questions, please don't hesitate to ask.

Best regards,
Jano
0 Kudos
Message 9 of 9
(3,494 Views)