I generated a 16 bit 44100 sample/s WAV file with a sine wave at 440 Hz using Audacity as per the image below:
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:
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:
The plots in Audacity don't move around like mine.
I have two questions:
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?
Why are we seeing frequencies other than 440 Hz in the FFT? Is it purely due to the quantization errors?
Thanks for any insights.




