0

I generated a 16 bit 44100 sample/s WAV file with a sine wave at 440 Hz using Audacity as per the image below:

enter image description here

I am trying to compute a N=1024 sliding window FFT of the signal (read in using Python pyaudio), using numpy methods as follows:

buf2 = np.frombuffer(data, dtype=np.int16)
# do FFT 
fft = np.fft.rfft(buf2)
fft = np.abs(fft) * 2.0/N
freqs = np.fft.rfftfreq(N, 1./SR)

Two plots of (freqs, fft) a few multiples of N apart are shown below:

Plot 1

Plot 2

As you can see above, the peaks remain at around 440 Hz, but the far left and far right sides of the plot have different values - these keep jumping around when I try to animate the plot by reading in data continuosly.

I also tried a 50% overlap between the FFT frames, but I get similar results.

Here are the spectrum as shown by Audacity for a rectangular window from two different parts of the audio:

Audacity FFT 1

Audacity FFT 2

The plots in Audacity don't move around like mine.

I have two questions:

  1. Why are the Y values of the graph at the extremes jumping around? Shouldn't the graph remain constant as the signal has only a single 440 Hz frequency?

  2. Why are we seeing frequencies other than 440 Hz in the FFT? Is it purely due to the quantization errors?

Thanks for any insights.

M-V
  • 101
  • 2
  • It's spectral leakage. Does this answer your question? https://dsp.stackexchange.com/questions/63405/spectral-leakage-in-laymans-terms – Hilmar Feb 20 '22 at 09:56
  • Thanks. I am trying to understand it. What I am confused about is that when I do an plot of a 1024 point FFT in any region in the above signal in Audacity, I am seeing the same FFT plot. It's not jumping around as I show above. – M-V Feb 20 '22 at 11:50
  • I believe that Audacity uses a Hanning Window for spectral analysis. – Hilmar Feb 20 '22 at 19:28
  • No, it supports rectangular windows also. Please see my updated question with images. – M-V Feb 21 '22 at 03:43
  • I just found from the Audacity documentation that "Plot Spectrum take the audio in blocks of 'Size' samples, does the FFT, and averages all the blocks together.". So maybe that's why it's not as unstable as my calculation. – M-V Feb 21 '22 at 07:06

0 Answers0