admin管理员组

文章数量:1290179

How can I modify my code to get biphasic pulses with 1 us long pulses and 1 us long pauses between each pulse. What ever I try, I am not able to generate such short pulses.. I managed to make it in Matlab but in Python I can't seem to make it work. Can someone help please?

MAIN PROBLEM: I need to have code where I can set my own duration of pulse and pause (which are 1 us - 0.1 ms). Right now my code is giving me too long pulses and I can't directly set for instance pulse_width=0.001 and break_width=0.001.

pointCount = 5000
voltages = np.empty(pointCount)
times = np.arange(pointCount) * 0.05

# Stimulus:
stim = np.zeros(pointCount)
amplitude = 1  # Pulse amplitude
num_pulses = 400  # Number of biphasic pulses
pulse_width = 2   # Width of each pulse (samples)
break_width = 2   # Break duration (samples)
start_index = 1200  # Start of first pulse

# Generate 50 biphasic pulses
for i in range(num_pulses):
    index = start_index + i * (2 * pulse_width + 2 * break_width)  # Calculate start index for each pulse pair
    stim[index:index + pulse_width] = amplitude    # Positive pulse
    stim[index + pulse_width + break_width:index + 2 * pulse_width + break_width] = -amplitude  # Negative pulse

plt.figure()
plt.plot(times, stim, 'r')
plt.xlabel('Time (ms)')
plt.ylabel('Amplitude (mV)')
plt.show()

本文标签: Biphasic pulses in PythonStack Overflow