Shop OBEX P1 Docs P2 Docs Learn Events
Measuring audio frequency — Parallax Forums

Measuring audio frequency

Donald WheelerDonald Wheeler Posts: 10
edited 2006-03-27 03:37 in BASIC Stamp
Does anyone have any ideas on how to best measure an audio frequency with a basic stamp?

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-03-26 13:09
    Donald -

    What is it exactly that you are trying to measure, in terms of an audio signal? The answer I'm looking for may be as simple as the output of an audio generator, or as complex as an entire symphony orchestra, or something in between. Obviously different methods would be used for each.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-03-26 19:42
    Donald, like Bruce mentioned, the complexity of the audio signal produced greatly affects the ease in which you can measure the frequency. If it is a pure sine wave, square wave, or saw tooth wave, then it is a relatively simple task to measure the frequency. But once you start trying to measure the frequency of real world instruments you can run into really difficult situations. This is because of two properties of musical instruments, they produce harmonics (ie an instrument playing a 1kHz note is also producing various amplitudes of 2kHz, 3kHz etc, some instruments will even have a measurable 5th harmonic). These harmonics and the corresponding amplitues wrt the base frequency is what creates the richness in sound produced by instruments and is called the timbre of the instrument. Another factor to consider is that most instruments have 3 phases of any note played, the first is the setup period (called the attack) where it takes a bit of time before the note reaches it's resonance, until that resonance is reached the waveform can appear chaotic and difficult to measure. The second pase is the main part of the note and it is called the sustain where resonance is reached and the note is being played at its loudest. This period is where you want to measure the frequency. The 3rd phase is called the decay when the note tapers off or is stopped, because the note is getting softer, its harder to measure the frequency.

    So when measuring the frequency of a musical instrument you have to be able to pick out the main note from its harmonics, and you need to know where in the phase of the envelope the instrument is playing. Neither of these are very easy to accomplish without using spectral analysis, which is a digital signal processing technique that the stamp is not powerful enough to do.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Donald WheelerDonald Wheeler Posts: 10
    edited 2006-03-27 03:10
    I am measuring the output of a metal detector. I am interested in having the basic stamp tell if metal detected or not. smile.gif
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-03-27 03:37
    Well then, measuring the frequency should be easier. There is a guy on the forums who has been working on a guitar tuner (you can read his thread here: http://forums.parallax.com/showthread.php?p=552903). Basically what you want to do is amplify the signal, the "squarify" it (make it a square wave), so you have an amplifier block followed by a comparator. You then use the COUNT function on th BS2 to get the frequency. If you use Piper's schematic as a base line, you wont need the mike preamp circuit, and he does alot of filtering you may or may not need, also follow Tracy's suggestions on corrections to the schematic.

    I would suggest you learn about opamps and comparators before trying to "plug and play" Piper's circuit, because chances are it wont work at first (analog circuitry can be picky especially if your not sure what things do). That way you can figure out what to change to make it work. Also an oscilloscope is highly recomended if not required for working with analog circuitry.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
Sign In or Register to comment.