Python+matplotlib实现计算两个信号的交叉谱密度实例

作者:mengwei 时间:2023-05-12 23:29:55 

 计算两个信号的交叉谱密度

结果展示:

Python+matplotlib实现计算两个信号的交叉谱密度实例

完整代码:


import numpy as np
import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(2, 1)
# make a little extra space between the subplots
fig.subplots_adjust(hspace=0.5)

dt = 0.01
t = np.arange(0, 30, dt)

# Fixing random state for reproducibility
np.random.seed(19680801)

nse1 = np.random.randn(len(t))         # white noise 1
nse2 = np.random.randn(len(t))         # white noise 2
r = np.exp(-t / 0.05)

cnse1 = np.convolve(nse1, r, mode='same') * dt  # colored noise 1
cnse2 = np.convolve(nse2, r, mode='same') * dt  # colored noise 2

# two signals with a coherent part and a random part
s1 = 0.01 * np.sin(2 * np.pi * 10 * t) + cnse1
s2 = 0.01 * np.sin(2 * np.pi * 10 * t) + cnse2

ax1.plot(t, s1, t, s2)
ax1.set_xlim(0, 5)
ax1.set_xlabel('time')
ax1.set_ylabel('s1 and s2')
ax1.grid(True)

cxy, f = ax2.csd(s1, s2, 256, 1. / dt)
ax2.set_ylabel('CSD (db)')
plt.show()

来源:https://matplotlib.org/index.html

标签:python,matplotlib
0
投稿

猜你喜欢

  • 使用Python脚本zabbix自定义key监控oracle连接状态

    2021-01-02 05:23:54
  • python中的__init__ 、__new__、__call__小结

    2021-07-19 20:10:38
  • MySQL数据库实验实现简单数据库应用系统设计

    2024-01-27 04:49:34
  • Python使用apscheduler模块设置定时任务的实现

    2021-05-01 05:01:54
  • 浅谈keras使用预训练模型vgg16分类,损失和准确度不变

    2021-05-25 18:23:40
  • JS实现DOM节点插入操作之子节点与兄弟节点插入操作示例

    2024-04-22 22:35:27
  • 浅析JavaScript对象转换成原始值

    2023-08-05 02:09:11
  • js返回顶部代码

    2011-04-25 19:21:00
  • python字符串切割:str.split()与re.split()的对比分析

    2022-08-09 20:57:13
  • SQLserver查询数据类型为ntext是空或NULL值的方法

    2024-01-24 18:40:52
  • Python实现位图分割的效果

    2021-09-05 11:13:15
  • python连接远程ftp服务器并列出目录下文件的方法

    2023-10-20 10:35:04
  • MySQL创建用户与授权方法

    2024-01-19 02:43:55
  • 浅谈Go语言中的次方用法

    2024-02-17 04:57:08
  • pymongo中group by的操作方法教程

    2021-03-23 05:44:40
  • PyQT5速成教程之Qt Designer介绍与入门

    2023-05-18 22:23:36
  • python实现清屏的方法

    2021-11-02 04:10:32
  • 在macOS上搭建python环境的实现方法

    2021-10-07 07:29:56
  • 使用go xorm来操作mysql的方法实例

    2024-01-18 11:56:35
  • 详解Python牛顿插值法

    2023-03-05 05:58:27
  • asp之家 网络编程 m.aspxhome.com