Here is the code to generate a homogeneous Poisson spike train and calculate the coefficient of variation and the Fano factor for different time step sizes:
% Parameters
duration = 100; % seconds
rate = 100; % Hz
timeWindows = 0.05; % seconds
deltaTs = [0.005, 0.001, 0.0005, 0.0001];
numTrials = 100; % number of spike trains to generate and analyze
% Preallocate arrays for results
cv = zeros(1, length(deltaTs));
fanoFactor = zeros(1, length(deltaTs));
% Generate and analyze spike trains for each time step size
for i = 1:length(deltaTs)
deltaT = deltaTs(i);
numSteps = duration / deltaT;
isiData = cell(1, numTrials); % interspike intervals
spikeCountData = zeros(1, numTrials); % spike counts
for j = 1:numTrials
% Generate spike train
spikeTrain = rand(1, numSteps) < rate * deltaT;
% Find spike times
spikeTimes = find(spikeTrain) * deltaT;
% Calculate interspike intervals
isi = diff(spikeTimes);
% Record interspike intervals
isiData{j} = isi;
% Calculate spike count in each time window
numWindows = ceil(duration / timeWindows);
spikeCounts = histcounts(spikeTimes, 'binwidth', timeWindows, 'bins', numWindows);
% Record spike counts
spikeCountData(j) = mean(spikeCounts);
end
% Calculate coefficient of variation of interspike intervals
cv(i) = std(cellfun(@mean, isiData)) / mean(cellfun(@mean, isiData));
% Calculate Fano factor for spike counts
fanoFactor(i) = var(spikeCountData) / mean(spikeCountData);
end
% Display results
disp('Time Step Size Coefficient of Variation Fano Factor');
disp('------------------------------------------------------------');
for i = 1:length(deltaTs)
fprintf('%.4f %.4f %.4f\n', deltaTs(i), cv(i), fanoFactor(i));
end
Running this code will generate and analyze spike trains for each time step size specified. The code will display the coefficient of variation and the Fano factor for each time step size.
The code generates a homogeneous Poisson spike train by using the expression spikeTrain = rand(1, numSteps) < rate * deltaT, where rand(1, numSteps) generates a random vector of size numSteps with uniform distribution between 0 and 1, and < rate * deltaT compares each element of the random vector with rate * deltaT to determine if a spike occurred at that time step.
The interspike intervals are calculated using the expression isi = diff(spikeTimes), which computes the differences between consecutive spike times. The coefficient of variation is then calculated by dividing the standard deviation of the interspike intervals by their mean.
The spike count in each time window is calculated using spikeCounts = histcounts(spikeTimes, 'binwidth', timeWindows, 'bins', numWindows), which counts the number of spikes in each time window based on the spike times. The Fano factor is then calculated by dividing the variance of the spike counts by their mean.
The results will be displayed in a table format, showing the time step size, coefficient of variation, and Fano factor for each time step size.
The time step size that gives the most accurate estimation of the coefficient of variation and the Fano factor can be determined by comparing the values obtained for each time step size. A smaller time step size will generally provide a more accurate estimation, but at the cost of increased computation time.