[project] partial solution for vector strength project

This commit is contained in:
Jan Grewe 2017-01-23 17:32:25 +01:00
parent 4f3dd321f4
commit 2c21dfe989
4 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,15 @@
% partial solution for the vector strength project
clear
files = dir('../data/*.mat');
dt = 1./20000;
vs = zeros(length(files), 1);
for i = 1:length(files)
load(strcat('../data/', files(i).name))
eod_time = (1:length(eod)) .* dt;
zero_crossings = zeroCrossings(eod, eod_time);
while spike_times(1) <= zero_crossings(1)
spike_times(1) = [];
end
phases = spikeEodPhase(spike_times, zero_crossings);
vs(i) = vectorStrength(phases);
end

View File

@ -0,0 +1,10 @@
function phi = spikeEodPhase(spike_times, eod_times)
phi = zeros(length(spike_times), 1);
period = mean(diff(eod_times));
for j = 1:length(spike_times)
t = spike_times(j);
phase = (t - eod_times(find(eod_times <= t, 1, 'last'))) / period * 2 * pi;
phi(j) = phase;
end

View File

@ -0,0 +1,3 @@
function vs = vectorStrength(phases)
vs = sqrt((mean(cos(phases)).^2) + (mean(sin(phases)).^2));

View File

@ -0,0 +1,9 @@
function xings = zeroCrossings(data, time, threshold)
if nargin == 2
threshold = 0;
end
shift_data = circshift(data, 1);
xings = time((data >= threshold) & (shift_data < threshold));