Shop OBEX P1 Docs P2 Docs Learn Events
How can you detect an audio frequency? — Parallax Forums

How can you detect an audio frequency?

lardomlardom Posts: 1,659
edited 2012-02-15 14:36 in Propeller 1
I'm trying to design an object where an led will blink if a microphone detects a certain pitch. I see how a musical note could be transmitted with a counter configured for nco but detecting it is another matter.

Comments

  • LeonLeon Posts: 7,620
    edited 2012-02-15 13:43
    Try Goertzel.
  • groggorygroggory Posts: 205
    edited 2012-02-15 13:50
    How about if you take a microphone, run it through an opamp so it spits out a nice A/C waveform. Then rectify that through a half wave rectifier which will give you a positive pulse every time the A/C waveform is positive. Then count the frequency of those pulses.

    ...I think I'm thinking of this without considering background noise. Don't do this, I bet it won't work.
  • Heater.Heater. Posts: 21,230
    edited 2012-02-15 14:03
    What frequency? To what accuracy or frequency resolution? What other signals or noise may be present at the same time?

    I'd be inclined to use a Fast Fourier Transform for this. The workings of that is hard to understand but using a ready made FFT object is quite easy.

    My FFT object for the Prop is here :http://forums.parallax.com/showthread.php?128292-Heater-s-Fast-Fourier-Transform.
    Ale has an FFT implementation here: http://propeller.wikispaces.com/FFT

    Alternatively there is the Fast Hartley Transform which can also pull frequencies out of signals and should use a bit less space in your Prop:
    http://forums.parallax.com/showthread.php?134261-Fast-Hartley-transform-%28interactive-demo-included%29

  • lardomlardom Posts: 1,659
    edited 2012-02-15 14:08
    @Leon. I plan to use Phil Pilgrims object eventually. At the moment I'm focusing on the direction the sound is coming from and pitch seems to be the easiest way to isolate a sound source from environmental noise.
    @groggory, I've found out an op amp is unnecessary. The "Microphone to VGA" object displays great waveforms even from a distance.
  • lardomlardom Posts: 1,659
    edited 2012-02-15 14:09
    @Heater. I will give that a try.
    @Leon. I know that Goerztel uses frequencies but I don't have the experience to tweak PASM yet.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-15 14:10
    FFT would work, but it's overkill if you already know the frequency you're trying to detect. The Goertzel algorithm is more compact and less compute-intensive:

    -Phil
  • jmgjmg Posts: 15,183
    edited 2012-02-15 14:14
    lardom wrote: »
    I'm trying to design an object where an led will blink if a microphone detects a certain pitch. I see how a musical note could be transmitted with a counter configured for nco but detecting it is another matter.

    If you know what frequency you want, then something like a (venerable) LMF100 in bandpass mode, would give good noise filtering and simple detection ?
    The Prop can nicely generate the clock the LMF100 needs.

    If you want to define that frequency to many digits, then a LMF100 into a Prop Pin, would check period more precisely.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-15 14:18
    You don't need an external filter. The Propeller is entirely capable of doing the detection in software.

    -Phil
  • lardomlardom Posts: 1,659
    edited 2012-02-15 14:36
    @Phil Pilgrim, I will study your code. I was impressed with what NikosG accomplished and I wanted to do my own experiments. Thanks for writing it.
Sign In or Register to comment.