Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to measure the frequency of a person humming?

  1. Oct 24, 2009 #1
    Im currently enrolled in embedded systems (so bare with me, Im not too experienced) and we had to come up with a final project for ourselves. Well, I would greatly appreciate some help in understanding some concepts of DSP.

    I am working with the freescale DEMOACKIT with the coldfire MCF51AC256.

    My project will have someone hum into a microphone, and output to a display the musical note that person was humming.

    I want to know if I could get by accomplishing this by amplifying the microphone output, putting it through a bandpass filter, then counting the number of zero passes and determing the frequency of the note that way. Would this work? Im not going for dead on accuracy everytime I use the device, as long as it gets it right most of the time I would be very happy. But, if there is a better way that is doable for me that would get me 100% accuracy, or close to it, I would definitely try.

    Would there be a better way? Again, Im very new to the subject, especially DSP, so layman's terms would be very helpful!
  2. jcsd
  3. Oct 24, 2009 #2


    User Avatar
    Science Advisor
    Gold Member

    Why not simply use FFT to determine the frequency of the fundamental?
  4. Oct 24, 2009 #3
    Every time I see a topic on finding frequencies I see someone suggest FFT. However, I have no clue how to do this. I'm trying to do some research on this but it seems very complicated, because up until 2 days ago I never even knew it existed.

    Can you explain to me what a FFT actually does in layman's terms? What exactly is involved in doing a FFT on an incoming signal? Would counting the number of zero crossings not work as an estimate of the pitch? Even if I were to average?
  5. Oct 24, 2009 #4
    The Fast Fourier transform is only a way of doinh the Discrete Fourier Transfrom quickly.
    Learning about the FFT isn't useful until you know what the DFT does. I recommend the wolfram page about it:

    http://mathworld.wolfram.com/DiscreteFourierTransform.html" [Broken]

    Also look at the fourier transform page.
    Last edited by a moderator: May 4, 2017
  6. Oct 24, 2009 #5
    Why would counting the number of zero crossings not work? Just wondering
  7. Oct 24, 2009 #6


    User Avatar
    Science Advisor

    Why would counting the number of zero crossings not work? Just wondering

    It would work OK. Just amplify it and feed it into a frequency counter.

    If you have one, you should observe the output of your amplifier on an oscilloscope to verify that there isn't enough mains hum (60 Hz or 120 Hz) in the waveform to matter.

    You can also estimate the frequency by using the oscilloscope calibrations. eg 5 mS is the period of a 200 Hz waveform.

    Also, you need to find a good quality microphone and amplifier. Humming is low frequency sound and this is not detected or amplified well with cheap equipment.
    Even then, the person humming should be very close to the microphone.
  8. Oct 25, 2009 #7

    Can you recommend a good microphone and amp I could use?

    Also, if I build this and find I have a lot of mains hum messing with my results, how could I fix it?
    Last edited: Oct 25, 2009
  9. Oct 25, 2009 #8


    User Avatar
    Science Advisor

    It has problems because the amount of harmionics present in "humming" can be large so you actually have a waveform that's more complex than a simple sine wave. As a result you'll often count several zero crossings per cycle of fundamental unless you bandpass filter first. Now there's the problem that the humming frequency may vary considerably from sample to sample so you don't know (apriori) at what frequency to filter.

    The bottom line is that you might be better off to use a DFT implementation. BTW, several years ago I built a guitar tuner using exactly this procedure and it works quite well. It also works for other instruments including "humming". :)
  10. Oct 25, 2009 #9
    Thats cool man! So you basically used a microphone, amplified it, sent it through a bandpass filter, and perfromed a FFT on the signal, and thats where you analyzed the signal in your processor to see what note its in?

    BTW, how hard was it to implement this device? Would you recommend a DFT approach for someone new to embedded systems? Or should I maybe stick with the zero crossings, even though it may not be as accurate? Did you have to manually write the DFT algorithm or was there already a C implementation written up for you somehwere that you found? How accurate is your device? I would love to learn how you accomplished this.
  11. Oct 25, 2009 #10


    User Avatar
    Science Advisor

    Measuring the frequency of someone humming is amusing for about 10 seconds and then you start whistling and this gets boring after about a minute.

    So, I'd suggest you go with whatever microphone or amplifier you can get hold of easily.

    You might have access to an old tape deck. These had microphone inputs and line outputs and were often excellent quality. Some of them even came with matching microphones.

    Nobody wants them because the belts in the tape decks have rotted, but the amplifiers probably still work.
  12. Oct 25, 2009 #11
    One way is to use a simple modulator circuit like in the thumbnail. Be sure to set the resistors to operate the transistors in the linear region. Use headphones to listen to the output. Use a signal generator to give about a volt on the emitter of the top transistor. Use a microphone to provide the hummer signal to lower transistor. Now, Adjust the signal generator frequency and beat the hummer with the signal generator until the beat frequency goes to zero.
    Bob S

    Attached Files:

  13. Oct 25, 2009 #12
    Here is another solution. I have a free program named Audacity installed on my computer. It has a microphone input (as well as other inputs), and is able to record analog audio streams digitally. It also has a FFT transform built in and can plot frequency spectrums (spectra?).
    Bob S
  14. Oct 25, 2009 #13


    User Avatar
    Science Advisor

    Good idea.

    I have a computer program called Spectran which gives a direct readout of the strongest audio frequency it is receiving. It doesn't matter if other signals or harmonics are present.

    This program is available, free, from:
  15. Oct 26, 2009 #14
    The freeware Matlab clone, Scilab, is wonderful at showing all the harmonics but takes a lot more effort to get working than Audacity (I used scilab to determine the fundamental resonant frequency of the body of my guitar).
  16. Oct 26, 2009 #15
    There is a really good demonstration of the way Fourier series work at this link:
    The link provides a Java applet which allows the viewer to play with the amplitudes of the sin and cos harmonics so they can see what is going on.
  17. Oct 26, 2009 #16


    User Avatar
    Science Advisor

    It's hard to say, you might be able to get the zero crossing method to work reliably enough if you normalize the amplitude and apply enough hysteresis to avoid "double crossings". Whether or not you'd choose an FFT implementation would also depend on the availability (or otherwise) of floating point operations on your embedded system. FFT is definitely a lot easier if floating point is available.

    Though your target implementation is the embedded system there is no reason why you can't experiment with algorithms etc with just your PC and some basic waveform editor software. You should try capturing some humming samples on soundcard and take a look at what you're up against. Do you have matlab? If not then download one of the freeware "clones" like "gnu octave".

    Here's an example for you. I hummed into my (headset) microphone and captured a few seconds in a waveform editor. My professional guitar tuner told me it was "A" at about 20% of a semitone flat, which equates to approx 145 Hz. Attached is an approx 0.5 second sample of the raw waveform (sampled at 44100Hz) along with a plot of the both time domain and FFT signals.

    As you can see, from the FFT it is very easy to identify the correct frequency of about 145Hz (along with copious 2nd and 3rd harmonics). A simple zero crossing analysis of the raw data however returned a count of 263 zero crossing corresponding to an incorrect frequency reading of about 259 Hz.

    Attached Files:

  18. Oct 26, 2009 #17
    Wow, interesting results. It definitely seems like doing an FFT on the signal would be the best way to go about this. Thank you for those images.

    Does anyone know of a place I can see samples of actual FFT code performed on some sort of signal? Im trying to learn as much as I can about this process right now, but I have to have this done in about 5 weeks, and this is pretty complicated by what Ive seen so far. I would love to actually see something written out so I can actually see it rather than try to conceptualize it all.
  19. Oct 26, 2009 #18
    What level of 'code' do you want to see? I could direct you to the example files for FFT on 'Scilab', which you could download and install in half an hour. The example routine first makes a signal out of trig functions, then analyses it using the FFT. You'd see how the syntax of the application works and be able to apply it to your your own .wav files.
    If this sounds like what you want simply download the appliction (very easy to find on the web) and start hacking. Please feel free to contact me personally and tell me how you're getting on, since I know that it took me some time to learn this software and I expect it'll be the same for you.
  20. Oct 26, 2009 #19
    Well Im using CodeWarrior with Processor Expert for my project and learned that Processor Expert actually has a FFT bean! Which is good news for me, but only after I actually learn a little more about the transformation.

    When performing a FFT on the data I'm feeding in from the microphone, would I be performing a Real forward FFT? I have 4 choices of Real forward, real backward, complex forward, or complex backward.

    Also, the FFT bean I have performs the Fast Hartley transform. Is this the one I should be using?
    Last edited: Oct 26, 2009
  21. Oct 27, 2009 #20
    A forward fft takes you from time domain to frequency domain, the backward fft takes you the other way.
    I wonder whether the 'complex' options require 2 arguments (real, imaginary) in each channel of signal? Though I'm rather sticking my neck out here I'd say you have only the option of 'real' analysis on your single-channel signal.
    Fast Hartley?
  22. Oct 27, 2009 #21


    User Avatar
    Science Advisor

    As you can see, from the FFT it is very easy to identify the correct frequency of about 145Hz (along with copious 2nd and 3rd harmonics). A simple zero crossing analysis of the raw data however returned a count of 263 zero crossing corresponding to an incorrect frequency reading of about 259 Hz.

    I've owned a few frequency counters and built a few more and I have never seen one that counted zero crossings.
    Invariably, the input signal drives a counter chip or a gate and these operate below a certain level for a zero and above another level for a 1. These might be below 1 volt for a Zero and above 4 volts for a 1.

    If you have one that uses zero crossings, don't use it. It would give oddball readings.

    Also, don't overdrive a frequency counter. Small harmonic bumps can get big enough to get counted on their own.
  23. Oct 27, 2009 #22


    User Avatar
    Science Advisor

    Yes of course that naive zero crossing example I gave was simply to point potential pitfalls of counting frequency.

    "These might be below 1 volt for a Zero and above 4 volts for a 1." Yes that's exactly equivalent to having some "hysteresis" like a Schmitt trigger before the zero crossing detector. That is what I was suggesting to the OP. I showed the waveform will a simple ZC detector to demonstrate why it's needed. :) As I pointed out earlier you need to control the waveform amplitude in relation to the hysteresis thresholds in order to make that work reliably.
  24. Oct 27, 2009 #23
    Yes Im definitely going to go the FFT route with this project. Even though it seems a lot harder because I'm having to learn a complex subject in a very limited amount of time, I think I'll be able to. Plus hopefully it will turn out to do exactly what I want it to do. Thats alway nice :)

    So Ill definitely be doing a real forward FFT on my signal correct? And is the Fast Hartley okay for this?

    So, just to do a little flow chart real quick, the signal will be coming in through the microphone. I will then pass it through an amplifier, probably an LM358?. I will then pass it through a bandpass filter (this is necessary correct?), and then pass that to the ADC in my processor. I will then fill an array with a lot of samples from the inputted sound, and after its filled will pass it through the FFT and out comes a frequency. Then all I need to do is have a bunch of conditions to match the frequency to an A or B or whatever, then output the result to my screen.

    Am I missing something?
  25. Oct 28, 2009 #24
    Last edited: Oct 28, 2009
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook