[project] partial solution for vector strength project
This commit is contained in:
parent
4f3dd321f4
commit
2c21dfe989
15
projects/project_vector_strength/solution/main.m
Normal file
15
projects/project_vector_strength/solution/main.m
Normal 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
|
10
projects/project_vector_strength/solution/spikeEodPhase.m
Normal file
10
projects/project_vector_strength/solution/spikeEodPhase.m
Normal 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
|
||||
|
||||
|
@ -0,0 +1,3 @@
|
||||
function vs = vectorStrength(phases)
|
||||
|
||||
vs = sqrt((mean(cos(phases)).^2) + (mean(sin(phases)).^2));
|
@ -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));
|
Reference in New Issue
Block a user