2
$\begingroup$

I'm building a sound visualizer with LED strips controlled by python, and I'm trying to learn how to use pyAudio to perform rapid Fourier transforms on live mic input and obtain the average amplitude of a certain range of frequencies.

How do I open a sound stream and consistently update the current amplitude (say, a variable called "amplitude") of a given frequency range with the live FFT data? I have set up all the hardware and all the basic pyAudio functions work so far.

$\endgroup$
  • $\begingroup$ You can grab a chunk of data using the example PyAudio code here: people.csail.mit.edu/hubert/pyaudio/#record-example. Next, you can use numpy.fft.fft to compute the FFT of the most recent data chunk. If you are interested in a frequency range $(f_1, f_2)$ you can look at FFT numbers $\lfloor Nf_1/f_s \rfloor \leq n \leq \lceil Nf_2/f_s \rceil$ where $N$ is the FFT length and $f_s$ is the sampling rate. $\endgroup$ – Atul Ingle Jan 4 '17 at 5:35
0
$\begingroup$

If you know the frequencies you're interested in, you might be better off just calculating the power / energy at those frequencies rather than using a full FFT.

The best algorithm to do that is probably the Goertzel algorithm. There is a python implementation of that here, and a related SP.SE question here.

| improve this answer | |
$\endgroup$

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