Archived

This topic is now archived and is closed to further replies.

kieren_j

Finding Peak Frequency (audio; FFT perhaps)

Recommended Posts

Hi there, the topic says it all really. I''m determining (in realtime) which note is being played by a guitar (clean, naturally, not distorted). At the moment, I multiply each sample in the recorded data by different sine waves -- one for each frequency in my table of musical note frequencies. Adding together the results of this multiplication for each sample appears to work -- to a certain extent. The highest score "wins", and around 50% of the time, it''s accurate! But.. I''m sure im doing lots of unnecessary calculations. I''ve looked into FFT, I''m wondering whether it would be the best solution; then just search the result for the peak, translate it into the nearest note etc.. but i''m really hoping theres some other (simpler?) way of getting the peak frequency. I''m taking Maths Mechanics in college here in the UK, but when I see the FFT alogrithm I''m still a little confused - we haven''t covered imaginary numbers or great use of the sigma symbol, big vectors, stuff like that Can anyone help mes? Thanks Kieren

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Fourier transform is the way to go. You don''t really need to know the inner workings of it either, just use a free library to do the job.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
Fourier transform is the way to go. You don''t really need to know the inner workings of it either, just use a free library to do the job.


Cool. FFTW looks to be popular/free, but well, I dont understand how to use it.
I put in "n" samples and naturally get "n" samples out. But I get real and imaginary parts out, what do I use..? Which samples corresponds to which frequency? How many samples should I use to be able to measure 32Hz to 5KHz? I realise 10,000 samples are needed to represent a 5KHz wave, but would the 10,000 output samples be good enough?
A few more pointers/pushes in this direction would really be very well received!

Thanks!
Kieren

Share this post


Link to post
Share on other sites
quote:
Original post by kieren_j

At the moment, I multiply each sample in the recorded data by different sine waves -- one for each frequency in my table of musical note frequencies. .



FFT works something like this, but it extracts all bands within it's resolution to cosine wave coefficients.
The complex results contain the levels as well as phases of each band, but you don't need phases at all when calculating peaks.

-Nik

EDIT: To clarify, the real results contain the levels of each band, and imaginary contain the phases.

[edited by - Nik02 on October 23, 2003 2:38:49 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
To get the amplitude of a frequency you calculate the magnitude of the complex output, ie sqrt(x^2 + y^2), where x and y are the real and imaginary parts. The frequency of the n:th output sample is n/T where T is the length (in time) of the sample. The highest frequency will always be half of the sample rate. So, if you use a sample rate of 20kHz and take 5000 samples you will get a spectrum ranging from 0 to 10kHz in 4Hz intervals.

Share this post


Link to post
Share on other sites