File Exchange

image thumbnail

spikegauss

version 2.0.0.0 (3.6 KB) by R P
Generate spike vector time series (SPKVEC) from the TIMESTAMPS of the spikes.

1 Download

Updated 30 Mar 2016

View License

Generate SPKVEC time series from TIMESTAMPS.

Syntax:
[spkvec,timevec,updatedpeak]=spikegauss(timestamps,srate,min_timevec,max_timevec,sigma,peak)

Each spike is represented by a gaussian centered on each of the TIMESTAMPS
SRATE is the sampling rate of the generated time series
MIN_TIMEVEC and MAX_TIMEVEC are the limits the generated time series
SIGMA is the standard deviation
PEAK is the value of the peak of the gaussian (use peak=0 for gaussian
integral = 1; thus sum(spkvec) is equal to the number of spikes)


Example:

timestamps=[-1.22 0.33 0.34 0.35 0.40 3.70 7.30]; % sec
srate=1000; % Hz
min_timevec=-4; % sec
max_timevec=8; % sec
sigma=0.1; % sec
peak=0;

[spkvec,timevec,updatedpeak]=spikegauss(timestamps,srate,min_timevec,max_timevec,sigma,peak);

plot(timevec,spkvec,'k')
hold on
plot([min_timevec max_timevec],[1 1]*updatedpeak,'-r')
plot(timestamps,rand(size(timestamps))/10*updatedpeak+updatedpeak,'ob')
hold off

Cite As

R P (2019). spikegauss (https://www.mathworks.com/matlabcentral/fileexchange/41248-spikegauss), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

R P

K, if I believe you want to plot the variable SPKISOLATED of the following function:

function [spkvec,timevec,spkisolated]=spikegauss(timestamps,srate,min_timevec,max_timevec,alpha)

spkpos=round( (timestamps-min_timevec) * srate); %sec
timevec=0:1/srate:max_timevec-min_timevec;
spkvec=zeros(size(timevec));
spkisolated=zeros(length(spkpos),length(timevec));

for i=1:length(spkpos)
temp=gausswin(srate-1,alpha)';
start_end=[spkpos(i)-(round(srate/2)-1) spkpos(i)+(round(srate/2)-1) 1 srate-1];
if spkpos(i)<=(round(srate/2)-1); start_end(1)=1; start_end(3)=(round(srate/2)+1)-spkpos(i); end
if spkpos(i)+(round(srate/2)-1)>=length(spkvec); start_end(2)=length(spkvec); start_end(4)=1+start_end(2)-start_end(1); end
spkvec(start_end(1):start_end(2))=spkvec(start_end(1):start_end(2))+temp(start_end(3):start_end(4));
spkisolated(i,start_end(1):start_end(2))=temp(start_end(3):start_end(4));
end

timevec=timevec+min_timevec+1/srate;

K

Hey, your function works great for what I am trying to do so far. The only problem I am having is that I am trying to modify it to not only plot the collective Gaussian together, but to also plot the individual Gaussians separately under the curve. (My peaks are put closely together with varying heights and wider Gaussians). Do you have any advice for a modification like this?

Updates

2.0.0.0

New version, using conv function, with inputs (sigma and peak).

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux