Go Down

Topic: Audio beat detect. with Diodes or Transistors? How to avoid HPF? (Read 3630 times) previous topic - next topic

alanMcFire

Hey everyone,

I have quite a few questions related to my project. I work as a DJ and just started with Arduino, and what I want to do is to be able to read the audio signal to sync some LEDs to the music (hopefully the bass kick), among other things.

I've read a lot of tutorials, including one that uses an Op-Amp to power the low level signal and then a DC Offset to create a readable range for the Arduino analogs, but I'm afraid that having a capacitor in series creates a high-pass filter, reducing the frequency that I actually want to read. Link to said tutorial: http://www.instructables.com/id/Arduino-Audio-Input

Is there another way to do this?
What if I simply hook a Diode to protect the analog input from negative audio signal?
Or use a transistor to control the amount of electricity it could flow from the 5V source to an input?
(there are so many transistors that I'm naively hoping one could work with low level audio signals to its base pin).
If not, how could I avoid the High-Pass Filter or improve the kick detection?

I don't think I need to change any sampling frequency (Configuring ADC to take input samples faster) or do any complex stuff in the code, as I don't really find the need to process the signal yet. Plus, reading distorted signals actually creates a cool effect: Right now, analog input is centered around 510 (10 bit) and I just read the high peaks (say, values between 700 and 1000) and map them to 8 bit to a PWM output, so the LEDs blink really fast and to the beat (sort of). The audio signal coming to the Arduino will not be used for speakers, or any other equipment that might get damaged by this distorted signals (so using cheap Op-Amps or whatever else might distort sound signal a little bit is not a big deal, compared to using a mic to read the sound "pressure" in a place where everyone is shouting), but I just want to make sure that this wont damage the Arduino either. The rest of the ideas for this project are switch or time controlled so are safe from distorted audio signal.

Sorry it took me that much to explain, but I feel that I have read and learned more this two weeks than in my whole school life and still have many questions and concerns. Thank you very much!

nickgammon

My suggestion is to Google "FFT arduino" (Fast Fourier Transform).

I think people have used that to take an incoming audio, detect frequency levels, and display them on an LED. Your project sounds similar.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

DVDdoug

#2
Oct 21, 2013, 07:39 am Last Edit: Oct 21, 2013, 07:48 am by DVDdoug Reason: 1
DC is zero Hz, and you need to block that.   But with a big enough capacitor,  you can "tune" the high pass filter to 20Hz or below so that all of the audio goes through it.    That's fairly standard practice in audio...  Most audio electronics will pass the whole audio range without passing DC, although some amps/preamps do go to DC.

You can make a simple bandpass filter by adding a low-pass filter to your "high pass" DC-blocking filter to pass frequencies between say, 10Hz and 100Hz.

You might do some research into beat detection.   I think you need an "envelope" filter that looks at and filters the loudness (not the actual waveform) at about 4Hz.   And if you want to make it really good, I think it should "learn" beat timing, so if there is a missing beat (a musical rest) or a weak beat, the lighting keeps on pulsing to the beat just like a human would do...  When you tap your toe to the music, you don't wait till you hear the beat, you anticipate when it's coming.

I've done some crude beat detection, and for my lighting effects, I think it's less boring if the lighting doesn't exactly follow beat 1,2,3,4, over-and-over, but responds more to the loudness.   

A diode will work to block the negative half of the waveform  (with a resistor in front of it so you don't damage/distort the signal you are listening to).   But if you decide to use FFT (or other digital filtering), the software needs to see a full sine wave.  (It's OK if the sine wave is DC biased.)  I generally use a Peak Detector Circuit, which also throws away the negative half of the waveform, and it puts-out a voltage proportional to the volume (instead of passing-through the audio).   So, with a peak detector, you cannot use FFT or digital filtering, unless you want to do a ~4Hz volume/beat filter.

alanMcFire

There's also MIDI: Is the MIDI clock constant or it changes depending on the BPMs? It would make sense for them to follow the beats to sync the notes, and my mixer has MIDI In and Out.


My suggestion is to Google "FFT arduino" (Fast Fourier Transform).


Thanks Nick for the reply. I've been reading about FFT the past few days and it didn't worked properly, but now that you mentioned it I searched a little bit more and found a couple of helpful tutorials. Thank you very much!


But with a big enough capacitor,  you can "tune" the high pass filter to 20Hz or below so that all of the audio goes through it.


Thanks DVDdough! Didn't know that. I'll look it up too. Does "big enough capacitor" refer to its capacitance or its working voltage? Or both? Right now I have a 10uF, 25V cap.

As for beat "learning" is also a good idea but I'm having trouble coming up with time ideas for the code. It is already controlling other lights (i.e. halogens, so they don't stay on enough to get damaged) and I'm calling the millis() function so may times in the code that I feel like the arduino is going to throw me a clock and scream "measure your own time!". I need to find a way for it to control all of this without having a bunch of time variables for each light.

