LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a clapping detection program

Solved!
Go to solution

Hello Im new to the forum. Im currently working on a program that turns on Leds when you clap. The tricky part in wich I cant seem to figure out how to do it is how to make Labview only turn on the Leds when it detects 2 claps.

 

What I have done is I used the microphone on my laptop to aquire the sound samples, then extract the samples to an array and also extract the maximun value of the array, then after a few comparisons when the program detects a peak then the LED turns on. But I cant find a way to make it turn on only if you make two claps. If someone can help me please.

 (BTW sorry if my english is bad cause Im from a Latin American Country)

 

 

0 Kudos
Message 1 of 6
(3,528 Views)

Welcome.

 

No need to apologize for your language skills.  Your English is much better than anything I would attempt in your language!

 

You are detecting a peak to define when a clap has occurred.  To find two claps you need to find two peaks.  So the question becomes one of timing: Are there two peaks which are far enough apart to be separate peaks and close enough that they represent a double clap and not just two independent claps.

 

Are you acquiring sound samples continuously or in discrete batches with time gaps between batches?  If in batch mode, is one batch long enough to capture a double clap?  These affect the details of how your program might work.

 

In general you could note the time when one clap is detected.  Put the time value in a shift register.  When the next clap is detected, compare its time to the previous clap time.  If the difference is within the specified limit, it is a double clap and you turn on the LED.  If not put the latest clap time in the shift register and look for the next clap.

 

Lynn

0 Kudos
Message 2 of 6
(3,518 Views)

Thanks alot for the Help, the language was because Im not used to technical stuff in English, anyway, the thing is Im using continuos sampling. The idea is that in any time the program will detect those peaks. I was thinking in adding a timer for each cycle it detects peaks, but still dont get how to tell the program there are two peaks, in this case thats continuos sampling. I could Use a register but until know Ive only managed to tell Labview to write the max value of the peak but when it sees the other one it automatically overwrites the first value. Any idea there?

0 Kudos
Message 3 of 6
(3,506 Views)
Solution
Accepted by topic author jnucleus

Continuous sampling makes it easier to get the timing of the two peaks.

 

To create an example let us define two peaks as peaks more than 200 ms and less than 2000 ms apart. When a peak (peak 1) is found store the Tick Count value (count 1) in the shift register.  The Tick Count is in milliseconds. The actual value does not mean anything for your program.  When the next peak is detected (peak 2) store the Tick Count at that time count 2) in the shift register and subtract the previous peak tick count (count 1) (left terminal of the shift register) from the current count (count 2) (connected to the right terminal).  If the difference is between 200 and 2000, turn on the LED, otherwise leave it off.  On the next iteration of the loop count 2 will be on the left terminal of the shift register and count 1 will be overwritten. If no peak is found on this iteration just connect the shift register straight across, keeping the value count 2 in it.  When the third peak is found, its count will be compared to count 2.  So you always have one old count (after you find the first peak) and either no change for no new peak or a new count if a new peak is found.

 

The different actions for peak or no peak are in two different cases of a case structure.

 

Lynn

Message 4 of 6
(3,502 Views)

Great I think I got it now. Thanks alot Lynn! You saved my life Smiley Happy

0 Kudos
Message 5 of 6
(3,498 Views)

Glad I could be of assistance.

 

Lynn

0 Kudos
Message 6 of 6
(3,469 Views)