import matplotlib.pyplot as plt sample_rate = 100000 # Hz on_time = 300e-6 # 300 microseconds off_time = 300e-6 on_samples = int(on_time * sample_rate) off_samples = int(off_time * sample_rate) bool_array = ( [True] * on_samples + [False] * off_samples ) # repeat several cycles bool_array = bool_array * 5 time = [] voltage = [] for sample, bit in enumerate(bool_array): time.append(sample / sample_rate) voltage.append(1.0 if bit else 0.0) plt.figure(figsize=(10,4)) plt.step(time, voltage, where="post") plt.xlabel("Time (seconds)") plt.ylabel("Voltage") plt.title("300us ON / 300us OFF Digital Wave") plt.grid(True) plt.ylim(-0.2, 1.2) plt.show()