Musical Note Detection Possibilities?

erco

Senior Member
I'm working on a music project for the kids, who are learning to play recorders (little flutes). It's simple enough to detect sound versus silence, I'm wondering if there is a simple microphone+audio amp+filter/clip circuit that might condition the recorder sound so a PicAxe could tell the difference between 3 or 4 different tones using COUNT and light different LEDs. The notes can be spaced apart as necessary, don't need to be adjacent.

No doubt, it will come down to the purity of the sound produced (harmonics+other noise) by the recorder. An electronic square wave generator could make audio frequency tones that would be easier to detect, but it would be more magical to use their recorders. My backup plan is using more hardware like several 567 tone decoders, but a software solution would be much simpler.

Has anyone tried anything along these lines? Those little whistle keychain beepers that are nothing but a piezo sensor/speaker and epoxy blob make it look easy.
 

sghioto

Senior Member
Use the pulsin command. Each note generated will be stored as a number in a variable. Pulsin requires a least 1 volt of audio and works better using a square wave.

Steve G
 

premelec

Senior Member
@erco - before you go too far with it all I suggest you build a simple microphone/amp and look at the waveform with an oscilloscope - I used to build and tune bamboo flutes and I recall some harmonic content. I've used a simple PC tuner app "APtuner", I think it's called, that has a "meter" face and shows sharp or flat deviation as well as the note. In any case you'll benefit from averaging as human generated notes tend to waver a bit. I guess the crude tone detection you have in mind for your current project could work out with PULSIN assuming you give it a pretty big range for each note... and kids could whistle as well as play wind instruments :) Have fun!
 

erco

Senior Member
Thanks guys, great points. After doing a little research, I think I'll try a kazoo instead. That buzzy sound has got to be more digital/square wavy than a recorder.

I found the attached "record/playback" circuit at http://www.engineersgarage.com which is a fun site to poke around. It's got a 1-transistor amp input to a PIC ADC, may be a good place to start.
 

Attachments

techElder

Well-known member
Where's your sense of adventure? Get some hardware, man! All you need are a few phototransistors, some LEDs, an 08M2 and a Hope RF transmitter on that kazoo! Do it with hardware! Forget this software stuff! ;)

Actually, I was going to remind you that beginning guitar players keep an electronic tuning device in their case that tells them the notes they are playing. You might find some hardware in one of those to use as input to a PICAXE.
 

hippy

Technical Support
Staff member
I recall a number of threads on guitar tuners so may be worth a forum search.
 

Buzby

Senior Member
Another solution might be to use a 'Frequency to Voltage' converter chip. This would provide a voltage which could be read by ADC much quicker than using PULSIN etc.
Example : http://uk.rs-online.com/web/p/product/5388175/?grossPrice=Y&cm_mmc=UK|Shopping-_-Google+PLA-_-Analog+Devices|Voltage-to-Frequency+&+Frequency-to-Voltage+Converters-_-5388175&kpid=&kpid=5388175&istCompanyId=f7e7b05b-2daf-4c0e-8825-3633baf8113b&istItemId=xwiixpalr&istBid=tzit&gclid=CLGag5SrosMCFWITwwodqisAjw

Yet another idea is to use a 'Spectrum Analyser' chip, here is a simple one : https://www.sparkfun.com/products/10468

However, if you can find an acceptable solution using just a PICAXE it would be interesing to see, I gave up with the drum tuner : http://www.picaxeforum.co.uk/showthread.php?23988-Ideas-needed-for-Drum-Tuner

Cheers,

Buzby
 

nekomatic

Member
Might this offer some starting point:
http://www.picaxe.com/docs/picaxe_sound.pdf
That's just for detecting the presence of a (sufficiently loud) sound - it doesn't give you anything to measure the frequency with.

The sound from a recorder (or flute or whistle) is usually fairly close to a sine wave, while a kazoo is going to have lots of harmonics and possibly non-harmonic extras going on - if I had to pick one I'd try the recorder first, as once you can successfully amplify and threshold it into a square wave, the frequency of the square wave is more likely to be the frequency you actually want to measure.
 

AllyCat

Senior Member
Hi,

I generally agree with nekomatic but I'm not sure that a recoder sound is particularly low in harmonics. In my primary school music class (many, many years ago) the teacher would not allow us to play recorders because of their "harsh" tone and insisted we play his (home-made) bamboo pipe whistles, which did indeed sound much more "mellow".

IMHO what you need is a fairly "pure" (sinusoidal) sound, not a square wave with high harmonics. See my last post #26 on page 3 of this thread and perhaps the whole thread which starts here may give an insight into some of the issues involved. BTW the only difference between the two waveforms in that post is in the phase shift of the higher frequency (relative to the lower) and most audio amplifiers do not maintain a constant phase shift over their frequency range.

The "software" solution is to perform a "Fast Fourier Transform" (FFT) on the waveform/data, but that it way beyond the capability of a PICaxe. Even compiled code for a PIC may struggle; it's really getting into the domain of dedicated Digital Signal Processor chips. IMHO you are going to need some good dedicated hardware assistance, and a few 567 tone decoders actually might be the "easy" way to do it.

Cheers, Alan.
 

sghioto

Senior Member
I breadboarded this circuit with good results. I used a signal generator and amp connected to a speaker as the sound source using this code: edited
Code:
        setfreq m8
 main:pulsin 3,1,w0
     
      if w0 > 219 and w0 < 231 then  '440hz A
      high 0
      goto main
      endif
      low 0
      
      if w0 > 183 and w0 < 195 then  '523hz C
      high 1
      goto main
      endif
      low 1
      
      if w0 > 145 and w0 < 156 then  '659hz E
      high 2
      goto main
      endif
      low 2
      
      if w0 > 120 and w0 < 132 then  '784hz G
      high 4
      goto main
      endif
      low 4
      goto main
Steve G
 

Attachments

Last edited:

geoff07

Senior Member
As you know the exact frequencies you are looking for, I would suggest tuned circuits for each frequency, and have the Picaxe measure the signal level received. I very much doubt you could do much analysis in even a 28X2 at 64MHz. But, as you know the frequencies you don't have to do anything like as much detection in hardware, compared to software. One opamp per channel wired as a bandpass filter, and then a rectifier/capacitor to create a dc signal, into a Picaxe ADC pin would do it. Probably there are more advanced ways available too, perhaps using the MAX263 or similar.

And if the filters are tuned to the fundamental, then the harmonics won't matter.
 
Top