Go Down

Topic: Registering notes (Read 432 times) previous topic - next topic

jacobdensityxvolume

What attachment to the arduino can I use that can register specific notes? (Like in terms of piano notes)

DVDdoug

Sorry, what do you mean buy "register"?

If you want to generate a square wave tone at a known pitch/note, that's easy.    Look at the Play Melody Example.   (There are charts on the Internet for converting notes to frequency.)

If you want to analyze a sound or signal and determine the note, that's tricky because of harmonics & overtones, and if there are chords or multiple sounds/instruments it gets even more tricky.  If you want to try that search for 'FFT' (Fast Fourier Transform) or 'Autocorrelation'.

Grumpy_Mike

Recognising the pitch of a real instrument like a piano is almost impossible to do with 100% accuracy. What exactly are you trying to do that requires this? 

jacobdensityxvolume

I want to recognize the frequency of what note is being played.  It doesn't have to be super accurate, but in the general area.  Is there any way to do that, without the harmonics and stuff?

slipstick

So what are your sound source(s)? Can you guarantee it will always be single notes? What range of frequencies (piano fundamentals are roughly 30Hz to 4000Hz)? How quickly do the notes change? And if you discover a frequency/note e.g. 440Hz/A4 what are you going to do with the information?

Steve

Grumpy_Mike

#5
Sep 14, 2017, 10:25 am Last Edit: Sep 14, 2017, 10:26 am by Grumpy_Mike
I want to recognize the frequency of what note is being played.  It doesn't have to be super accurate, but in the general area.  Is there any way to do that, without the harmonics and stuff?
That is the problem, the harmonics. What tends to happen is that you get the octave wrong. This is because the fundamental is often not the strongest harmonic at any one time.

Again I ask what you are trying to do, it will answer so many questions, like how long is this note and how quickly after one not has been recognised will another one be along.

DVDdoug

Quote
I want to recognize the frequency of what note is being played...  Is there any way to do that, without the harmonics and stuff?
All natural/real-world sounds have harmonics & overtones.   Harmonics & overtones are what makes a guitar sound different from a piano and it's what makes Lady Gaga sound different from Elton John when they are singing the same song and the exact same notes.

If it's an artificially-generated pure-tone tone (or even a square/rectangle wave, which does  have harmonics) you can count the zero-crossings or rising-edges for a period of time and calculate the frequency.  Otherwise, you'll have to use FFT or autocorrelation (and those may, or may-not, work for your requirements).

Quote
It doesn't have to be super accurate, but in the general area.
Musical notes are about 6% apart.*  For example, A = 440Hz and A-Sharp is 466Hz.   A C is about 6% higher than a B, etc.    But, that's not the issue...   The problem is identifing the perceived fundamental pitch out of all the simultaneous frequencies...    If you are off, you probably won't be off by a few-percent and if you are you just pick the closest note.   If you are off, you'll probably be of by a lot.





*That's on the traditional western music scale.

People who have perfect pitch (AKA absolute pitch) can identify the pitch within 3% or better, and they can name the note (without a reference).   That's not good enough to tune a guitar, it's just good enough to name the closest note...    You need a reference-note or a gadget to tune a guitar.    

jacobdensityxvolume

Thanks for your help so far everyone.  Basically what I'm trying to do is recognize the notes from a tuba mouthpiece.  This may work despite the harmonics problem.  My machine will also incorporate a three-button system (the valves), so for each valve arrangement pressed, there are only a few certain notes that can be played.  If an attachment can just find the general area of where the main note is, the machine wil be able to figure out what note is trying to be played.  I know things like tuners can find the note being played, so I'm hoping that along with a valve system I will be able to tell what is being played.

Grumpy_Mike

Ok so we have got that it is a tuba but little else. Are you trying to turn the notes into MIDI? What is the output of recognising a note going to be?

Things like tuners do not get the octiave correct, will that matter to you?

slipstick

I have no idea what sort of sound you get from a tuba mouthpiece with no tuba but how are you planning to capture this sound. Some sort of microphone? What sort?

It sounds like you're planning to make an electronic tuba. Possibly so you can play "silently" through headphones (am I anywhere near?) or maybe to use with a synthesiser. But a tuba plays across at least a 2 octave range so harmonics are definitely going to play a part.

It's a good guessing game isn't it?

Steve

DVDdoug

You'll just have to try a couple of the methods/algorithms to see if you get useful data/numbers.   In addition to FFT & autocorrelation there is something called FHT.   From what I've read autocorrelation works 'best' for guitar tuners, although I haven't read about lots of success making guitar tuners with the Arduino...      As you can see, nobody can predict if you'll be successful or not.

The good news is, a tube can't play chords and it's only one instrument so there's only one note at a time.  

The complete tuba would be easier because it's constrained (by physics & acoustics) to certain notes...     Like a multiple-choice test, it's easier to get the right answer.  (I would imagine it's also more difficult to play in-tune without the resonant tube/pipe attached?)  



-----------------------------------------------------------------------------------------------------------
On the hardware side, of course you'll need a microphone.  You'll also need a preamp to bring-up the millivolt signal to around 1V, and since the Arduino can't read negative voltages the signal needs to be biased.

If you already have a working microphone & preamp (or mixer) the bias circuit only needs 2 resistors and a capacitor.  If you don't have any hardware, a microphone board, with a built-in preamp is the easiest way to go.   At least start with something like that so you can try-out the software before you spend time building hardware.

jacobdensityxvolume

Thank you for all your responses.  I am working sort of on making an electronic tuba like you said.  I think using only the mouthpiece should be fine because it still produces the same note.  With the valve system it will be able to tell the exact note you're going for.  I suppose for now even if it gets the octave wrong that's alright, I just want to get close enough.  Mostly I need help with knowing how to program a microphone board like that, like "if the frequency is between this and this and these valves are pressed then it is this note." How would you do this sort of thing?

DVDdoug

Quote
Mostly I need help with knowing how to program a microphone board like that, like "if the frequency is between this and this and these valves are pressed then it is this note." How would you do this sort of thing?
The GOOD NEWS is, that part is easy!   It's just if-statements and some simple Boolean logic.

-------------------------------------------
The two most important concepts in programming are conditional execution (if statements, etc.)  and loops  (doing something over-and-over, usually until some condition is reached).

slipstick

I think the first thing I'd try is amplifying the sound, filtering it to limit it roughly to the range of fundamental frequencies you want then hard clipping it to approximate a square/rectangular wave. Get that shifted to 0 to 5V and it may be possible to get to an approximate frequency just by measuring and averaging pulse lengths. Crude I admit but it might work.

If you can get a reasonably accurate base frequency the rest is involved but reasonably straightforward programming. Is your output going to be MIDI notes or have you planned some other way of communicating with the rest of your "machine".

Steve

Johan_Ha

I don't know how FFT or autocorrelation works, but 'i've successfully found the frequency of a waveform with this:

Find a zero cross point
Find the next zero cross point with same direction (- to + or + to -)
Check if you found a complete wavelength. Do this by comparing subsequent samples from both zero crossings. Calculate the difference of two samples. Square it. Add it to a sum. Continue with following pair. After adding the squared difference of a fair number of pairs, save the sum.
Advance to the following zero cross point and repeat the action ending in saving the sum. After a while you have some candidates for the wavelength. The one with the least sum is your wave length. From that you can calculate the frequency.

If you play say two octaves, you search for say 60 Hz to 240 Hz. That narrows down things. This method should find the basic frequency, no matter if the harmonics are stronger than the basic frequency, as long as the basic frequency is there.
____________________
- One day my stepper motor driver works like a charm. No task is too big for it and I can do anything with it. Next day it refuses to work and even the tiniest motor blows its fuse. What's wrong with it?
- It's bipolar.

Go Up