This article mainly introduces the time domain waveform and spectrum diagram of Python to realize sinusoidal signal, which involves the operation skill of Python mathematical operation and graphics drawing, and the need of friends can refer to
In this paper, we describe the time-domain waveform and spectrogram for realizing sinusoidal signal in Python. Share to everyone for your reference, as follows:
#-*-Coding:utf-8-*-# sine signal time domain waveform and Spectrum map import NumPy as Npimport Matplotlib.pyplot as Plimport matplotlibimport mathimport R Andomrow = 4col = 4N = 500fs = 5n = [2*math.pi*fs*t/n for T in range (N)] # generates 500 dots between 0.0-31.35 # print naxis_x = Np.lin Space (0,3,num=n) #频率为5Hz的正弦信号x = [Math.sin (i) for I in N]pl.subplot (221) pl.plot (axis_x,x) pl.title (sinusoidal signal of U ' 5Hz ', fontproperties= ' Simhei ') pl.axis (' tight ') #频率为5Hz, sinusoidal + noise with a amplitude of 3 X1 = [Random.gauss (0,0.5) for I in range (N)]xx = []# Is there a way to add a direct list of two items?? For I in range (len (x)): Xx.append (x[i]*3 + x1[i]) Pl.subplot (222) Pl.plot (axis_x,xx) pl.title (U ' frequency 5Hz, sine + noise of amplitude 3), fontproperties= ' Simhei ') pl.axis (' tight ') #频谱绘制xf = Np.fft.fft (x) xf_abs = Np.fft.fftshift (ABS (XF)) AXIS_XF = Np.linspace (-n/2,n/2-1,num=n) pl.subplot (223) pl.title (U ' frequency 5Hz sine spectrum map ', fontproperties= ' Simhei ') Pl.plot (AXIS_XF, Xf_abs) Pl.axis (' tight ') #频谱绘制xf = Np.fft.fft (xx) xf_abs = Np.fft.fftshift (ABS (XF)) Pl.subplot (224) Pl.title ( U ' frequency 5Hz sine spectrum graph ', fontproperties= ' Simhei ') pl.plot (axis_xf,xf_abs) pl.axis (' tight ') pl.show()
Operating effect: