Preamp design for guitar tuner

Started by RevBlue, October 02, 2013, 10:31:11 AM

Previous topic - Next topic

RevBlue

Hello everyone.

I'm designing an arduino based guitar tuner based on the Arduino Uno R3. The way im planning the tuner is to build an analog preamp circuit that takes the input from the guitar, and converts the signal to 5Vpp with 2.5V DC bias since the arduino analog inputs can only take 0-5V.
I've plugged my guitar into a scope (sadly I have no access to a spectrometer) to figure out the range of the frequency and voltage coming out from my guitar (Reverend Roundhouse), and for freq i got from about 82Hz - 1.6kHz (standard tuning only for now), and for voltage I got a huge variance from 300mV (maybe even lower sometimes) to about 1.8V max.

The problem I have figuring out is:
1) for freq, do I need a BPF of 82Hz - 1.6kHz or will just a LPF with a cut off of anything above 1.6kHz will do?
2)How do I figure out the gain i need for the preamp? some circuits i looked at had a gain of 100-200 but wont that make the signal way too big, and wont the clipping for 0-5v cause a big loss of data?


g_u_e_s_t

i built a preamp for arduino, all schematics here:
http://wiki.openmusiclabs.com/wiki/StompShield

this has a variable gain input stage, which might not be a bad idea if you will be using different guitars or different settings on your guitar while tuning.  it is then followed by a 3-pole active filter with cutoff of 10kHz.  this sounds like it is too high for your application, but can be changed easily by scaling the capacitors appropriately.  the rest is for the DAC and output stage, so you wont need that.

how were you planning on finding the note frequency?

RevBlue

#2
Thanks for the link, thing is I'm trying to learn as I build this so I'm trying not to "copy blocks" from the net and put them into my build.
This is more of project for learning how to design circuits and deal with MC's. Thing is about the variable gain you said, I'm only designing this for my guitar for now and I don't want to need to manually change gain each time, so how do I deal with such a wide range of input voltages? is there such a thing as a log scale gain op-amp? Or do I go by the highest value I'm gonna be dealing with?

For the pitch detection I haven't delved too much into that, but so far I have 3 candidates: Zero Crossing, Autocorrelation or YIN (a type of improved autocorrelation algorithm with improved error %)

g_u_e_s_t

so, the best way to handle varying amplitude inputs is to use an AGC amp (automatic gain control).  but those are a bit of a pain, and if you are just doing zero crossings, not really necessary.  to amplify the guitar you will want a high impedance input, which is why most pedals use a non-inverting opamp topology at the input, with a JFET input opamp.  thats what the first amp is doing in that circuit.  you can do some hacks with a microcontroller to make your own AGC by enabling different resistors to the feedback pin.  the next stage is the filter, which is critical if you are samping with an ADC, but not as critical if youre just doing zero crossings. 3 pole active filters are really good for using just one opamp.  analog devices has an online design tool that i use to help figure out which values to use.  otherwise there are cookbook methods or equations.  after that its either a comparator for your zero crossings, or into the ADC.

mistahead

Quote from: RevBlue on October 02, 2013, 04:56:51 PM
Thanks for the link, thing is I'm trying to learn as I build this so I'm trying not to "copy blocks" from the net and put them into my build.
This is more of project for learning how to design circuits and deal with MC's. Thing is about the variable gain you said, I'm only designing this for my guitar for now and I don't want to need to manually change gain each time, so how do I deal with such a wide range of input voltages? is there such a thing as a log scale gain op-amp? Or do I go by the highest value I'm gonna be dealing with?

For the pitch detection I haven't delved too much into that, but so far I have 3 candidates: Zero Crossing, Autocorrelation or YIN (a type of improved autocorrelation algorithm with improved error %)

Reinventing the wheel is not a better way to learn anything - take the "copy blocks" and implement them, tear them apart and reimplement them, learn how they were done...

I only base this on my former life as a code monkey where "learning from snippet" is the preffered method of teaching - I'm sure the mechanical guys get put through building an engine from scratch prior to doing a tear down/analysis on an existing one.

RevBlue

Quote from: mistahead on October 02, 2013, 07:35:20 PM
Reinventing the wheel is not a better way to learn anything - take the "copy blocks" and implement them, tear them apart and reimplement them, learn how they were done...

