gpt4 book ai didi

python - 优化时间线构建器功能

转载 作者:行者123 更新时间:2023-12-01 02:08:09 25 4
gpt4 key购买 nike

我有一个频率为 f 的平方信号,我对平方开始的时间感兴趣。

def time_builder(f, t0=0, tf=300):
"""
Function building the time line in ms between t0 and tf with a frequency f.
f: Hz
t0 and tf: ms
"""

time = [t0] # /!\ time in ms
i = 1
while time[len(time)-1] < tf:
if t0 + (i/f)*1000 < tf:
time.append(t0 + (i/f)*1000)
else:
break
i += 1
return time

因此该函数在 t0 和 tf 之间循环以创建一个列表,其中是方 block 开始的时间。我很确定这不是最好的方法,我想知道如何改进它。

谢谢。

最佳答案

如果我的解释是正确的,那么您正在寻找从 t0 开始到 tf 结束的波浪时间列表。

def time_builder(f, t0=0, tf=300):
"""
Function building the time line in ms between t0 and tf with a frequency f.
f: Hz
t0 and tf: ms
"""
T = 1000 / f # period [ms]
n = int( (tf - t0) / T + 0.5 ) # n integer number of wavefronts, +0.5 added for rounding consistency
return [t0 + i*T for i in range(n)]

关于python - 优化时间线构建器功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48862435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com