theaterbas.blogg.se

Fft windowing
Fft windowing












fft windowing

Then you should note that the graph on Wikipedia is actually shown with amplitudes in decibels. To get around this problem we simply need to swap the lower and upper parts of the arrays with np.fft.fftshift: ax5.plot(np.fft.fftshift(fft_freq_axis),np.fft.fftshift(abs(fft_hann))) Indeed, if we print the fft_freq_axis we can see that the result is: The routine np.fft.fftfreq(n) returns an array giving the frequencies of corresponding elements in the output. Then A contains the positive-frequency terms, and A contains the negative-frequency terms, in order of decreasingly negative frequency. The values in the result follow so-called “standard” order: If A = fft(a, n), then A contains the zero-frequency term (the sum of the signal), which is always purely real for real inputs.

fft windowing

Then we notice that there is still a line striking through our plot. To generate a graph which looks like the one from Wikipedia, you would have to take the magnitude (instead of the real part) with: ax5.plot(fft_freq_axis,abs(fft_hann)) You may in fact be getting the warning ComplexWarning: Casting complex values to real discards the imaginary part as a result. The first is that this command essentially attempts to plot a complex-valued array ( fft_hann). There are a number of issues with the way the plot is constructed. Instead of the expected graph from Wikipedia. It appears the plot which is problematic is the one generated by: ax5.plot(fft_freq_axis,fft_hann) Wsin_spec_freq_axis=np.fft.rfftfreq(len(num),d=1/sample_freq)Īx3.plot(lin_spec_freq_axis,lin_spec,'r')ĮDIT: as asked in the comments, i plotted the functions in dB scale, obtaining much clearer plots. Wsin_spec=sqrt(2)*np.abs(np.fft.rfft(wsin))/len(num) Wlin_spec=sqrt(2)*np.abs(np.fft.rfft(hann))/len(num) Lin_spec_freq_axis=np.fft.rfftfreq(len(num),d=1/sample_freq)

fft windowing

Lin_spec=sqrt(2)*np.abs(np.fft.rfft(sin))/len(num) function to get leak, putting a 1 straight for the 300 first items of the array, the result: The middle plots are pure FFT plot, here is where i get weird things. Im playing with python and scipy to understand windowing, i made a plot to see how windowing behave under FFT, but the result is not what i was specting.














Fft windowing