swharden/Python-GUI-examples

[Question] - Python Gui Examples - SWHear - getFFT()

Niceplace opened this issue · 1 comments

@swharden
Hi Scott !

I'm trying to understand your code, more specifically the math behind it as I am trying to build an audio vizualiser for fun (generate various patterns / colors / shapes on a screen based on real-time analysis of PCM data from a playing song).

I have come to the realisation that I absolutely need to lean how to use FFT and I'm stil figuring it out, I have basic knowledge of math / physics in that regard so I'm not too good but I understand some high level concepts. My question is related to the Hamming Window you seem to be applying on the data chunks before applying the FFT to it, in the getFFT function of the SWHear.py class.

I have included my questions in the comments of the code but please let me add more detail.
My understanding of the Hamming Window is that it helps reduce the noise around the frequency peaks that are generated by the FFT. What I don't understand is why you decided to apply it "out of the blue" instead of analyzing the data first to discover where the actual peaks where before applying the Hamming Window to them. Now this question probably arises because of my lack of knowledge in this field so please don't hesitate to point out where I'm wrong.

Also, I don't get why you do both the FFT and the FFTFreq, I obviously need to do more research on the matter but if you can explain it in a few sentences it would really help :) !

    # Why calculate the hamming on the LENGTH and not the data itself ?
    data=data*np.hamming(len(data))
    fft=np.fft.fft(data)
    fft=np.abs(fft)
    #fft=10*np.log10(fft)
    # Why ffrfreq AND fft ? 
    freq=np.fft.fftfreq(len(fft),1.0/rate)

Thanks for making this, its helping me a lot !