I came across this snippet of code in a program that does real time FFT graph of audio data:
data=scipy.array(struct.unpack("%dB"%(bufferSize*2),data))
ffty=scipy.fftpack.fft(data)
ffty=abs(ffty[0:len(ffty)/2])/1000
ffty1=ffty[:len(ffty)/2]
ffty2=ffty[len(ffty)/2::]+2
ffty2=ffty2[::-1]
ffty=ffty1+ffty2
ffty=scipy.log(ffty)-2
I didn’t understand the math behind the part after the abs(). It does something like adding the first half of the magnitude array with the second half reversed, and 2 added.
Is this some kind of normalization?
This is the source:
I don’t know Python but it looks like it’s just adding the magnitude of the two mirror image complex conjugate halves of the real-to-complex FFT output. You could just as easily take only the magnitude of the first half and multiply by 2.
Finally it computes the log magnitude, presumably to get (scaled) dB values.