问题描述
我有一个有趣的练习,我无法弄清楚.这是练习:
现在从 1 Myr 的时间序列开始,锯齿的平均波长为 0.1 Myr.波长随机变化±0.02Myr(因此在 80 到 120 kyrs 之间),振幅再次为 1.
所以我必须创建一个锯齿函数的时间序列,长度为 1000 kyr,时间步长为 1 kyr.锯齿波的波长必须是随机的,平均为 100 kyr,从 80 kyr 到 120 kyr 不等.我希望时间序列从零开始并以零结束,所以不要在锯齿波中途停止.现在我正在使用这个:
time = np.arange(0,1000,1)func = scipy.signal.sawtooth(2 * np.pi* 0.01 * time-np.pi)
结果如下:
I have an interesting exercise that I cannot figure out. This is the exercise:
So I have to create a time series of a sawtooth function, of 1000 kyrs long with timesteps of 1 kyr. The wavelength of the sawtooths have to be random, with an average of 100 kyr and varying from 80 kyr to 120 kyr. I want the time series to start at zero and end at zero, so not stop halfway during a sawtooth. Right now I am using this:
time = np.arange(0,1000,1)
func = scipy.signal.sawtooth(2 * np.pi* 0.01 * time-np.pi)
Which results in this:
I am trying to figure out how to make the wavelength irregular, but still let the time series end at zero. Does anyone have an idea?
Thanks in advance
You could concatenate waves with distinct wavelengths which you create with np.linspace
and random.randrange
:
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
import random
waveform = np.concatenate(
[signal.sawtooth(2 * np.pi * np.linspace(0, 1, random.randrange(30, 150))) for _ in range(10)]
)
plt.plot(waveform)
plt.show()
The output looks like this:
这篇关于在python中创建不规则锯齿函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!