1
$\begingroup$

I made a spectograpm in C that takes in a wav file (44.1kHz), converts it to 8bit pcm(can't go higher because of memory constraints) and does 1024 sample FFT on a number of bins, using Welch method. I applied the Hamming window in the time domain. In the end all bins are averaged out, converted to a decibel scale, and I get a 1024 point function telling me which frequencies are dominant in the audio file (0-22.05kHz).

It works... sort of. I fed it several test frequencies: 2, 6, 12, and 18kHz. The most noticeable spikes (global maxima) are at said frequencies so I count that as a success, however: there are various other local maxima (said artifacts) that shouldn't be there. For example: 6kHz output shows a large spike at exactly 6kHz, but also a smaller spike at around 12kHz. (and several such smaller spikes in the example for 18kHz) Why?

Several spikes, yet only one frequency present in audio file

Another question I have is: Why do the spikes have a "buildup" to them? Why aren't they just singular discrete spikes like on the picture below? (i.e. there isn't a 5kHz component in the file, it's pure 6kHz, why isn't it just one spike at 6kHz?). Is this spectral leakage? The resolution here is 44100kHz/1024points = 43.06Hz (no multiple of this number results in the above test frequencies). If so how do I fix this (FFT sample size must be a power of 2 since I'm using radix2)?

Below is the example of how I thought it was going to look like (without negative part).

Example

$\endgroup$
1
  • 1
    $\begingroup$ If you want to see pure and singular spikes of pure periodic signals (like sine waves) in the frequency domain, you must use Fourier Series, instead of Fourier Transform. $\endgroup$ Commented Feb 9, 2022 at 11:20

1 Answer 1

1
$\begingroup$

converts it to 8bit pcm

That's unlikely to work for a 1024 length FFT. Your FFT gain for a sine wave is 512 (or 54 dB) where as the gain for a noise like signal is only around 20 (27 dB). In addition you also pick up numerical noise on the order of -50dB or every FFT stage.

but also a smaller spike at around 12kHz. (and several such smaller spikes in the example for 18kHz) Why?

These are most likely harmonics created by some non-linear operation. Could be that you are clipping somewhere or it's truncation/rounding noise.

Is this spectral leakage?

Yes

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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