diff --git a/projects/project_vector_strength/solution/main.m b/projects/project_vector_strength/solution/main.m new file mode 100644 index 0000000..379e349 --- /dev/null +++ b/projects/project_vector_strength/solution/main.m @@ -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 diff --git a/projects/project_vector_strength/solution/spikeEodPhase.m b/projects/project_vector_strength/solution/spikeEodPhase.m new file mode 100644 index 0000000..f55d250 --- /dev/null +++ b/projects/project_vector_strength/solution/spikeEodPhase.m @@ -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 + + diff --git a/projects/project_vector_strength/solution/vectorStrength.m b/projects/project_vector_strength/solution/vectorStrength.m new file mode 100644 index 0000000..fc9bc43 --- /dev/null +++ b/projects/project_vector_strength/solution/vectorStrength.m @@ -0,0 +1,3 @@ +function vs = vectorStrength(phases) + +vs = sqrt((mean(cos(phases)).^2) + (mean(sin(phases)).^2)); \ No newline at end of file diff --git a/projects/project_vector_strength/solution/zeroCrossings.m b/projects/project_vector_strength/solution/zeroCrossings.m new file mode 100644 index 0000000..2d614a2 --- /dev/null +++ b/projects/project_vector_strength/solution/zeroCrossings.m @@ -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)); \ No newline at end of file