Ukulele Tuner

Discussion in 'The Projects Forum' started by jerrytouille, Apr 4, 2014.

  1. jerrytouille

    Thread Starter New Member

    Mar 23, 2014
    13
    0
    Hi AAC.
    I'm building a simple tuner for my ukulele, standard 4-string G,C,E,A with electret mic. The respective frequencies are G (392 Hz), C (262 Hz), E (330 Hz), A (440 Hz). I'm in the process of learning so my goal is to do this from scratch (no prebuilt mic/preamp 'sparkfun' type) and also will open-source this on github/instructable for newbies like me.

    So after a week of research, here's what I got so far:
    Overview: Ukulele->ElectretMic/Preamp->Bandpass filter->SchmittTrigger->PIC MCU->LED display

    Ukulele: standard 4-string soprano G,C,E,A.
    Mic/Preamp: following this post.
    Bandpass filter:
    [​IMG]

    Schmitt Trigger:
    [​IMG]

    PIC/LED display: my PIC16F877 schematic

    Currently I'm struggling with how to select resistors and capacitors value for the bandpass-filter and schmitt trigger to accomodate the frequencies I'm trying to detect with the PIC. There are quite amount of resistors and caps variables and I'm not sure where to start (do I just select a random standard values say 10k, 10uF and leave one variable and calculate that one?)

    So what values should I use?

    Thanks for your help.

    -jerrytouille
     
  2. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    How you gonna tune your tuner?

    FYI, tuners are available as apps for Android and iPad. Just sayin'.
     
  3. jerrytouille

    Thread Starter New Member

    Mar 23, 2014
    13
    0
    The UI is inspired by this app.
    The tuner segment LED will display the note closest to the sound and left/right LEDs for lower/higher pitch guide.
    Yes there are apps for that but the point is to build one yourself (electronically) and to learn, isn't that this forum is about.

    Thanks.
     
  4. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    Ok. But I wouldn't approach the design with filters. Sharp BP filters are too difficult to tune *and* keep tuned. I'd start with a crystal time base, and divide it down into the various note frequencies (look for a "top octave generator). This gives you a solid reference for each note.

    From there, you can go multiple directions. You could just output a selected note to a speaker and listen for the beat frequency to disappear when you are in tune.

    Or, you could input the sound from your instrument with a mic or pickup, amplify it and mix it with the reference signal. A peak DC signal will indicate in tune (be careful with phase relationships).

    As a fully integrated alternative, a DSP chip could do the analysis for you, providing any kind of UI you want.
     
  5. jerrytouille

    Thread Starter New Member

    Mar 23, 2014
    13
    0
    As posted, I'm using electret mic and preamp circuit to listen and amplify the sound, filters and trigger to cut off lower/higher frequencies then feed into PIC MCU to detect frenquencies and map to note (lookup table) with +/- %error of course. Again this is a simple getting started tuner.
     
  6. bertus

    Administrator

    Apr 5, 2008
    15,649
    2,348
  7. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    Well, if it helps, here's a spreadsheet I put together in LibreOffice Calc that'll compute a 4th order MFBP filter:

    4th Order MFBP Filter Design
     
  8. jerrytouille

    Thread Starter New Member

    Mar 23, 2014
    13
    0
  9. bertus

    Administrator

    Apr 5, 2008
    15,649
    2,348
    Hello,

    The schmitt trigger will do nothing with the frequency.
    It will only transform the incoming signal to a squarewave.
    The hysteresis in the schmitt trigger will reduce the noise on the signal.
    See this page of the eBook for more info:
    http://www.allaboutcircuits.com/vol_3/chpt_8/12.html

    Bertus
     
    jerrytouille likes this.
  10. jerrytouille

    Thread Starter New Member

    Mar 23, 2014
    13
    0
    Sorry that was my bad what i meant is the bandpass filter. The filter will filter out all sound freqs <100hz and >600hz. So by the time it gets to the Schmitt trigger to convert analog waves to square waves, the voltages dont really matter that much as long as the waves are solid square wave so the MCU can detect edge triggers thus can calculate the waves' periods -> convert to frequencies.

    Am i on the right track?
     
  11. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    so, if you have, say, a combination of frequencies between 100 to 600 Hz, going into the schmitt trigger, what do you think will be coming out?
     
  12. jerrytouille

    Thread Starter New Member

    Mar 23, 2014
    13
    0
    :( crap. i dont know. What will happen then? My guess is the 600hz just overlap the 100hz?
     
  13. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    On the analog side, yes. The output of the schmitt trigger will be completely unpredictable.
     
  14. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,546
    1,252
    I think your plan is solid. The filters might be easier than you think.

    First, lets rein in your expectations a bit. No circuit can "filter out all sound freqs <100Hz". If the corner frequency is 100 Hz, then noise at 50 Hz is attenuated by only 50% (6 dB) with a single-pole filter such as the highpass part of your schematic in post #1. In this application that probably is good enough. You're trying to cut down the noise a bit to reduce timing errors in the PIC, not extract quasar signatures from deep space.

    Given that the mic preamp has 40 dB of gain, you can build the bandpass filter into it by adding exactly one capacitor and adjusting another.

    Highpass - C1, the input coupling capacitor, forms a single-pole highpass filter with R4. Usually you make C1 large enough so that the corner frequency is below audio frequencies. In your case, calculate C1R4 for a corner freq of 100 Hz.

    Note: The total input impedance is R4 plus the output impedance of the microphone element. Starting with the C1R4 calc, then reduce the capacitor value to compensate for the extra impedance. Trial and error probably will be faster than trying to find the true output impedance of the mic.

    Lowpass - Add a capacitor Cx in parallel with R5. Calculate CxR5 for a corner freq of 600 Hz. This will have the same performance as the lowpass part of your bandpass filter out to abut 40 KHz, way beyond the abilities of the opamp.

    Also, at 40 dB of forward gain the LM358 will act as an additional lowpass filter stage with a cutoff freq of 3 KHz due to its internal compensation network.

    ak
     
    Last edited: Apr 4, 2014
    jerrytouille likes this.
  15. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,546
    1,252
    If you pluck two strings at the same time, yes. But this is an instrument tuner, and that application places restrictions on the input. Pluck one string at a time, and any sympathetic vibrations in the adjacent strings should be below the schmidt window and clipped out.

    ak
     
  16. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    You say so. His desired window is 2.5 octaves wide. Overtones kill the concept, IMHO.
     
  17. wayneh

    Expert

    Sep 9, 2010
    12,155
    3,061
    IMHO, you don't want to process the signal AT ALL before it gets to the smart device that can figure out what it's hearing. Why waste time on analog stuff when the real horsepower must be in the microprocessor and the software it is running? That's how the apps do it, after all.
     
  18. jerrytouille

    Thread Starter New Member

    Mar 23, 2014
    13
    0
    @AK you're right the tuner is meant to be very basic and only one string to be strummed at a time when tuning, also noise to be kept at the minimum (so only the sound is from the string). I'll try to redraw the schematic based on your input and post back for further feedback. Thanks for your help.
    @wayneh i was thinking along the same line. Most processing should be done at the MCU level. The hardware basically just to record, eliminate obvious unnecessary frequencies, convert to squarewave and feed into the MCU.

    Now as to think of it, can we just feed the analog signal directly into the PIC (datasheet)? There are 4 analog ports (RA0-RA3) configured by ADCON1 reg. on the PIC.
     
  19. wayneh

    Expert

    Sep 9, 2010
    12,155
    3,061
    I think I'd avoid the attempt to digitize before hitting the MCU. Soooo much more is possible in the MCU than in preprocessing. For instance in the MCU you can dynamically choose the level that defines the cutoff between on and off.
     
  20. jerrytouille

    Thread Starter New Member

    Mar 23, 2014
    13
    0
    Can you elaborate on that a little more? I'm not getting it.
     
Loading...