24 lines
799 B
Python
24 lines
799 B
Python
import pandas as pd
|
|
import numpy as np
|
|
import os
|
|
|
|
fs = 100000 # 100 kHz
|
|
t_total = 0.030 # 30 ms
|
|
# 建立時間陣列:0 ~ 30ms
|
|
t = np.arange(0, t_total, 1/fs)
|
|
|
|
step_mask = t >= 0.001 # 在 1 ms 時觸發 step 改變
|
|
|
|
df = pd.DataFrame({
|
|
'time': np.round(t, 6), # 修正浮點數微小誤差
|
|
'step_0_to_1': np.where(step_mask, 1.0, 0.0),
|
|
'step_0.1_to_0.9': np.where(step_mask, 0.9, 0.1),
|
|
'step_0.2_to_0.8': np.where(step_mask, 0.8, 0.2),
|
|
'step_1_to_0': np.where(step_mask, 0.0, 1.0),
|
|
'step_0.9_to_0.1': np.where(step_mask, 0.1, 0.9),
|
|
'step_0.8_to_0.2': np.where(step_mask, 0.2, 0.8)
|
|
})
|
|
|
|
output_path = os.path.join(os.path.dirname(__file__), 'step_signal.csv')
|
|
df.to_csv(output_path, index=False)
|
|
print(f"成功建立 {output_path},包含 {len(df)} 筆資料點。") |