Example of time-domain waveform and spectrum diagram for sinusoidal signals based on matplotlib python

Source: Internet
Author: User
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.