0
$\begingroup$

I'm trying to do an FFT on live audio to see its spectrum.

So I have a sampling rate of 44100 Hz and from this take out 1024 bins on my FFT

So to test it I play a continuous tone at 15000 Hz and another one at 16000 Hz and look for it on my spectrum. I try to use higher ones to cut out noise from around. I have made the sound in a way there is no clipping

The thing is when I look at the individual frames of the FFT in each 2048 byte block of data I can see the peaks at these frequencies but some frames won't have the peaks, yet the others would.

How can this happen? How can I avoid it or what can I do to the way I'm reading the audio so that I can see the two tones in every frame?

$\endgroup$
  • $\begingroup$ You need to make plots of the spectra and look at them and show them to us to figure out what's wrong $\endgroup$ – endolith Aug 2 '13 at 16:23
-1
$\begingroup$

Not sure I understand your question exactly, but make sure to take the magnitude not just the real/imaginary components. Also, it will probably help to window your incoming data, and it sounds like you aren't doing that. For further detail and even some sample code, see here:

http://blog.bjornroche.com/2012/07/frequency-detection-using-fft-aka-pitch.html

$\endgroup$
2
$\begingroup$

You might be looking only at the cosine component (sometimes called the even or real component) of the FFT result, instead of the magnitude of each entire complex FFT result vector. The real component will vary as your test signal goes in and out of phase with the cosine basis vectors (always even functions) of each frame, even if the complex bin magnitude stays constant (or varies only slightly due to windowing scalloping).

mag[i] = sqrt(real[i]*real[i] * imag[i]*imag[i]);

$\endgroup$
  • $\begingroup$ I'm already doing this, previously I had this 'beating' which occurred when the wave went out of phase to the sin portion. Is there anything else that can do this? Is there a chance it could fall into a different bin? I'm only looking at 15000 Hz and 16000 Hz $\endgroup$ – user2610470 Aug 2 '13 at 14:56
1
$\begingroup$

If you are looking at only those bins, you will not be accurate. Some energy is transferred to the neighboring bins. You need to set a threshold and assume its existence if you bin has a value greater than the threshold. Fixing the threshold is a task of lots of experimenting.

$\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.