importnumpyasnpfromscipyimportsignalimportmatplotlib.pyplotaspltw_1=40# frequency of the 1st component of the signal (Hz)w_2=60# frequency of the 2nd component of the signal (Hz)a=0.5# magnitude of the 1st component of the signalb=1.0# magnitude of the 2nd component of the signalt=np.array([iforiinrange(1,301)])/1000# time samples (s)fs=1/(t[1]-t[0])# sampling frequency (Hz)x=a*np.cos(2*np.pi*w_1*t)+b*np.sin(2*np.pi*w_2*t)# considered signaln=.2*np.random.randn(len(t))# white Gaussian noisey=x+nwindows=[None,'hamming']forwindowinwindows:ifwindowisNone:label='rect'else:label=windowf,Pxx_den=signal.periodogram(y,fs=fs,scaling='spectrum',nfft=2048,window=window)plt.semilogy(f[1:200],Pxx_den[1:200],label=label)plt.ylabel('Spectrum')plt.xlabel('Frequencies (Hz)')plt.title('Periodogram')plt.grid(True)plt.legend()plt.savefig("Periodogram windows.svg")
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
to share – to copy, distribute and transmit the work
to remix – to adapt the work
Under the following conditions:
attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.