1
$\begingroup$

I want to program a microcontroller in C but I am asking about the theoretical aspect of it. I think I've got an idea what I am going to do but there is one thing I can't quite get. To begin with, I will use a guitar, so there is a 82Hz-987Hz range. So roughly, I'm going to low-pass the data on 1KHz, "window" them and apply FFT. Supposedly, I am going to have a good estimate.

Since highest frequency is ~1KHz, I decided my sample rate to be 2KHz (haven't tested yet if it works).

Suppose I have a 2 seconds track with 1 note each second. If the first note is C, my result would be 2000 C notes for the first second right? We can say that every time there is a note change, that's when you recognize a note, so if the second note is D, the program will acknowledge C, then D (and not 2000 times C and 2000 times D). The problem I see, is that if the second note is also C, how would I know that indeed there is a note hitting?

I believe I need an extra step to the process but I can't quite find what would that be. Might be that I have to go a different route though.. (if this is the case just mention the method, no need to elaborate on it and lose your time, I will read about it).

$\endgroup$
1
$\begingroup$

Hotpaw2's reply addressed the note boundary detection problem (envelope tracking is a solution, though they are more robust solutions, look for "onset detection"). A few more comments on your plan:

  • Sampling your signal at 2kHz is going to cause more problems than it is going to solve. The signal from the guitar is not a pure sine wave, so there are harmonics above 1kHz that will be aliased if not filtered properly. This would require very steep anti-aliasing filters, with a very narrow transition band.

  • You have not explained how you intend to compute pitch, but it is very unlikely that your pitch detection method is going to yield a result for every single input sample. More likely, you'll have to find a trade-off (for example through the choice of a FFT or autocorrelation size; or a bandpass filter Q factor) between how often you get a pitch estimate, and how accurate this estimate is.

$\endgroup$
  • $\begingroup$ This is a beginner's project so I am still grasping the basic concepts, that means some of my assumptions could be wrong. 1) About the sample rate, since I am already low-passing the sound at 1Khz it is going to eliminate the majority of harmonics over 1KHz. I just want to find the fundamental frequency and I don't need to reconstruct the signal so I assume that this sample rate won't be much of a problem. $\endgroup$ – user2832080 Oct 11 '13 at 17:47
  • $\begingroup$ 2) I was thinking that I can just find the peak frequency in each of my sample and then somehow I will find when a note is hitting. Granted, it isn't the best method but it's quite simple and the results will be terrible. I haven't tried programming it but playing with sounds and frequency domains on my PC, I can see with naked eye that most times the fundamental frequency is the one peaking. $\endgroup$ – user2832080 Oct 11 '13 at 17:49
  • $\begingroup$ Which filter do you use to limit the bandwidth to 1kHz? How do you determine "the peak frequency" from just one single sample? $\endgroup$ – pichenettes Oct 11 '13 at 18:30
  • $\begingroup$ I am thinking RC filter before ADC. More like the peak frequency each time division. What would be a good time division length in order to apply the window function and FFT? $\endgroup$ – user2832080 Oct 11 '13 at 21:06
  • $\begingroup$ A simple RC filter will only attenuate harmonics, not eliminate them; so they will all be aliased in your 1kHz band and you'll get false readings. FFT is just not the right tool for note detection. $\endgroup$ – pichenettes Oct 12 '13 at 7:34
2
$\begingroup$

Usually, the envelope of a note will decay. A new note pluck will start (add or replace) a new amplitude envelope with an attack transient.

So you might add envelope tracking to your spectral frequency analysis (which may or may not be appropriate for correct pitch estimation).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.