Frequency detection (audio)


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653

    Default Frequency detection (audio)

    I keep revisiting this project, then parking it & then resurrecting it...and guess what I've just resurrected it!

    I seek to derive the frequency of a plucked guitar note so I can do lots of funky frequency related stuff to the signal

    I've presently got a PIC (16f1828) a comparator setup & I'm looking at the number of counts timer1 has incremented between each DT comparator interrupt.

    for now I'm usiing a sig gen with a sine wave (yes I realise a guitar note is way more complicated...but I'll cross that bridge blah blah)

    Anyway, by & large it's working OK.....the TMR1 count jitters about a bit, but it's close enough. but what I'm seeing is that with some frequencies the count jitters *way* too much.

    For example, heres a stable-ish(!) timer1 count for 1khz into the PIC comparator.....

    3208
    3203
    3194
    3183
    3161
    3163
    3163
    3156
    3150
    3152
    3148
    3141
    3139

    Ok so it's a little jittery but in percentage terms the jitter is still fairly low, but look what happens when I then feed 800hz into the same same setup....

    4955
    180
    4982
    205
    5012
    176
    4936
    176
    4963
    183
    4988
    207
    5001
    176
    4936
    176
    4957


    ...the Timer1 count between comparator interrupts is all over the shop!

    Can anyone enlighten me why this might be happening?

    here's the interrupt SETUP......

    Code:
    ASM
    INT_LIST  macro ; IntSource,    Label,         Type, ResetFlag?
        INT_Handler  CMP2_INT,  _CMP2_Interrupt,  PBP,  YES 
        endm
        INT_CREATE       ; Creates the interrupt processor
    ENDASM
    
    
    
    CMP2_Interrupt:   ' COMPARATOR2 INTERRUPT.
    @ INT_DISABLE CMP2_INT 
    hserout [dec TMR1,13,10]
    TMR1=0
    @ INT_ENABLE CMP2_INT 
    @ INT_RETURN

    Is my approach wrong here?


    Basically I want this type of sequence...

    1. Guitar string plucked - PIC detects this (envelope detector)
    2. PIC waits about 0.5s (to let the complex harmonics drop out)
    3. PIC then attemps to detect frequency for a period of about 0.3s
    4. Use a look up table for number of counts
    5. Go do stuff with the outcome!


    Now step 4 (go do stuff) I don't need help on - it's step 3 that I'm wondering what the best approach would be?
    Last edited by HankMcSpank; - 7th June 2012 at 14:37.

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audo)

    Hi Hank, just stabbing at this, you second set of numbers is not really all over, every other one is close to the last. I am guessing here maybe timer is overflowing with the lower freq?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audo)

    Quote Originally Posted by cncmachineguy View Post
    Hi Hank, just stabbing at this, you second set of numbers is not really all over, every other one is close to the last. I am guessing here maybe timer is overflowing with the lower freq?
    hi bert,

    Very plausible/good idea, but alas, it's not down to Timer1 overflowing (I worked out that with a 16 bit timer @16Mhz oscillator I can go down to about 58hz before worrying about overflows), for example if i take the frequency even lower than 800hz, it goes fairly stable again, here's 500Hz...

    3120
    3218
    3212
    3208
    3202
    3198
    3194
    3184
    3182
    3179
    3173
    3168
    3163
    3154
    3151
    3150

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audo)

    Are my eyes lying to me or are they the same-ish as for 1K? One must ask them selves How can this be?

    BTW Nice to be back and looking at hanks fun stuff
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audo)

    Quote Originally Posted by cncmachineguy View Post
    Are my eyes lying to me or are they the same-ish as for 1K? One must ask them selves How can this be?
    Good spot!

    Here's approx the Timer counts I'm seeing for different frequencies...

    82.4Hz (lowest note on a guitar) - 42,900 (ish)
    330Hz (top E) - 7,300(ish)
    600Hz - 1800 (ish)

    650Hz -1200(ish)

    & then when I go higher in frequency, the timer1 counts start going all over the place ..

    Here's 800 hz...

    4924
    177
    4940
    177
    4965
    179
    4987

    Oddly, when I dial 1000hz in, yep the counts go to 3,200 again ....so clearly something is wrong with my detection method using interrupts & timer1 counts

    (btw I know the frequencies the PIC is handling internally are correct, as I'm outputting the PIC's comparator output to an external pin & attaching a frequency counter to the pin)

    Hmm [strokes chin]
    Last edited by HankMcSpank; - 7th June 2012 at 16:05.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audo)

    500 hz is the first harmonic negative of 1 Khz. some Pi filters might help or lower the input gain
    Last edited by Archangel; - 7th June 2012 at 16:33.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts