swharden/FftSharp

Bug in frequency analysis near Nyquist limit?

Closed this issue · 2 comments

I've noticed a strange phenomenon. Maybe it's normal but I compared it to the results in Audition and it doesn't seem right.

Steps to reproduce: Create a 48kHz file. Within that file, create a 23,500 Hz signal.

Now use FFTSharp on this with a window size of 32. I'm using a Hanning window but I've gotten similar results with other windows.

Slide the window sample by sample across the file and you'll notice that in a regular interval, the highest bin (index 16) in the output of FFTmagnitude turns to zero or very close to zero. If you save these results into an array and use that to create an audio file, you'll end up with a loud 1kHz signal and a lot of overtones at 1kHz intervals. But what you really should be getting is something close to a flat constant number, since it's a constant tone and a bin size of 32 at 48kHz should be enough to analyze 23,500 Hz, or is it not?

Now, when I look at the wave reconstruction of that 23,500 Hz signal in Audition, I can see that the amplitude goes a little bit up and down (I don't understand why either, as resampling to 192kHz with a good algorithm seems to eliminate any such perceptible up and downs), but it never reaches zero. The fft analysis in Audition also correspondingly to the "changing" amplitude goes a little bit up and down at the same window size, but it's always only a difference of about 5 dB, it definitely never comes close to zero.

Index 15 in the FFT on the other hand seems to give more reasonable results, never quite reaching zero, but still oscillates too much for my taste.

Reason this is a problem for me is that I'm trying to do amplitude modulation and using FftSharp to decode the signal, and this way I end up with a 1 kHz (+overtones) signal strongly overpowering the original signal.

Is this to do something with an imperfect reconstruction of the full wave used for the frequency analysis? If so, what could be done about it? Is it a user error of mine?

Thanks!

Just tried again with 22 kHz and curiously enough, it happens too, except this time it "zeros" at a rate of 4kHz. That can't be right, can it? This time bin 15 seemed pretty steady but bin 16 is just jumping all over the place.

Hi @TomArrow, do you have pictures or graphs you could show to demonstrate this?

EDIT: A code sample demonstrating your concern would be ideal

EDIT2: A code sample demonstrating this issue in Python would be interesting, as it would confirm that this is not a FftSharp question but rather a general question about FFTs.

constant tone and a bin size of 32 at 48kHz should be enough to analyze 23,500 Hz

It sounds like you are right at the edge of what is detectable, and your signal is probably overwhelmed with quantization artifacts and aliasing. Inspecting graphs might be the best way to figure out what is going on here.

Do these resources help answer your question?