Making a vector where each element represents an interspike interval in milliseconds, and another vector with zeros and ones where the index of the vector is the time

2 次查看(过去 30 天)
Hello! My instructor has asked us to write 2 functions
  1. ISI = spike2isi(SPIKE)
  2. SPIKE = isi2spike(ISI)
where ISI is a vector where each element represents an interspike interval in milliseconds, and SPIKE is a vector with zeros and ones where the index of the vector is the time in milliseconds.
Test your functions such that ISI1 is the same as ISI2 with ISI2=spike2isi(isi2spike(ISI1)) and in an analogous fashion for SPIKE.
I have tried to following code for SPIKE using class notes and documentation I can find but I'm not sure what to do. If anyone has insight please let me know!
function SPIKE = isi2SPIKE(ISI)
defMU = 25; %firing rate in 1 sec or Hz
defN = 1000;
switch(nargin)
case 0, mu = defMU; n = defN;
case 1, mu=defMU;
case 2 %all input there
end
ISI = -log(rand(1,n))/mu; %generate ISIs according to a Poisson distribution
ISI = ISI*1000; %convert ISI into miliseconds
l=sum(ISI);
c=cumsum(ISI); %%spike times
for SPIKE = zeros(1:l)
if rand<lambda
SPIKE(c) = 1;
SPIKE = l + length(ISI);
end
end
if ~nargout
figure(10); histogram(SPIKE, 'Normalization','probability')
clear SPIKE
end
end

回答(1 个)

Rishav
Rishav 2023-9-11
Hi DANIELLE,
I understand that you are trying to convert 'ISI' to 'SPIKE' and back using the functions 'isi2spike' and 'spike2isi' and test the same.
The function 'SPIKE' can be defined as follows:
function SPIKE = isi2spike(ISI)
% firing rate of 1 sec or Hz
defMU = 25;
% Convert ISI into spike times
spike_times = cumsum(ISI);
% Create a vector of zeros with the length of the total time
total_time = round(sum(ISI) * 1000); % Total time in milliseconds
SPIKE = zeros(1, total_time);
% Place spikes at spike times
SPIKE(round(spike_times * 1000)) = 1; % Convert spike_times to milliseconds
end
The function 'ISI' can be defined as follows :
function ISI = spike2isi(SPIKE)
% Find spike times
spike_times = find(SPIKE == 1);
% Calculate ISI by taking the differences between spike times
ISI = diff(spike_times); % ISI in milliseconds
end
You can test these functions as follows:
% Test ISI to SPIKE and back to ISI
ISI1 = rand(1, 100); % Sample ISI data
SPIKE = isi2spike(ISI1);
ISI2 = spike2isi(SPIKE);
% Test SPIKE to ISI and back to SPIKE
SPIKE1 = randi([0, 1], 1, 100); % Sample SPIKE data
ISI = spike2isi(SPIKE1);
SPIKE2 = isi2spike(ISI);
% Check if ISI1 and ISI2 are the same, and if SPIKE1 and SPIKE2 are the same
isequal(ISI1, ISI2)
isequal(SPIKE1, SPIKE2)
This code tests whether the conversion functions work correctly by comparing the original data ('ISI1' and 'SPIKE1') with data obtained after conversion ('ISI2' and 'SPIKE2') by using the 'isequal' function.
Thank you,
Rishav Saha

类别

Help CenterFile Exchange 中查找有关 Oceanography and Hydrology 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by