%ex35
% import spreadsheet as table, rename to T0

% filter out the equipment artifact at about 0.7 to1.2 Hz,
lpFilt = designfilt('lowpassfir','PassbandFrequency',0.001, ...
         'StopbandFrequency',0.0014,'PassbandRipple',0.5, ...
         'StopbandAttenuation',65,'DesignMethod','kaiserwin');

T1=T0;
for i=2:5
T1.(i)=filtfilt(lpFilt,T1.(i));
end

%LineWidth
set(groot,'defaultLineLineWidth',1)

%
plot(T.Time,T.s02,'DisplayName','rST19');
plot(T.Time,T.s01,'DisplayName','rST19 +6mm');

plot(T.Time,T.s03,'DisplayName','rST21');
plot(T.Time,T.s04,'DisplayName','rST21 +6mm');


T=T1;
figure
plot(T.Time,T.s03,'DisplayName','rST21');
hold on;
yyaxis right;
plot(T.Time,T.s01,'DisplayName','rST19');
hold on;
yyaxis left
xlabel('Time (seconds)')
ylabel('Impedance at 40KHz (kOhms)')
legend('show', 'Location', 'northwest')
grid
title('Right ST-19 and ST-21; lowpass filter at 0.7Hz')

yyaxis right
marker=26.224;
x=[marker,marker];
y=[0,6];
plot(x,y,'--','Color',[0.277 0.473 0.098],'DisplayName','hold breath');

marker=33.774;
x=[marker,marker];
y=[0,6];
plot(x,y,'--','Color',[0.277 0.473 0.098],'DisplayName','finish');

marker=58.095;
x=[marker,marker];
y=[0,6];
plot(x,y,'--','Color','blue','DisplayName','drink');

marker=69.499;
x=[marker,marker];
y=[0,6];
plot(x,y,'--','Color','blue','DisplayName','finish');

% closeup box
axes('position',[.65 .175 .25 .25])
box on % put box around new pair of axes
indexOfInterest = (T.Time > 110) & (T.Time < 135); % range of t near perturbation
plot(T.Time(indexOfInterest),T.s03(indexOfInterest)) % plot on new axes
hold on
axis([110 135 5.138 5.238 ])
%axis tight
yyaxis right
plot(T.Time(indexOfInterest),T.s04(indexOfInterest))
hold on
axis([110 135 4.461 4.521 ])
title('Close-up of ST-21 and ST-21 +6mm')
grid

% ===== peaks

[R19pks,R19locs] = findpeaks(T.s01);
R19locs=R19locs/1000;

[R21Ppks,R21Plocs] = findpeaks(T.s04);
R21Plocs=R21Plocs/1000;
