-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctrlmyl124.m
79 lines (65 loc) · 1.81 KB
/
ctrlmyl124.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
data = textread('ctrl myl 1.2.4.txt');
trace = mat2cell(data, [2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000], [2]);
new = [];
menf = [];
nw = [];
medf = [];
for j = 1:2000
for i=1:50
y = trace{i,1} (j,:);
new = [new;y];
end
men = mean(new);
menf = [menf;men];
end
for k = 1:2000
for i=1:50
w = trace{i,1} (k,:);
nw = [nw;w];
end
med = median(nw);
medf = [medf;med];
end
TanX = trace{1,1} (:,1);
TanY = menf(:,2);
figure(1)
plot(data(:,1), data(:,2))
figure(2)
plot(trace{1,1} (:,1), menf(:,2))
%figure(3)
%plot(trace{1,1} (:,1), medf(:,2))
% Now smooth with a Savitzky-Golay sliding polynomial filter
%figure(4);
%windowWidth = 27;
%polynomialOrder = 3;
%smoothY = sgolayfilt(menf(:,2), polynomialOrder, windowWidth);
%plot(menf(:,1), smoothY, 'b-', 'LineWidth', 2);
%grid on;
TanX = trace{1,1} (:,1);
TanY = menf(:,2);
figure(4);
subplot(1, 2, 1);
plot(TanX, TanY, 'b-');
grid on;
baseLineIndexes = TanX > 0 & TanY >-0.1 & TanY<-0.05;
% Fit those to a line
xBaseLine = TanX(baseLineIndexes);
yBaseLine = TanY(baseLineIndexes);
% Overlay them in red.
hold on;
plot(xBaseLine, yBaseLine, 'r.', 'LineWidth', 2);
legend('Signal', 'Base Line');
% Fit a line to the baseline elements.
coefficients = polyfit(xBaseLine, yBaseLine, 1);
% Extrapolate everywhere
xFit = linspace(min(TanX), max(TanX), length(TanX));
yFit = polyval(coefficients, xFit);
% Subtract the baseline from TanY
correctedTanY = TanY - yFit';
% Clamp to 0
%correctedTanY = max(correctedTanY, 0);
% Plot baseline corrected
subplot(1, 2, 2);
plot(TanX, correctedTanY, 'b-');
grid on;
legend('Corrected Signal');