


Examples of time domain waveforms and spectrograms of sinusoidal signals based on matplotlib Python
This article mainly introduces Python to implement the time domain waveform and spectrogram of sinusoidal signals, involving Python mathematical operations and graphics drawing related operating skills. Friends in need can refer to the following
The examples in this article describe the Python implementation Time domain waveforms and spectrograms of sinusoidal signals. Share it with everyone for your reference, the details are as follows:
# -*- 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()
Operation effect:
Related recommendations:
Example of the least common multiple algorithm implemented in Python
The above is the detailed content of Examples of time domain waveforms and spectrograms of sinusoidal signals based on matplotlib Python. For more information, please follow other related articles on the PHP Chinese website!

Pythonlistsareimplementedasdynamicarrays,notlinkedlists.1)Theyarestoredincontiguousmemoryblocks,whichmayrequirereallocationwhenappendingitems,impactingperformance.2)Linkedlistswouldofferefficientinsertions/deletionsbutslowerindexedaccess,leadingPytho

Pythonoffersfourmainmethodstoremoveelementsfromalist:1)remove(value)removesthefirstoccurrenceofavalue,2)pop(index)removesandreturnsanelementataspecifiedindex,3)delstatementremoveselementsbyindexorslice,and4)clear()removesallitemsfromthelist.Eachmetho

Toresolvea"Permissiondenied"errorwhenrunningascript,followthesesteps:1)Checkandadjustthescript'spermissionsusingchmod xmyscript.shtomakeitexecutable.2)Ensurethescriptislocatedinadirectorywhereyouhavewritepermissions,suchasyourhomedirectory.

ArraysarecrucialinPythonimageprocessingastheyenableefficientmanipulationandanalysisofimagedata.1)ImagesareconvertedtoNumPyarrays,withgrayscaleimagesas2Darraysandcolorimagesas3Darrays.2)Arraysallowforvectorizedoperations,enablingfastadjustmentslikebri

Arraysaresignificantlyfasterthanlistsforoperationsbenefitingfromdirectmemoryaccessandfixed-sizestructures.1)Accessingelements:Arraysprovideconstant-timeaccessduetocontiguousmemorystorage.2)Iteration:Arraysleveragecachelocalityforfasteriteration.3)Mem

Arraysarebetterforelement-wiseoperationsduetofasteraccessandoptimizedimplementations.1)Arrayshavecontiguousmemoryfordirectaccess,enhancingperformance.2)Listsareflexiblebutslowerduetopotentialdynamicresizing.3)Forlargedatasets,arrays,especiallywithlib

Mathematical operations of the entire array in NumPy can be efficiently implemented through vectorized operations. 1) Use simple operators such as addition (arr 2) to perform operations on arrays. 2) NumPy uses the underlying C language library, which improves the computing speed. 3) You can perform complex operations such as multiplication, division, and exponents. 4) Pay attention to broadcast operations to ensure that the array shape is compatible. 5) Using NumPy functions such as np.sum() can significantly improve performance.

In Python, there are two main methods for inserting elements into a list: 1) Using the insert(index, value) method, you can insert elements at the specified index, but inserting at the beginning of a large list is inefficient; 2) Using the append(value) method, add elements at the end of the list, which is highly efficient. For large lists, it is recommended to use append() or consider using deque or NumPy arrays to optimize performance.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment
