[Python] Biphasic pulses in Python

Discussão em 'Python' iniciado por Stack, Fevereiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    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?

    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()


    [​IMG]

    Continue reading...

Compartilhe esta Página