Skip to content

Commit 197c4d4

Browse files
committed
add functions for RDK from the visual localizer
1 parent 1cf218f commit 197c4d4

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

initializeDots.m

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
function [dots] = initializeDots(cfg, thisEvent)
2+
3+
direction = thisEvent.direction(1);
4+
5+
dots.lifeTime = cfg.dot.lifeTime;
6+
7+
speedPixPerFrame = thisEvent.speed(1);
8+
9+
% decide which dots are signal dots (1) and those are noise dots (0)
10+
dots.isSignal = rand(cfg.dot.number, 1) < cfg.dot.coherence;
11+
12+
% for static dots
13+
if direction == -1
14+
speedPixPerFrame = 0;
15+
dots.lifeTime = cfg.eventDuration;
16+
dots.isSignal = ones(cfg.dot.number, 1);
17+
end
18+
19+
% Convert from seconds to frames
20+
dots.lifeTime = ceil(dots.lifeTime / cfg.screen.ifi);
21+
22+
% Set an array of dot positions [xposition, yposition]
23+
% These can never be bigger than 1 or lower than 0
24+
% [0,0] is the top / left of the square
25+
% [1,1] is the bottom / right of the square
26+
dots.positions = rand(cfg.dot.number, 2) * cfg.screen.winWidth;
27+
28+
% Set a N x 2 matrix that speed in X and Y
29+
dots.speeds = nan(cfg.dot.number, 2);
30+
31+
% Coherent dots
32+
[horVector, vertVector] = decompMotion(direction);
33+
dots.speeds(dots.isSignal,:) = ...
34+
repmat([horVector, vertVector], sum(dots.isSignal), 1);
35+
36+
% If not 100% coherence, we get new random direction for the other dots
37+
direction = rand(sum(~dots.isSignal), 1) * 360;
38+
[horVector, vertVector] = decompMotion(direction);
39+
dots.speeds(~dots.isSignal, :) = [horVector, vertVector];
40+
41+
% So far we were working wiht unit vectors convert that speed in pixels per
42+
% frame
43+
dots.speeds = dots.speeds * speedPixPerFrame;
44+
45+
% Create a vector to update to dotlife time of each dot
46+
% Not all set to one so the dots will die at different times
47+
dots.time = floor(rand(cfg.dot.number, 1) * cfg.eventDuration / cfg.screen.ifi);
48+
49+
end
50+

updateDots.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function [dots] = updateDots(dots, cfg)
2+
3+
% Move the selected dots
4+
dots.positions = dots.positions + dots.speeds;
5+
6+
% Create a logical vector to detect any dot that has:
7+
% - an xy position inferior to 0
8+
% - an x position superior to winWidth
9+
% - an x position superior to winHeight
10+
% - has exceeded its liftime
11+
N = any([...
12+
dots.positions > cfg.screen.winWidth, ...
13+
dots.positions < 0, ...
14+
dots.time > dots.lifeTime, ...
15+
rand(cfg.dot.number,1) < cfg.dot.proportionKilledPerFrame ], 2) ;
16+
17+
% If there is any such dot we relocate it to a new random position
18+
% and change its lifetime to 1
19+
if any(N)
20+
dots.positions(N, :) = rand(sum(N), 2) * cfg.screen.winWidth;
21+
dots.time(N, 1) = 1;
22+
end
23+
24+
% Add one frame to the dot lifetime to each dot
25+
dots.time = dots.time + 1;
26+
end

0 commit comments

Comments
 (0)