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?
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).