-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_position_vector.m
60 lines (44 loc) · 3.46 KB
/
create_position_vector.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function [ position ] = create_position_vector( period, T, G, Pos )
%CREATE_SPIKE_COUNT_AND_ANGLES_VECTOR Summary of this function goes here
% Detailed explanation goes here
global BEHAVIORAL_SAMPLE_RATE NEURONAL_SAMPLE_RATE BEHAVIORAL_SAMPLES_PER_TEMPORAL_BIN SAMPLE_LIMIT;
number_of_neurons = max(G);
% Create edges of entire sws period
cluster_bin_edges = [0.5:1:number_of_neurons + 0.5];
angles = [];
for segment_index = 1:size(period, 1)
current_period_start_behavior_sample_index = ceil(period(segment_index, 1) * BEHAVIORAL_SAMPLE_RATE);
current_period_end_behavior_sample_index = floor(period(segment_index, 2) * BEHAVIORAL_SAMPLE_RATE);
current_period_behavior_sample_edges = (current_period_start_behavior_sample_index - 0.5):BEHAVIORAL_SAMPLES_PER_TEMPORAL_BIN:(current_period_end_behavior_sample_index + 0.5);
current_period_neuronal_sample_edges = current_period_behavior_sample_edges * NEURONAL_SAMPLE_RATE / BEHAVIORAL_SAMPLE_RATE;
current_T = T(T > round(current_period_start_behavior_sample_index / BEHAVIORAL_SAMPLE_RATE * NEURONAL_SAMPLE_RATE) & ...
T < round(current_period_end_behavior_sample_index / BEHAVIORAL_SAMPLE_RATE * NEURONAL_SAMPLE_RATE));
current_G = G(T > round(current_period_start_behavior_sample_index / BEHAVIORAL_SAMPLE_RATE * NEURONAL_SAMPLE_RATE) & ...
T < round(current_period_end_behavior_sample_index / BEHAVIORAL_SAMPLE_RATE * NEURONAL_SAMPLE_RATE));
neuron_firing_per_bin = hist3([current_T current_G], 'Edges', {current_period_neuronal_sample_edges cluster_bin_edges});
current_segment_start_angle_index = current_period_start_behavior_sample_index;
current_segment_end_angle_index = current_segment_start_angle_index + ...
(length(current_period_behavior_sample_edges) - 1) * BEHAVIORAL_SAMPLES_PER_TEMPORAL_BIN - 1;
position_during_segment = Pos(current_segment_start_angle_index:current_segment_end_angle_index, :);
% TODO: Check here which is longer. the number of behavioral samples or
% the neuronal samples per this session. if neuronal, then pad with
% -1 in the angle measurements. if behavioral cut the extra angles
% (we can't assume the neuronal data).
% Bin position
marked_position_during_segment = position_during_segment;
marked_position_during_segment(position_during_segment == -1) = Inf;
position_mat = reshape(sum(reshape(marked_position_during_segment, BEHAVIORAL_SAMPLES_PER_TEMPORAL_BIN, [])), [], ...
size(marked_position_during_segment, 2)) ./ BEHAVIORAL_SAMPLES_PER_TEMPORAL_BIN;
% Bin angles
angles_mat = reshape(angles_during_segment, [BEHAVIORAL_SAMPLES_PER_TEMPORAL_BIN size(neuron_firing_per_bin, 1) - 1])';
angles_valid_mask_mat = (angles_mat ~= -1);
angle_per_temporal_bin = mod(angle(sum(angles_valid_mask_mat .* exp(1i * angles_mat), 2)), 2 * pi);
angle_per_temporal_bin(abs(sum(angles_valid_mask_mat .* exp(1i * angles_mat), 2)) == 0) = nan;
angles = [angles; angle_per_temporal_bin];
end
% Truncate the data to avoid exceeding maximum array size
if size(full_neuron_firing_per_bin, 1) > SAMPLE_LIMIT
full_neuron_firing_per_bin = full_neuron_firing_per_bin(1:SAMPLE_LIMIT, :);
angles = angles(1:SAMPLE_LIMIT);
end
end