-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcorrectBackground.m
56 lines (50 loc) · 2.01 KB
/
correctBackground.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
function nplate = correctBackground(plate, chname, bgval);
%--------------------------------------------------------------------------
% nplate = correctBackground(plate, chname, bgval)
%
% correctBackground: remove background from timecourse measurements.
%
% plate = cell array returned by importPlate2 and subsequent processing.
% chname = name of channel to adjust (string).
% bgval = background values to remove, can be a timecourse of single
% value. This will be extended to match the length of the timecourse to be
% corrected. Specify bgval=[] to use minimum in timecourse.
%
% Remove background from a timecourse channel. Affects all versions
% of timepoints, e.g. chname='YFP' will remove background from 'YFP',
% and 'sYFP_t'. The fit object 'sYFP' will not be touched, but
% should be corrected using the 'sYFP_bg' field created here.
% If bg=[], then the minimum value of the channel (smoothed) in each well
% will be used as background.
%
% (c) Tim Rudge, 2014
% (Provided under GPL v3 license, http://www.gnu.org/copyleft/gpl.html)
%--------------------------------------------------------------------------
schname = ['s' chname];
bgname = [chname '_bg'];
stchname = [schname '_t'];
n = length(plate(:));
for i=1:n;
if isempty(bgval);
bg = min(plate(i).(stchname));
else;
bg = bgval;
end;
bg = bg(:);
nbgt = length(bg);
nct = length(plate(i).(chname));
if nct>nbgt;
% Pad bg values with mean of last 10 time points
nextra = nct-nbgt;
bg = [bg; mean(bg(end-9:end))*ones(nextra,1)];
end;
% Subtract bg from time points
plate(i).(chname) = plate(i).(chname) - bg; %max(0, plate(i).(chname) - bg);
%plate(i).(stchname) = max(0, plate(i).(stchname) - bg);
%% bg correction for smoothed data
%plate(i).(bgname) = bg;
% This is a nicer way to correct the smoothed function, but is
% INCREDIBLY slow for some reason.
%plate(i).(scorrchname) = @(t) max(0, feval(plate(i).(schname),t) - bg);
end;
nplate = plate;