Improved page breaks

This commit is contained in:
2015-11-26 23:40:12 +01:00
parent 5b2aaad235
commit a125bca9ac
21 changed files with 131 additions and 110 deletions

View File

@@ -1,19 +1,24 @@
function [time, rate] = binned_rate(spike_times, bin_width, dt, t_max)
% Calculates the firing rate with the binning method. The hist funciton is
% used to count the number of spikes in each bin.
% Arguments:
% spike_times, vector containing the times of the spikes.
% bin_width, the width of the bins in seconds.
% dt, the temporal resolution.
% t_max, the tiral duration.
function [time, rate] = binned_rate(spikes, bin_width, dt, t_max)
% PSTH computed with binning method.
% The hist funciton is used to count the number of spikes in each bin.
%
% Returns two vectors containing the time and the rate.
% [time, rate] = binned_rate(spikes, bin_width, dt, t_max)
%
% Arguments:
% spikes : vector containing the times of the spikes.
% bin_width: the width of the bins in seconds.
% dt : the temporal resolution.
% t_max : the tiral duration.
%
% Returns:
% two vectors containing the time and the rate.
time = 0:dt:t_max-dt;
bins = 0:bin_width:t_max;
rate = zeros(size(time));
h = hist(spike_times, bins) ./ bin_width;
for i = 2:length(bins)
rate(round(bins(i - 1) / dt) + 1:round(bins(i) / dt)) = h(i);
time = 0:dt:t_max-dt;
bins = 0:bin_width:t_max;
rate = zeros(size(time));
h = hist(spikes, bins) ./ bin_width;
for i = 2:length(bins)
rate(round(bins(i - 1) / dt) + 1:round(bins(i) / dt)) = h(i);
end
end

View File

@@ -1,16 +1,20 @@
function [time, rate] = convolution_rate(spike_times, sigma, dt, t_max)
% Calculates the firing rate with the convolution method.
% Arguments:
% spike_times, a vector containing the spike times.
% sigma, the standard deviation of the Gaussian kernel in seconds.
% dt, the temporal resolution in seconds.
% t_max, the trial duration in seconds.
function [time, rate] = convolution_rate(spikes, sigma, dt, t_max)
% PSTH computed with convolution method.
%
% Returns two vectors containing the time and the rate.
% [time, rate] = convolution_rate(spikes, sigma, dt, t_max)
%
% Arguments:
% spikes: a vector containing the spike times.
% sigma : the standard deviation of the Gaussian kernel in seconds.
% dt : the temporal resolution in seconds.
% t_max : the trial duration in seconds.
%
% Returns:
two vectors containing the time and the rate.
time = 0:dt:t_max - dt;
rate = zeros(size(time));
spike_indices = round(spike_times / dt);
spike_indices = round(spikes / dt);
rate(spike_indices) = 1;
kernel = gauss_kernel(sigma, dt);

View File

@@ -1,22 +1,24 @@
function [time, rate] = instantaneous_rate(spike_times, dt, t_max)
% Function calculates the firing rate as the inverse of the interspike
% interval.
% Arguments:
% spike_times, vector containing the times of the spikes.
% dt, the temporal resolutions of the recording.
% t_max, the duration of the trial.
function [time, rate] = instantaneous_rate(spikes, dt, t_max)
% Firing rate as the inverse of the interspike interval.
%
% Returns the vector representing time and a vector containing the rate.
% [time, rate] = instantaneous_rate(spikes, dt, t_max)
%
% Arguments:
% spikes: vector containing the times of the spikes.
% dt : the temporal resolutions of the recording.
% t_max : the duration of the trial.
%
% Returns:
% the vector representing time and a vector containing the rate.
time = 0:dt:t_max-dt;
rate = zeros(size(time));
time = 0:dt:t_max-dt;
rate = zeros(size(time));
isis = diff([0 spike_times]);
inst_rate = 1 ./ isis;
spike_indices = [1 round(spike_times ./ dt)];
isis = diff([0 spikes]);
inst_rate = 1 ./ isis;
spike_indices = [1 round(spikes ./ dt)];
for i = 2:length(spike_indices)
rate(spike_indices(i - 1):spike_indices(i)) = inst_rate(i - 1);
for i = 2:length(spike_indices)
rate(spike_indices(i - 1):spike_indices(i)) = inst_rate(i - 1);
end
end

View File

