这篇文章主要介绍了Python实现正弦信号的时域波形和频谱图,涉及Python数学运算与图形绘制相关操作技巧,需要的朋友可以参考下
本文实例讲述了Python实现正弦信号的时域波形和频谱图。分享给大家供大家参考,具体如下:
# -*- coding: utf-8 -*- # 正弦信号的时域波形与频谱图 import numpy as np import matplotlib.pyplot as pl import matplotlib import math import random row = 4 col = 4 N = 500 fs = 5 n = [2*math.pi*fs*t/N for t in range(N)] # 生成了500个介于0.0-31.35之间的点 # print n axis_x = np.linspace(0,3,num=N) #频率为5Hz的正弦信号 x = [math.sin(i) for i in n] pl.subplot(221) pl.plot(axis_x,x) pl.title(u'5Hz的正弦信号',fontproperties='SimHei') pl.axis('tight') #频率为5Hz、幅值为3的正弦+噪声 x1 = [random.gauss(0,0.5) for i in range(N)] xx = [] #有没有直接两个列表对应项相加的方式?? for i in range(len(x)): xx.append(x[i]*3 + x1[i]) pl.subplot(222) pl.plot(axis_x,xx) pl.title(u'频率为5Hz、幅值为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'频率为5Hz的正弦频谱图',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'频率为5Hz的正弦频谱图',fontproperties='SimHei') pl.plot(axis_xf,xf_abs) pl.axis('tight') pl.show()
运行效果:
相关推荐:
以上是基于matplotlib Python实现正弦信号的时域波形和频谱图示例的详细内容。更多信息请关注PHP中文网其他相关文章!

pythonuseshybridapprace,ComminingCompilationTobyTecoDeAndInterpretation.1)codeiscompiledtoplatform-Indepententbybytecode.2)bytecodeisisterpretedbybythepbybythepythonvirtualmachine,增强效率和通用性。

theKeyDifferencesBetnewpython's“ for”和“ for”和“ loopsare:1)” for“ loopsareIdealForiteringSequenceSquencesSorkNowniterations,而2)”,而“ loopsareBetterforConterContinuingUntilacTientInditionIntionismetismetistismetistwithOutpredefinedInedIterations.un

在Python中,可以通过多种方法连接列表并管理重复元素:1)使用 运算符或extend()方法可以保留所有重复元素;2)转换为集合再转回列表可以去除所有重复元素,但会丢失原有顺序;3)使用循环或列表推导式结合集合可以去除重复元素并保持原有顺序。

fasteStmethodMethodMethodConcatenationInpythondependersonListsize:1)forsmalllists,operatorseffited.2)forlargerlists,list.extend.extend()orlistComprechensionfaster,withextendEffaster,withExtendEffers,withextend()withextend()是extextend()asmoremory-ememory-emmoremory-emmoremory-emmodifyinginglistsin-place-place-place。

toInSerteLementIntoApythonList,useAppend()toaddtotheend,insert()foreSpificPosition,andextend()formultiplelements.1)useappend()foraddingsingleitemstotheend.2)useAddingsingLeitemStotheend.2)useeapecificindex,toadapecificindex,toadaSpecificIndex,toadaSpecificIndex,blyit'ssssssslorist.3 toaddextext.3

pythonlistsareimplementedasdynamicarrays,notlinkedlists.1)他们areStoredIncoNtiguulMemoryBlocks,mayrequireRealLealLocationWhenAppendingItems,EmpactingPerformance.2)LinkesedlistSwoldOfferefeRefeRefeRefeRefficeInsertions/DeletionsButslowerIndexeDexedAccess,Lestpypytypypytypypytypy

pythonoffersFourmainMethodStoreMoveElement Fromalist:1)删除(值)emovesthefirstoccurrenceofavalue,2)pop(index)emovesanderturnsanelementataSpecifiedIndex,3)delstatementremoveselemsbybybyselementbybyindexorslicebybyindexorslice,and 4)

toresolvea“ dermissionded”错误Whenrunningascript,跟随台词:1)CheckAndAdjustTheScript'Spermissions ofchmod xmyscript.shtomakeitexecutable.2)nesureThEseRethEserethescriptistriptocriptibationalocatiforecationAdirectorywherewhereyOuhaveWritePerMissionsyOuhaveWritePermissionsyYouHaveWritePermissions,susteSyAsyOURHomeRecretectory。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

记事本++7.3.1
好用且免费的代码编辑器