Thanks again!


nickgammon

Quote

I'm calling the millis() function so may times in the code that I feel like the arduino is going to throw me a clock and scream "measure your own time!". I need to find a way for it to control all of this without having a bunch of time variables for each light.


It doesn't mind. If you didn't call it, it would get bored.

Whenever you see a bunch of variables, think about an array.

http://www.gammon.com.au/forum/?id=12153#tip1
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Grumpy_Mike

Quote
Is the MIDI clock constant

Yes.
But you are not playing MIDI music are you?

Quote
Does "big enough capacitor" refer to its capacitance

Yes.

Quote
I feel like the arduino is going to throw me a clock and scream "measure your own time!

Yes but it won't.  :)


DVDdoug

Quote
Thanks DVDdough! Didn't know that. I'll look it up too. Does "big enough capacitor" refer to its capacitance or its working voltage? Or both? Right now I have a 10uF, 25V cap.
An R-C filter depends on the capacitance and the resistor value.   Increasing either the resistor or the capacitor value will lower the filter cut-off frequency.   You can look-up the formula, or there is a calculator on this page.   With a 10k Ohm "load" resistance, and a 10uF capacitor, you can go below 2Hz.

Quote
(i.e. halogens, so they don't stay on enough to get damaged)
What???  You should be able to leave halogens (or other incandescents) on full-time, or turn them on with a very short pulse that causes it to glow dimly.   But, incandescent "dimmers" have to be synchronized with the AC line frequency, which is another timing issue.

Quote
and I'm calling the millis() function so may times in the code that I feel like the arduino is going to throw me a clock...
One advantage to the peak detector circuit I use is it acts something like a low-pass filter.   It puts-out a DC value that's proportional to the peak audio level, and it holds/decays that voltage depending on the resistor & capacitor values.   I have a "time constant" of about 1/10th of a second, and I can get-by reading the Arduino's ADC at 1/10th second intervals (slow for a microprocessor and slower than the audio frequency).   I don't always read it that slowly...  It depends on the effect I'm doing.

cjdelphi

Google the ic msgeq7, a tiny ic that spits out the volume levels from selected frequencies..

The other way would be a low band pass (opposite circuit to a high pass)

nickgammon



But with a big enough capacitor,  you can "tune" the high pass filter to 20Hz or below so that all of the audio goes through it.


Thanks DVDdough!


It's DVDdoug. He is not going to turn into bread!
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

alanMcFire


Google the ic msgeq7


Thanks for that! I think I can use it right away and add more things later.


You can look-up the formula, or there is a calculator on this page.   With a 10k Ohm "load" resistance, and a 10uF capacitor, you can go below 2Hz.


Thanks for the link now I get it. Fixed it and worked like a charm. Oh, and sorry about halogen comment I thought I was writing too much and deleted some lines, and ended up with that. How about the laser? User manual said that I should let it rest from time to time during the gig (with technical words, of course).


Whenever you see a bunch of variables, think about an array.
http://www.gammon.com.au/forum/?id=12153#tip1


Thanks! I'm already using arrays, but the link you provided will help me improve many parts of the code. Awesome page!
About the bread thing, the h is next to the g, it was an honest mistake :) Thanks again!


Yes.
But you are not playing MIDI music are you?


No =( haha, thank you very much for saving my time with that idea. For what I'm trying to do I don't think MIDI would help.


I might go with FFT though it's taking some time to implement (a.k.a. I feel like I'm reading Chinese with most tutorials). Did find this, which should help as a starting point, I hope: http://blurtime.blogspot.com/2010/11/arduino-realtime-audio-spectrum.html.

Go Up