matplotlib学习——案例五:计算两个信号的互谱密度(Compute the cross spectral density of two signals)

import numpy as np
import matplotlib.pyplot as plt

fig,(ax1,ax2) = plt.subplots(2,1)
#调整边距和子图的间距
fig.subplots_adjust(hspace=0.5)
dt = 0.01
t = np.arange(0,30,dt)
np.random.seed(19680801)
#创建两个白噪声
nse1 = np.random.randn(len(t))
nse2 = np.random.randn(len(t))

r = np.exp(-t/0.05)
#convolve是numpy函数中的卷积函数库
cnse1 = np.convolve(nse1,r,mode='same')*dt
cnse2 = np.convolve(nse2,r,mode='same')*dt

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值