LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help counting pulses in analogue waveform

Solved!
Go to solution

Hi,

 

I'm a fairly experienced LabVIEW/Teststand developer, but I'm not very good at signals like these. I mostly work with digital electronics, and automated tests. I'm using LabVIEW 2020.

 

I'm writing a VI, which uses a cDAQ 9205 connected to a microphone, which is placed directly above a PCBA which has a buzzer. That buzzer buzzes 5 times when something fails during the test, and at the end of the test, it will buzz 10 times if everything passes.

 

I want that VI to be able to give me a count of the buzzes. I've been able to get a very nice analogue waveform out of it, but counting peaks using native VI's hasn't worked for me.

 

NB: This will run asychronously in TestStand, but I don't need help with that, I just need help counting the peaks. Once I got that sorted out, I will be able to continue from there.

 

Here, I listen for 3 seconds, at 20kHz. The buzzer beeps twice, and I get a very nice time domain waveform. See below.

 

image.png

However, if I zoom in on the waveform, it's not a square wave. It swings. So built-in peak counting VI's yield massive overcount. I want this example to give me a count of exactly 2, instead I have hundreds.

image.png

 

I was wondering if anybody could give me advice on how to do this. I was thinking, like I said, either some debounce feature, or some analogue-to-digital translation, which gives me a nice way to count the peaks. I've tried various analogue filter VI's, and the problem is not resolved.

 

I've tried to be thorough in my post, please let me know if some information is missing.

0 Kudos
Message 1 of 5
(1,219 Views)

It would also be helpful to provide some sample data for different buzz patterns.

 

Nonetheless I generated a dataset that looked reasonably similar to yours and found that I could get an accurate count by tweaking the input parameters to the peak detector.

 

Essential ideas:

- take the absolute value of the signal

- use the Peak Detector function with an extra-large width.  Make it a little wider than a single buzz burst (which I estimated to be 2000 samples at 20 kHz, i.e., 0.1 sec).  I also set the threshold to 1/2 the buzz amplitude.   Small variations in those parameters didn't affect the accuracy of the count.

 

Caveats:

- I simulated a buzz as a 0.1 second sine wave burst superimposed on a 15 mV noise floor.  I tried a few sine wave freqs from 500 to 3000 and all worked fine.  Your signal may be more complex, but I'd expect some kind of similar approach could be made to work.

 

Notes:

- initially I tried lowpass filtering after taking the absolute value.  It worked out fine too, but it turned out not to be necessary.   The peak detector worked anyway, once an appropriate threshold and width were chosen.

 

 

-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.
Message 2 of 5
(1,196 Views)

Thank you for your advice. I have added the absolute value feature. I've also managed to detect peaks.

 

If you look at the attached updated VI, the waveform below is also added as a constant at the bottom left of the block diagram.

waveform.png

 

However, there is a problem related to reading data continuously. I really haven't done it that much. My first thought was to look at peaks in the appended waveform, but that waveform data size increases linearly with time, so it lags my computer completely. Clearly, that is not the way to do it. So what can I do? That is the question. I can't look at some arbitrary length of samples either, because my beeps might become divided between two sample sets.

 

Do you have any advice on that?

0 Kudos
Message 3 of 5
(1,180 Views)
Solution
Accepted by topic author DrOnline82

NI also has a point-by-point version of the Peak Detector.  I hadn't ever used it, so I tried it out with some quick mods of your code.  It worked out fine with your example data, have a look. 

 

Each While loop iteration processes the next chunk of your example data by using the point-by-point function in a For loop.  You can change the # samples per chunk on the front panel to see that it's insensitive to whether a buzz is split across 2 or more acquisition chunks.  I also used a standard filter function to avoid the Express VI and its Dynamic Data wires.

 

 

-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.
Message 4 of 5
(1,156 Views)

Aha! Point-by-point... Like I said before, I have quite a bit of experience with LabVIEW, but never with real time data analysis, never really with waveforms. It's my impression MOST LabVIEW development deals with this stuff, but it's just not what I work with daily. So I haven't even heard of these point-by-point vi's before. I'm reading the documentation for them now, they seem to be exactly what I need. Thank you very much for your help. I've downloaded the VI you attached, to get me started. Appreciate it!

0 Kudos
Message 5 of 5
(1,120 Views)