我有以下信号,并希望执行以下操作:
s= 4*np.cos(4*np.pi*pow(10,6)*t+30)+2*np.sin(8*np.pi*pow(10,6)*t+15)+np.cos(12*np.pi*pow(10,6)*t)+0.5*np.cos(16*np.pi*pow(10,6)*t) # the signal
我想用matplotlib和numpy绘制信号频谱,找到它的带宽,并确定它是否是周期性的
我使用这里提供的代码(https://matplotlib.org/3.1.0/gallery/lines_bars_and_markers/spectrum_demo.html)
感谢你的帮助
发布于 2019-06-19 08:05:49
我不能100%确定我现在想要做什么,但似乎绘制和返回函数的所有转折点应该会对你的问题有很大帮助。
因此,您可以尝试以下操作:
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import argrelextrema
def func(t):
# messures the time in units of
# pow(10,6)*t
exp = 4*np.cos(4*np.pi*t+30)+\
2*np.sin(8*np.pi*t+15)+\
np.cos(12*np.pi*t)+\
0.5*np.cos(16*np.pi*t)
return exp
max_time = 2
time_steps = 400
# defining the signal
X = np.linspace(0,max_time,time_steps)
Y = func(X)
# getting all the max and min values
minimas = argrelextrema(Y, np.less)
maximas = argrelextrema(Y, np.greater)
# plot the singal
plt.plot(X,Y)
# plot minimas and maximas
plt.scatter(X[minimas],Y[minimas],color='r')
plt.scatter(X[maximas],Y[maximas],color='g')
plt.xlabel('t*10**6')
plt.ylabel('signal')
plt.show()
https://stackoverflow.com/questions/56661346
复制相似问题