這篇文章主要介紹了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中文網其他相關文章!

pythonisehybridmodeLofCompilation和interpretation:1)thepythoninterpretercompilesourcecececodeintoplatform- interpententbybytecode.2)thepythonvirtualmachine(pvm)thenexecutecutestestestestestesthisbytecode,ballancingEaseofuseEfuseWithPerformance。

pythonisbothinterpretedAndCompiled.1)它的compiledTobyTecodeForportabilityAcrosplatforms.2)bytecodeisthenInterpreted,允許fordingfordforderynamictynamictymictymictymictyandrapiddefupment,儘管Ititmaybeslowerthananeflowerthanancompiledcompiledlanguages。

在您的知識之際,而foroopsareideal insinAdvance中,而WhileLoopSareBetterForsituations則youneedtoloopuntilaconditionismet

ForboopSareSusedwhenthentheneMberofiterationsiskNownInAdvance,而WhileLoopSareSareDestrationsDepportonAcondition.1)ForloopSareIdealForiteratingOverSequencesLikelistSorarrays.2)whileLeleLooleSuitableApeableableableableableableforscenarioscenarioswhereTheLeTheLeTheLeTeLoopContinusunuesuntilaspecificiccificcificCondond

pythonisnotpuroly interpred; itosisehybridablectofbytecodecompilationandruntimeinterpretation.1)PythonCompiLessourceceCeceDintobyTecode,whitsthenexecececected bytybytybythepythepythepythonvirtirtualmachine(pvm).2)

concatenateListSinpythonWithTheSamelements,使用:1)operatoTotakeEpduplicates,2)asettoremavelemavphicates,or3)listcompreanspherensionforcontroloverduplicates,每個methodhasdhasdifferentperferentperferentperforentperforentperforentperfornceandordorimplications。

pythonisanterpretedlanguage,offeringosofuseandflexibilitybutfacingperformancelanceLimitationsInCricapplications.1)drightingedlanguageslikeLikeLikeLikeLikeLikeLikeLikeThonexecuteline-by-line,允許ImmediaMediaMediaMediaMediaMediateFeedBackAndBackAndRapidPrototypiD.2)compiledLanguagesLanguagesLagagesLikagesLikec/c thresst

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

記事本++7.3.1
好用且免費的程式碼編輯器

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Atom編輯器mac版下載
最受歡迎的的開源編輯器