31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
import numpy as np
|
||
|
||
def symmetric_timestamps(total_duration: float, num_points: int, flat_ratio: float = 0.3) -> list:
|
||
"""
|
||
Generate symmetric timestamps with increasing → decreasing → flat → increasing spacing pattern.
|
||
|
||
Args:
|
||
total_duration (float): The total duration (last timestamp).
|
||
num_points (int): Total number of timestamps (must be >= 3).
|
||
flat_ratio (float): Fraction of timestamps in the constant-spacing center (0.0–0.9).
|
||
|
||
Returns:
|
||
List[float]: List of timestamps from 0 to total_duration.
|
||
"""
|
||
n = int(num_points*(1-flat_ratio)/2)
|
||
start = np.cos(np.linspace(0, np.pi, n))+2
|
||
end = np.cos(np.linspace(-np.pi, 0, n))+2
|
||
flat = np.ones(num_points-2*n)
|
||
|
||
timestamps = np.concatenate((start, flat, end))
|
||
timestamps *= total_duration / timestamps.sum()
|
||
timestamps = np.cumsum(timestamps)
|
||
|
||
return timestamps.tolist()
|
||
|
||
|
||
|
||
a = symmetric_timestamps(7.5, 30, 0.7)
|
||
|
||
for i in range(len(a)-1):
|
||
print(f"{a[i]:.2f} - {a[i+1]:.2f} = {a[i+1]-a[i]}") |