I only base this on my former life as a code monkey where "learning from snippet" is the preffered method of teaching - I'm sure the mechanical guys get put through building an engine from scratch prior to doing a tear down/analysis on an existing one.

First of all thanks for the advice.
That being said, while I agree with you to some extent, the reason I'm going at it the way I am is because this is (hopefully) going to be my job. I am an EE student, so its not like I'm starting from scratch here knowledge-wise. That also being said this IS the first time I ever tried doing something like this, but still I want to be able to do this kinds of things without just using an entire schematic just because I found it on the internet and it seemed ok.
I want to be able to approach a design problem from the start and figure it out as I go along

mistahead

Quote from: RevBlue on October 02, 2013, 08:36:36 PM
Quote from: mistahead on October 02, 2013, 07:35:20 PM
Reinventing the wheel is not a better way to learn anything - take the "copy blocks" and implement them, tear them apart and reimplement them, learn how they were done...

I only base this on my former life as a code monkey where "learning from snippet" is the preffered method of teaching - I'm sure the mechanical guys get put through building an engine from scratch prior to doing a tear down/analysis on an existing one.

First of all thanks for the advice.
That being said, while I agree with you to some extent, the reason I'm going at it the way I am is because this is (hopefully) going to be my job. I am an EE student, so its not like I'm starting from scratch here knowledge-wise. That also being said this IS the first time I ever tried doing something like this, but still I want to be able to do this kinds of things without just using an entire schematic just because I found it on the internet and it seemed ok.
I want to be able to approach a design problem from the start and figure it out as I go along

How far into EE are you? I suggested the other way because I've gone through my education, supplemented that with some training, and architect solutions for a living - that is to say it IS my job and has been for some time now.

