pulsegen.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Created on 25.06.2015
  4. @author: frank
  5. '''
  6. def create_pulse_times(start, n, duration, period):
  7. return reduce(lambda a, b: a+b,
  8. [[start+i*period, start+i*period+duration]
  9. for i in range(n)])
  10. def create_pulse_gen_dict(duration=2., period=10., amplitude=1000., n=10, start=10.):
  11. assert period >= duration
  12. pulse_times = [0.,] + create_pulse_times(start, n, duration, period)
  13. pulse_values = [0.,] + [amplitude, 0.]*n
  14. return {'amplitude_times': pulse_times, 'amplitude_values': pulse_values}
  15. def create_burst_gen_dict(duration=2.,
  16. n_spikes=5,
  17. spike_frequency=200.,
  18. period=500.,
  19. amplitude=1000.,
  20. n=5, start=10.,
  21. start_spike_amplitude=0.,
  22. start_spike_time=5.,
  23. start_spike_duration=2.):
  24. spike_period = 1000./spike_frequency
  25. single_burst_duration = spike_period*n_spikes
  26. assert duration < single_burst_duration
  27. assert period >= single_burst_duration
  28. pulse_times = reduce(lambda a, b: a+b, [create_pulse_times(start+i*period, n_spikes, duration, spike_period)
  29. for i in range(n)])
  30. pulse_values = [amplitude, 0.]*n*n_spikes
  31. pulse_times.insert(0, 0.)
  32. pulse_values.insert(0, 0.)
  33. if start_spike_amplitude > 0.:
  34. pulse_times.insert(1, start_spike_time)
  35. pulse_values.insert(1, start_spike_amplitude)
  36. pulse_times.insert(2, start_spike_time+start_spike_duration)
  37. pulse_values.insert(2, 0.)
  38. return {'amplitude_times': pulse_times, 'amplitude_values': pulse_values}
  39. if __name__=='__main__':
  40. import pylab as plt
  41. p = create_pulse_gen_dict()
  42. plt.plot(p['amplitude_times'], p['amplitude_values'], '.-')
  43. plt.title("simple regular pulses")
  44. plt.figure()
  45. p = create_burst_gen_dict(duration=2., n_spikes=5, spike_frequency=100., period=100., amplitude=1000., n=5, start=50.)
  46. plt.plot(p['amplitude_times'], p['amplitude_values'], '.-')
  47. plt.title("bursts")
  48. plt.figure()
  49. p = create_burst_gen_dict(duration=2., n_spikes=5, spike_frequency=100., period=100., amplitude=1000., n=2, start=50.,
  50. start_spike_amplitude=2000.)
  51. plt.plot(p['amplitude_times'], p['amplitude_values'], '.-')
  52. plt.title("bursts, with singular initial spike")
  53. plt.show()