-
Notifications
You must be signed in to change notification settings - Fork 0
/
slideWinSub.m
41 lines (37 loc) · 1.33 KB
/
slideWinSub.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
% Sliding window dF/F calculation
% Inputs: F - raw fluorecense
% winsize - baseline window size
% percent - lower percent of baseline values to average
% Output: dFF - relative change in fluorescense in percent
function dFF = slideWinSub(F,winsize,percent)
nRois = size(F,1);
nFrames = size(F,2);
dFF = zeros(size(F));
%M = zeros(1, nrois);
%SD = zeros(1, nrois);
for j = 1 : nRois
for k = 1 : nFrames
lWin = 1;
rWin = min(k+winsize, nFrames);
if k > winsize
lWin = max(1,k-2*winsize);
rWin = k;
end
percentWin = floor(percent/100*(rWin-lWin));
tWin = sort(F(j,(lWin:rWin)),'ascend');
F0 = mean(tWin(1:percentWin));
dFF(j,k) = 100 * (F(j,k)- F0) / F0;
end
% for k = 1 : nFrames
% lWin = max(1,k-winsize);
% rWin = min(k+winsize, nFrames);
% percentWin = floor(percent/100*(rWin-lWin));
% tWin = sort(F(j,(lWin:rWin)),'ascend');
% F0 = mean(tWin(1:percentWin));
% dFF(j,k) = 100 * (F(j,k)- F0) / F0;
% end
%twin = sort(nDFF(j,:));
%pcentwin = floor(percent/100*(nframes));
%M(j) = mean(twin(1:pcentwin));
%SD(j) = std(twin(1:pcentwin));
end