Design principal and the implemenation medium are taught seperately (generally - sometimes they've got to teach a little of B to explore A, especially early on), and this is for a reason.

Good luck but think of it this way - you wouldn't try to create your own dialect to speak a language, you piece together your own dialect or vocabulary from pulling bits of other people's speach to bits... but everyone "learns differently".

PRR

> converts the signal to 5Vpp with 2.5V DC bias
> variance from 300mV (maybe even lower sometimes) to about 1.8V max.
> wont the clipping for 0-5v cause a big loss of data?


Think.

WHY do you want 5V at the ADC? So you can get the maximum bit-resolution you paid-for when you bought the ADC. Telephone-grade sound can be 8-bit. CD sound is 16-bit. 12-bit is very popular in industrail systems and often "free" with PICs and such.

> arduino based guitar tuner

So this isn't for releasing your tracks on iTunz? You just want *pitch*?? You can hear pitch perfectly well on a bad telephone line.

Arguably a fast ADC can pitch-detect fairly pure tones with a ONE-bit converter, as long as the wave crosses the threshold of that bit.

Guitar may not be so easy.

Also you can GROSSLY fuzz a guitar and it is still the same musical pitch. It now has even more overtones, but the fundamental has NOT changed pitch. Since plucked strings always have overtones, part of your job is to find the LOWest major partial, the fundamental, and not be distacted by ripe string overtones. If you can do that, any distortion overtones will largely be ignored.

So assuming you have a 12-bit, but only need 8-bit quality, you could come in "4 bits low", or 5Vpp/16, or 0.28Vpp.

Oddly enough, your (hot) guitar HAS that much. (Even if I can't tell if your 300mV-1.8V is Peak, Peak-Peak, or RMS.)

Anyway, you are a long way from done. Run the guitar straight-in (almost), pluck hard, and get some algorithms going. Once you have the software working most of the time, you can re-examine the analog side to see  if that needs tweaking to handle old single-coils and limp pickers.

Since the ADC input may load-down guitar or crap-up the signal that also goes to the stage-amp and fans, you want a unity-gain buffer. Many such plans around. Use an opamp, but make Vref = 2.5V instead of 0V or 4.5V as in most plans. Verify that the output idles very near 2.5v DC. This can go to the ADC pin, perhaps with a 47 ohm resistor so the tight-strung opamp and the ADC's input pulses don't fight.

Band-limiting is NOT needed for a first try. You won't have any significant output below your lowest string pitch; where would it come from? (Oh, yeah: the universal 60Hz humm. I suspect your algorithm should always toss-out any answer that is exactly 60.0Hz.) You also won't have much above 6KHz (or less) because steel strings don't like to jiggle faster, and wound pickups feeding long cables form a very effective 2-pole low-pass. (Ah, sometimes you get MHz trash from local radio stations. Standard buffer inputs should have ~~10K + 270pFd to drop that, anyway your slow PIC can't handle MHz input.)
  • SUPPORTER

mistahead

PRR - I like the way you think there, heavily distorted signal using up as much of "too little bandwidth", with enough filtering to drag it back towards its fundamental and get rid of the layered harmonics... but don't you now need to filter more dynamically?

Are we starting to sneak into a ground where we could saturate the bandwidth and average the outcome to get back to a mono-pitch?

Anyone know the figures on minumum width and maximum filtering one could get away with here... I'm bleeding into another tangent thought mwhahahaha.  :icon_smile:

RevBlue

#9
PRR, thanks you've given me a lot to think about, a couple of things I may have needed to clarify first:

The 300mV-1.8V i spoke about is Vpp, and its around 0. Since the analog inputs of the arduino uno can only read 0-5V anything negative will be read as 0 and that's not good so I *have* to offset it to around 2.5V (which I planned on doing using a voltage divider after the output coupling at the opamp exit.
And the analog inputs have 10-bit resolution btw


P.S- sorry if some of my questions seem stupid, like I said this is my first time dealing with a MC

Digital Larry

I think OpenMusicLabs also published Arduino FFT code.  You could get an FFT and look for the lowest peak, the do another FFT with a tighter range around that peak to try to zoom in on the exact pitch.  That said, I have no idea how "real" tuners work and maybe there's a documented approach that's simpler than that.

I did find a tuner/spectral analysis Android app and found it pretty fascinating to watch spectral changes depending on where I plucked my ukulele string.
Digital Larry
Want to quickly design your own effects patches for the Spin FV-1 DSP chip?
https://github.com/HolyCityAudio/SpinCAD-Designer

PRR

#11
> can only read 0-5V anything negative will be read as 0 and that's not good

Why not??

And BTW a FFT is a high-CPU low-resolution approach.

Classic is to open a gate for 1 second, count waves, display CPS (Hz). But at audio that's both slow and low-resolution. (1 second of 440Hz is 441 or 439 counts, or only 3 musical-Cents accuracy; and guitar tunes much lower than 440Hz.)

Instead we start a 1MHz counter when the wave rises above zero, stop it the next time it rises above zero. At say 100Hz we get 10,000 counts and excellent resolution, every cycle.

Note that I suggest counting "when the wave rises above zero". Negative voltages can actually be *ignored*. At least if the wave has no strong overtones, which may shift phase, and disturb the zero-crossings.

However. You will probably end up low-passing. And you really want to do this with algorithms, not an analog filter-chain. So you probably *do* want to input the whole wave, then do low-pass in the digital world. (Doing much of this in analog, especially dynamically, is way more parts and solder-time.)

Cheez-Whiz for thought: classic Frequency Counters (standard lab gear for 50+ years) do not use an ADC. If signal is less than 20%-10% overtones, you just clip it to a square-wave and gate it to a digital counter. This will even work for very mellow guitars. But guitar pluck and pickup locations favor a less-mellow tone, so you may have to deal with strong overtones.

Low-tech approach: older pocket tuners require you to say (switch) what note you are tuning. They look for deviation from that note, they don't acquire arbitrary notes. This even works good in orchestra. A clarinet can't move individual notes, there's just one adjustment (the end slides a small amount). Typically you tune the A and then trust the instrument maker (and your reed-bite) to hit the other notes. This is also done on older piano tuners, though with many more note-settings. Yes, tuning a 6-string this way IS tedious. (Not as tedious as tuning the middle of a piano.)

> so I *have* to offset it to around 2.5V (which I planned on doing using a voltage divider after the output coupling at the opamp exit.

The opamp output has to sit at some DC level. In single-supply systems, often half the battery voltage. Set the opamp input at 2.5V, set opamp DC gain at unity (AC/audio gain can be higher), and direct-couple the opamp to the ADC pin (possibly with 47 ohms between). The opamp is a much more solid DC source than any voltage divider it can drive. And less parts.
  • SUPPORTER