@@ -1,7 +1,7 @@
function [pdf, centers] = isi_hist(isis, binwidth)
function [pdf, centers] = isiHist(isis, binwidth)
% Compute normalized histogram of interspike intervals.
%
% [pdf, centers] = isi_hist(isis, binwidth)
% [pdf, centers] = isiHist(isis, binwidth)
%
% Arguments:
% isis: vector of interspike intervals in seconds

View File

@@ -2,7 +2,12 @@ function isivec = isis( spikes )
% returns a single list of isis computed from all trials in spikes
%
% isivec = isis( spikes )
%
% Arguments:
% spikes: a cell array of vectors of spike times in seconds
% isivec: a column vector with all the interspike intervalls
%
% Returns:
% isivec: a column vector with all the interspike intervalls
isivec = [];
@@ -13,4 +18,3 @@ function isivec = isis( spikes )
isivec = [ isivec; difftimes(:) ];
end
end

View File

@@ -1,7 +1,7 @@
function plot_isi_hist(isis, binwidth)
function plotISIHist(isis, binwidth)
% Plot and annotate histogram of interspike intervals.
%
% isihist(isis, binwidth)
% plotISIHist(isis, binwidth)
%
% Arguments:
% isis: vector of interspike intervals in seconds
@@ -9,9 +9,9 @@ function plot_isi_hist(isis, binwidth)
% compute normalized histogram:
if nargin < 2
[pdf, centers] = isi_hist(isis);
[pdf, centers] = isiHist(isis);
else
[pdf, centers] = isi_hist(isis, binwidth);
[pdf, centers] = isiHist(isis, binwidth);
end
% plot:

View File

@@ -1,19 +1,19 @@
function s_est = reconstructStimulus(spike_times, sta, stim_duration, dt)
% Function estimates the stimulus from the Spike-Triggered-Average
% (sta).
function s_est = reconstructStimulus(spikes, sta, duration, deltat)
% Estimate the stimulus from the spike-triggered-average (STA).
%
% s_est = reconstructStimulus(spikes, sta, duration, deltat)
%
% Arguments:
% spike_times, a vector containing the spike times in seconds.
% sta, a vector containing the spike-triggered-average.
% stim_duration, the total duration of the stimulus.
% dt, the sampling interval given in seconds.
% spikes : a vector containing the spike times in seconds.
% sta : a vector containing the spike-triggered-average.
% duration: the total duration of the stimulus.
% deltat : the time step of the stimulus in seconds.
%
% Returns:
% the estimated stimulus.
s_est = zeros(round(stim_duration / dt), 1);
binary_spikes = zeros(size(s_est));
binary_spikes(round(spike_times ./ dt)) = 1;
s_est = conv(binary_spikes, sta, 'same');
% s_est: vector with the estimated stimulus.
s_est = zeros(round(duration / deltat), 1);
binary_spikes = zeros(size(s_est));
binary_spikes(round(spikes ./ deltat)) = 1;
s_est = conv(binary_spikes, sta, 'same');
end

View File

@@ -1,32 +1,31 @@
function [sta, std_sta, valid_spikes] = spikeTriggeredAverage(stimulus, spike_times, count, sampling_rate)
% Function estimates the Spike-Triggered-Average (sta).
function [sta, std_sta, n_spikes] = spikeTriggeredAverage(stimulus, spikes, count, deltat)
% Estimate the spike-triggered-average (STA).
%
% [sta, std_sta, n_spikes] = spikeTriggeredAverage(stimulus, spikes, count, deltat)
%
% Arguments:
% stimulus, a vector containing stimulus intensities
% as a function of time.
% spike_times, a vector containing the spike times
% in seconds.
% count, the number of datapoints that are taken around
% the spike times.
% sampling_rate, the sampling rate of the stimulus.
% stimulus: vector of stimulus intensities as a function of time.
% spikes : vector with spike times in seconds.
% count : number of datapoints that are taken around the spike times.
% deltat : the time step of the stimulus in seconds.
%
% Returns:
% the sta, a vector containing the staandard deviation and
% the number of spikes taken into account.
% sta : vector with the STA.
% std_sta : standard deviation of the STA.
% n_spikes: number of spikes contained in STA.
snippets = zeros(numel(spike_times), 2*count);
valid_spikes = 1;
for i = 1:numel(spike_times)
t = spike_times(i);
index = round(t*sampling_rate);
if index <= count || (index + count) > length(stimulus)
continue
snippets = zeros(numel(spikes), 2*count);
n_spikes = 0;
for i = 1:numel(spikes)
t = spikes(i);
index = round(t/deltat);
if index <= count || (index + count) > length(stimulus)
continue
end
snippets(n_spikes,:) = stimulus(index-count:index+count-1);
n_spikes = n_spikes + 1;
end
snippets(valid_spikes,:) = stimulus(index-count:index+count-1);
valid_spikes = valid_spikes + 1;
snippets(n_spikes+1:end,:) = [];
sta = mean(snippets, 1);
std_sta = std(snippets,[],1);
end
snippets(valid_spikes:end,:) = [];
sta = mean(snippets, 1);
std_sta = std(snippets,[],1);

View File

@@ -86,7 +86,7 @@ heisen die Intervalle auch \determ{Interspikeintervalle}
\"ublichen Gr\"o{\ss}en beschrieben werden.
\begin{figure}[t]
\includegraphics[width=1\textwidth]{isihexamples}\hfill
\includegraphics[width=0.96\textwidth]{isihexamples}\vspace{-2ex}
\titlecaption{\label{isihexamplesfig}Interspikeintervall Histogramme}{der in
\figref{rasterexamplesfig} gezeigten Spikes.}
\end{figure}
@@ -113,15 +113,15 @@ heisen die Intervalle auch \determ{Interspikeintervalle}
\frac{\sigma_{ISI}^2}{2\mu_{ISI}^3}$.
\end{itemize}
\begin{exercise}{isi_hist.m}{}
Schreibe eine Funktion \code{isi\_hist()}, die einen Vektor mit Interspikeintervallen
\begin{exercise}{isiHist.m}{}
Schreibe eine Funktion \code{isiHist()}, die einen Vektor mit Interspikeintervallen
entgegennimmt und daraus ein normiertes Histogramm der Interspikeintervalle
berechnet.
\end{exercise}
\begin{exercise}{plot_isi_hist.m}{}
\begin{exercise}{plotISIHist.m}{}
Schreibe eine Funktion, die die Histogrammdaten der Funktion
\code{isi\_hist()} entgegennimmt, um das Histogramm zu plotten. Im
\code{isiHist()} entgegennimmt, um das Histogramm zu plotten. Im
Plot sollen die Interspikeintervalle in Millisekunden aufgetragen
werden. Das Histogramm soll zus\"atzlich mit Mittelwert,
Standardabweichung und Variationskoeffizient der
@@ -155,6 +155,7 @@ Intervalls mit sich selber).
\begin{exercise}{isiserialcorr.m}{}
Schreibe eine Funktion \code{isiserialcorr()}, die einen Vektor mit Interspikeintervallen
entgegennimmt und daraus die seriellen Korrelationen berechnet und plottet.
\pagebreak[4]
\end{exercise}
@@ -395,6 +396,7 @@ vorkommen k\"onnen nicht aufgl\"ost werden. Mit der Wahl der Binweite
wird somit eine Annahme \"uber die relevante Zeitskala des Spiketrains
gemacht.
\pagebreak[4]
\begin{exercise}{binnedRate.m}{}
Implementiere die Absch\"atzung der Feuerrate mit der ``binning''
Methode. Plotte das PSTH.
@@ -435,6 +437,7 @@ Binweite, die zeitliche Aufl\"osung von $r(t)$. Die Breite des Kerns
macht also auch wieder eine Annahme \"uber die relevante Zeitskala des
Spiketrains.
\pagebreak[4]
\begin{exercise}{convolutionRate.m}{}
Verwende die Faltungsmethode um die Feuerrate zu bestimmen. Plotte
das Ergebnis.
@@ -490,10 +493,13 @@ die Zellantwort mit dem STA verfaltet.
Implementiere eine Funktion, die den STA ermittelt. Verwende dazu
den Datensatz \file{sta\_data.mat}. Die Funktion sollte folgende
R\"uckgabewerte haben:
\vspace{-1ex}
\begin{itemize}
\setlength{\itemsep}{0ex}
\item den Spike-Triggered-Average.
\item die Standardabweichung der individuellen STAs.
\item die Anzahl Aktionspotentiale, die dem STA zugrunde liegen.
\item die Anzahl Aktionspotentiale, die zur Berechnung des STA verwendet wurden.
\vspace{-2ex}
\end{itemize}
\end{exercise}