5

So my question follows the development after my last one. I have been trying to work on getting the spike times as a rastor plot for a spike train. I took a firing rate of 100 and got spike train for 20 trials: The code for that is:

fr = 100
dt = 1/1000 #dt in milisecond
duration = 2 #no of duration in s
nBins = 2000 #SpikeTrain
nTrials = 20 #NumberOfSimulations
MyPoissonSpikeTrain = function(p, fr= 100) {
  p = runif(nBins)
  q = ifelse(p < fr*dt, 1, 0)
  return(q)
}

set.seed(1)
SpikeMat <- t(replicate(nTrials, MyPoissonSpikeTrain()))

plot(x=-1,y=-1, xlab="time (s)", ylab="Trial",
main="Spike trains",
ylim=c(0.5, nTrials+1), xlim=c(0, duration))
for (i in 1: nTrials)
{
  clip(x1 = 0, x2= duration, y1= (i-0.2), y2= (i+0.4))
  abline(h=i, lwd= 1/4)
  abline(v= dt*which( SpikeMat[i,]== 1))
}

This gives the result: Spike Trains

After all this was done, my next task was to get a vector of Inter-Spike intervals and get a histogram of them. Because the distribution of ISIs follows the exponential distribution, if I plot the exponential distribution of ISIs with the same data, it will match the curve made by the height of the histograms. So to get the interspike timings first, I used:

spike_times <- c(dt*which( SpikeMat[i, ]==1))

Then to get a vector for interspike intervals and their histogram, I used the following command line,

ISI <- diff(spike_times)
hist(ISI, density= 10, col= 'blue', xlab='ISI(ms)', ylab='number of occurences')

and it gave me this plot:

HistogramsofISIs

Now, What I want is to plot the exponential distributions within the histograms that justifies the exponential distribution nature of the inter spike intervals. I am confused about what parameters to use and which rate to use. If somebody has worked with Interspike interval plotting, please help. And I am sorry if my data seems incomplete, please let me know if I am missing something.

Neuron
  • 3,776
  • 3
  • 24
  • 44
TimeLord
  • 171
  • 13

1 Answers1

3

My fellow researcher just told me a simple line of codes:

x <- seq(0, 0.05, length=1000)
y <- dexp(x, rate=100)
lines(x,y)

which gave me, this: HistogramWithExpoDis

If somebody has any way of making this process more efficient, please help me.

Neuron
  • 3,776
  • 3
  • 24
  • 44
TimeLord
  • 171
  • 13