Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: blackbeard on November 09, 2010, 10:35:27 AM

Title: convert input from microphone to pwm input
Post by: blackbeard on November 09, 2010, 10:35:27 AM
so i want to detect sound from standard microphones by converting the low voltage they generate to pwm signals. i'm thinking if i use an op amp chip i could have it output either +5v or 0v so that a micro could understnd it as usefull data
Title: Re: convert input from microphone to pwm input
Post by: Soeren on November 09, 2010, 06:50:24 PM
Hi,

so i want to detect sound from standard microphones by converting the low voltage they generate to pwm signals. i'm thinking if i use an op amp chip i could have it output either +5v or 0v so that a micro could understnd it as usefull data
I doubt that you'd get anything usable from PWM'd sound - each time you convert the signal, you loose some and that is detrimental to speech recognition (if that's what you're trying to do).

What you need for the conversion is a digital audio amplifier, and since they're now quite common, you should be able to find enough articles to study all the intricacies of such a beast.

In short, you create a very stable (think both X-tal- and amplitude control) triangle waveform running at 150+kHz (HiFi amps are running much higher). This signal is fed to a comparator along with the audio signal and the resulting output is your PWM signal.
Now you "just" need to program the controller to read 150+kHz PWM - better you than me ;D

I'd rather use an A/D-C input, unless the main purpose is experimenting and learning.
Title: Re: convert input from microphone to pwm input
Post by: blackbeard on November 10, 2010, 06:23:04 AM
Ok I should have been more detailed in the description of my project. I am not trying to add speech recognition but sound detection. It would be used to allow a robot to hunt down noises. It wouldn't need to understand what it is hearing but when it detects a noise on one of it's two microphones it would adjust it's position accordingly.
Title: Re: convert input from microphone to pwm input
Post by: azy on November 13, 2010, 06:18:21 AM
I got some source code somewhere , and a standalone exe file (Freebasic, Compiles into c i think, not interpreted at run time so its fast and light as basic goes)


plug in a analogue mic in to your sound card, run the prog and then a text file is created

in the text file is a volume and a time, eg volume = 77 , time = 12:35:17  

updates a couple of times a second, text file gets bigger 1 line at a time, can easily distinguish 10 different volume levels of sound. Just write a snippet of code to snoop the txt file in the language of your choice

any good to you ?

Original code was a spectrum analyzer that output to the screen in real time, i just sampled some screen pixels to get the peak volume levels at any given point in time. Butt ugly but it works !