-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownsample.m
More file actions
28 lines (22 loc) · 730 Bytes
/
downsample.m
File metadata and controls
28 lines (22 loc) · 730 Bytes
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
% downsample.m
% This function downsamples the data to reduce computation time
% rate is desired sampling rate in Hz. It must produce an integer timestep
% in milliseconds
function [xDS,yDS,spikesDS] = downsample(x,y,spikes,rate)
step = 1/rate*1000;
if rem(step,1)
error('Invalid sampling rate. Please choose a sampling rate that produces an integer timestep in ms.');
end
xDS = x(1:step:end);
yDS = y(1:step:end);
spikesDS = NaN(length(xDS),size(spikes,2));
for n = 1:size(spikes,2)
for i = 1:ceil(length(x)/step)
if i < ceil(length(x)/step)
spikesDS(i,n) = sum(spikes(1+(i-1)*step:i*step,n));
else
spikesDS(i,n) = sum(spikes(1+(i-1)*step:end,n));
end
end
end
end