python - Understanding matplotlib magnitude_spectrum output -


i'm having problems understanding output generated matplotlib's magnitude_spectrum function call.

i have generated sine 50khz frequency,

f_s = 488000.0 # hz t = np.arange(0.0, 1.0, 1/f_s) s1 = 100*np.sin(2*np.pi*50000*t) 

i plot resulting magnitude spectrum, after dividing number of fft bins

s1_magspec = plt.magnitude_spectrum(s1,fs=f_s) plt.plot(s1_magspec[0]/len(s1_magspec[0])) 

the result single spike @ 50khz, magnitude of 50, opposed expected 100.

can explain why is?

here link ipython notebook describing showing afforementioned code , resulting plot:

http://nbviewer.ipython.org/gist/bkinman/22cc15d3ad3b9b2db09e

it looks has default setting fft window used. documentation says default hanning window. if use boxcar window instead:

s1_magspec = plt.magnitude_spectrum(s1, fs=f_s, window=np.ones(s1.shape)) 

you'll peak @ 100, straight numpy fft.

by way, if edited question put in line of code creating s1_magspec rather relying on notebook viewer, link undoubtedly break someday.


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -