PDA

View Full Version : Project Guidance - FFT/Frequency Detection from Piezo pickup - Total Noob



jarvitron
08-24-2015, 10:44 PM
My ignorance here is vast but I think I have a project which the Teensy is hyper overkill for (I hope).

The basic idea is that a musical instrument (a chime) will be played, the fundamental frequency of the note played is detected (of seven possible input frequencies) and if one is detected an action will be taken (change the color of a ws2812 LED by sending serial data to it, or move a servo a certain number of steps).

Since the intended environments will be noise heavy and cords are acceptable, I've opted away from a microphone and use a clip on piezo contact pickup, with the signal fed into an op amp (I understand that a piezo contact mic can output an insane voltage when dropped or tapped) to protect the Teensy pin. The op amp (lm741, which I understand is not ideal but I have an lm324 if that's more appropriate. I don't think it should matter since this isn't an audio replication application its just an analysis) is running from the same 0-5v as the Teensy as the with the non-inverting input tied to 3.3v out. The frequencies I'm interested in from this particular instrument are all in a very small range, 2000khz to 3750 khz basically. Would it make sense to band pass filter around that range to help avoid unwanted noise pickup?

Here's my schematic, there's no values filled in because I am having trouble even determining which formula I should be using in this situation, what gain I'd even want. Forgive my coctail-napkin-aided-drafting schematic. 4977

I understand that a microphone would probably provide a higher resolution, but I find microphone selection pretty daunting, is it as simple as a couple cent electret mike installed in the instrument near its "voicehole"?

JBeale
08-24-2015, 10:58 PM
Just FYI, if you are looking at the output of a FFT for spectral analysis, for many instrument sounds, the fundamental is lower in amplitude than the overtones. As I recall, bells in particular can have many overtones that are not harmonically related to the fundamental.

jarvitron
08-24-2015, 11:08 PM
I've been using 10kohm resistors for both the feedback network values mostly because they're what I had at hand but I'm unable to get consistent "what amplification am I getting here" readings from the op amp (even just using DC input).

jarvitron
08-24-2015, 11:12 PM
Well, the operative thing I'm looking for is repeatable detectability and not accuracy or even musical evaluation, simply raw detection input without real total spectrum analysis. When I play the bells through my computer mic using a mic-oscilloscope plotter I can see strong bars at the frequencies I stated and no detectable activity elsewhere in the chart. I don't need to know how good C# (a couple notches sour from that actually, according to my clip on guitar tuner) just that the c# bell is being tolled.

jarvitron
08-24-2015, 11:13 PM
So when I say FFT understand that I don't really mean FFT, I mean frequency detection, but whenever I approach that subject in various arduino/teensy forums the Fourier-letter word shows up first thing.

PaulStoffregen
08-25-2015, 02:31 AM
If you're looking for only a specific set of known frequencies, maybe the tone detection object could help?

http://www.pjrc.com/teensy/gui/?info=AudioAnalyzeToneDetect

There's an example of using 7 of these to detect DTMF tones. Maybe it could give you a good starting point?

File > Examples > Audio > Analysis > DialTone_Serial

Jp3141
08-25-2015, 07:20 AM
The '741 isn't a great opamp for this application -- its output can't swing particularly close to the rails (it'll clip when within about 1 V of each rail). Similarly the common-mode range at the input is narrow. Pick a more modern rail-rail opamp - e.g. TLC271.

You'd be better off AC coupling the input -- that way you can get increased gain for your AC signal. Connect a 0.1 uF in series with the piezo. Your gain is now -R_feedback/R_input.

You need to bias the output at 3.3 V / 2 -- so instead of connecting the non-inverting input to 3.3 V, connect 2 10k R's in series between 3.3 V and GND and connect to the midpoint.

Best to power the opamp from 3.3 V, else it'll over drive the Teensy's ADC input (I think it is only rated to 3.3 V).

WMXZ
08-25-2015, 08:57 AM
Since the intended environments will be noise heavy and cords are acceptable, I've opted away from a microphone and use a clip on piezo contact pickup, with the signal fed into an op amp (I understand that a piezo contact mic can output an insane voltage when dropped or tapped) to protect the Teensy pin. The op amp (lm741, which I understand is not ideal but I have an lm324 if that's more appropriate.

Here's my schematic, there's no values filled in because I am having trouble even determining which formula I should be using in this situation, what gain I'd even want. Forgive my coctail-napkin-aided-drafting schematic. 4977


To avoid that 'insane voltages' of your piezo destroy your electronics, you need two anti-parallel diodes at the input to ground.
As piezo work best (only?) with 10s of Megohm load (much higher than the input impedance of most opamps) the standard way is to use a FET as pre-amp before using standard opamps. a google of piezo preamp will give you some examples.
I don't know the sensitivity of your pickup, so I cannot comment on the gain you need for ADC.

My understanding is that Teensy ADC is NOT 5 V tolerant (i.e. does not convert above 3.3 V), so your schematic is not good. You need a voltage divider to provide, say 1.65 V and not 3.3V as virtual ground to the opamp. There is Vref output on Teensy which seems more appropriate to me (someone else, please, to comment on this, as I never used Teensy onboard ADC). Also, I believe preamp ground should go to AGND.

jarvitron
08-25-2015, 09:45 PM
To avoid that 'insane voltages' of your piezo destroy your electronics, you need two anti-parallel diodes at the input to ground.

As piezo work best (only?) with 10s of Megohm load (much higher than the input impedance of most opamps) the standard way is to use a FET as pre-amp before using standard opamps. a google of piezo preamp will give you some examples.

My understanding is that Teensy ADC is NOT 5 V tolerant (i.e. does not convert above 3.3 V), so your schematic is not good. You need a voltage divider to provide, say 1.65 V and not 3.3V as virtual ground to the opamp. There is Vref output on Teensy which seems more appropriate to me (someone else, please, to comment on this, as I never used Teensy onboard ADC). Also, I believe preamp ground should go to AGND.

I understood from the Teensy 3.1 page that all the "normal" analog pins are 5v tolerant but the analog only pins are 3.3v only, though in closer reading I realize it ignores those values between 3.3v and 5v, so that's unideal. I'll sort out the voltage virtual ground. By preamp ground do you mean the ground/barrel of the pickup before it is amplified or the ground of the proposed preamplifier circuit?

I had considered a preamplification circuit but most circuit diagrams are suspiciously worded about musical tone and are more about reproduction/sound creation than analysis. Would a "jfet" J201 preamplifier circuit be suitable, presuming I can feed it with the right power? Is there a simpler way to skin this particular cat, some more efficient way to amplify the signal sufficient for 0-3.3v analysis that would satisfy the high input impedance requirement of the piezo that isn't preamp/opamp/(adc pin)?

Thank you so much for all of your time, guys.

Aaron

jarvitron
08-25-2015, 09:49 PM
This is a very interesting library, and that is a great starting point for me, code wise, thank you so much. I'll go read up about this audio library a bit before I embarrass myself with dumb quetions. Thank you Paul.

jarvitron
08-25-2015, 09:51 PM
I'm not sure what AC coupling means but I'll do some googling. Thanks for your response I'll find a newer op amp.

jarvitron
08-25-2015, 10:17 PM
Is this what you mean by antiparallel diodes on the input?

4985

jarvitron
08-25-2015, 10:21 PM
I also have a 2N3904 NPN Transistor, would it be possible to use that in a preamplification duty?

WMXZ
08-26-2015, 11:15 AM
Would a "jfet" J201 preamplifier circuit be suitable, presuming I can feed it with the right power?
I would try it.
keep in mind that for J201 drain source current (at VGS=0) is 1 mA and that VGS cutoff is -1.5 V, but if you have these FETs you know how to use them.

WMXZ
08-26-2015, 11:17 AM
Is this what you mean by antiparallel diodes on the input?

4985

yes, but I would put all preamp on Agnd, not only piezo. This way you have a looong ground loop through Teensy.

WMXZ
08-26-2015, 11:20 AM
I also have a 2N3904 NPN Transistor, would it be possible to use that in a preamplification duty?

not as a first stage, bipolar transistors have limited input impedance (in fact base current is muuuch larger than gate current of FET)

jarvitron
09-01-2015, 02:00 AM
I would try it.
keep in mind that for J201 drain source current (at VGS=0) is 1 mA and that VGS cutoff is -1.5 V, but if you have these FETs you know how to use them.

I suppose the words "total noob" and the absolutely uncertain way I asked the question did not indicate it in full detail but no, I don't know how to use them just because I was able to google for them. In fact I don't even know what the phrase drain source current means, nor what I'd need to do to compensate for its value at 1ma versus any other value. Thank you for your time.

WMXZ
09-01-2015, 10:40 AM
I suppose the words "total noob" and the absolutely uncertain way I asked the question did not indicate it in full detail but no, I don't know how to use them just because I was able to google for them. In fact I don't even know what the phrase drain source current means, nor what I'd need to do to compensate for its value at 1ma versus any other value. Thank you for your time.

As good audio analog circuitry is not for beginners, I suggest to get you first a microphone with proper pre-amp and try it. If it is too noisy and you cannot remove noise with Teensy by simply filtering the data, then you may consider alternatives.