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

yipeiwu_com6年前Python基础

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

结果展示:

完整代码:

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()

总结

以上就是本文关于Python+matplotlib实现计算两个信号的交叉谱密度实例的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

相关文章

Python图像处理之图片文字识别功能(OCR)

Python图像处理之图片文字识别功能(OCR)

OCR与Tesseract介绍 将图片翻译成文字一般被称为光学文字识别(Optical Character Recognition,OCR)。可以实现OCR 的底层库并不多,目前很多库都...

.dcm格式文件软件读取及python处理详解

要处理一些.DCM格式的焊接缺陷图像,需要读取和显示.dcm格式的图像。通过搜集资料收集到一些医学影像,并通过pydicom模块查看.dcm格式文件。 若要查看dcm格式文件,可下Ech...

python3+mysql查询数据并通过邮件群发excel附件

本文实例为大家分享了python3邮件群发excel附件的具体代码,供大家参考,具体内容如下 连接、查询mysql,导入到excel文件,定时群发邮件与附件。 主要用到pymysql...

基于Python中numpy数组的合并实例讲解

基于Python中numpy数组的合并实例讲解

Python中numpy数组的合并有很多方法,如 - np.append() - np.concatenate() - np.stack() - np.hstack() - np...

wxPython实现窗口用图片做背景

wxPython实现窗口用图片做背景

本文实例为大家分享了wxPython实现窗口用图片做背景的具体代码,供大家参考,具体内容如下 效果图:   实现代码: #!/usr/bin/env python # -...