% ex57 % 9-11-18 % import imp readings as table, rename to T0 % import temp readings as table, rename to TT0 % filter out freq above 0.7 Hz lpFilt = designfilt('lowpassfir','PassbandFrequency',0.0014, ... 'StopbandFrequency',0.002,'PassbandRipple',0.5, ... 'StopbandAttenuation',65,'DesignMethod','kaiserwin'); T1=T0; % passband = 0.7hz (not clean results on breath pattern) for i=2:13 T1.(i)=filtfilt(lpFilt,T1.(i)); end beep TT=TT0; for i=2:3 TT.(i)=filtfilt(lpFilt,TT.(i)); end beep % lowpass, filter out freq above 0.435 Hz % this leaves resp, duodenal, st slow wave, only takes out pulse lpFilt = designfilt('lowpassfir','PassbandFrequency',0.000870, ... 'StopbandFrequency',0.001,'PassbandRipple',0.5, ... 'StopbandAttenuation',65,'DesignMethod','kaiserwin'); T2=T0; % passband= 0.435 Hz for i=2:13 T2.(i)=filtfilt(lpFilt,T2.(i)); end beep % filter out freq above 0.125 Hz % leaves only stomach slow wave lpFilt = designfilt('lowpassfir','PassbandFrequency',0.000250, ... 'StopbandFrequency',0.000350,'PassbandRipple',0.5, ... 'StopbandAttenuation',65,'DesignMethod','kaiserwin'); %fvtool(lpFilt) T3=T0; % slow wave, passband= 0.125 Hz for i=2:13 fprintf('%d', i);fprintf('\n');pause(.05); T3.(i)=filtfilt(lpFilt,T3.(i)); end beep % st slow wave 8-12 s; 0.0833 - 0.125 hz (12 - 8 s) % resp, 3.0-5.0 s; 0.200 - 0.333 Hz (5 - 3 s) % duodenal, 2.0 - 3.5 s; 0.286 - 0.5 hz (3.5 - 2 s) % breath, thermistor. 1 - 12 s; 0.0833 - 1 hz % bandpass iir bpFilt = designfilt('bandpassiir','FilterOrder',8, ... 'HalfPowerFrequency1',0.0833,'HalfPowerFrequency2',1, ... 'SampleRate',1000); %fvtool(bpFilt) T4=T0; % duodenal waves for i=2:13 fprintf('%d', i);fprintf('\n');pause(.05); T4.(i)=filtfilt(bpFilt,T4.(i)); end % st slow wave 8-12 s; 0.0833 - 0.125 hz (12 - 8 s) % breath, 3.0-5.0 s; 0.200 - 0.333 Hz (5 - 3 s) % duodenal, 2.0 - 3.5 s; 0.286 - 0.5 hz (3.5 - 2 s) % bandpass iir bpFilt = designfilt('bandpassiir','FilterOrder',8, ... 'HalfPowerFrequency1',0.200,'HalfPowerFrequency2',0.333, ... 'SampleRate',1000); %fvtool(bpFilt) T5=T0; % respiration waves for i=2:13 fprintf('%d', i);fprintf('\n');pause(.05); T5.(i)=filtfilt(bpFilt,T5.(i)); end Tb=TT0; % breath pattern for i=2:3 fprintf('%d', i);fprintf('\n');pause(.05); Tb.(i)=filtfilt(bpFilt,Tb.(i)); end %========== temperature figure set(groot,'defaultLineLineWidth',1); set(gca,'FontSize',14, 'Box' , 'on'); set(gca, 'LineStyleOrder', {'-', '--', ':', '-.'}); hold all; T=TT; % plot(T.Time,T.s01,'DisplayName','Breath 01'); plot(TT.Time,TT.s02,'DisplayName','Breath 02'); ylabel('Temperature at nostril (Celcius)') legend('show', 'Location', 'northwest') grid title('Impedance; lowpass filter at 0.7 Hz') xlabel('Time (seconds)') % ====== Fig 1, LU-6 T=T2; figure set(groot,'defaultLineLineWidth',1); set(gca,'FontSize',14, 'Box' , 'on'); set(gca, 'LineStyleOrder', {'-', '--', ':', '-.'}); hold all; plot(T.Time,T.s05,'DisplayName','left Lung-6'); yyaxis right; plot(T.Time,T.s06,'DisplayName','left Lung-6 + 6mm'); yyaxis left; ylabel('Impedance at 40 kHz (K\Omega)') legend('show', 'Location', 'northwest') grid title('Impedance at left Lung-6 (lowpass filter at 0.435 Hz), and breathing pattern') xlabel('Time (seconds)') axes('position',[0.13 0.11 0.775 0.815]); box on plot(Tb.Time,Tb.s02, 'Color', 'black', 'DisplayName','breathing pattern'); hold on axis([0 600 -0.12 0.7 ]) %axis tight legend('show', 'Location', 'north'); % hold breath marker yyaxis right; yMax=0.05; yMin=-0.04; yyaxis right marker=458.862; x=[marker,marker]; y=[yMin,yMax]; plot(x,y,'--','Color',[0.277 0.473 0.098],'DisplayName','hold breath'); marker=476.038; x=[marker,marker]; y=[yMin,yMax]; plot(x,y,'--','Color',[0.277 0.473 0.098],'HandleVisibility','off'); % ==== resp, duo waves at left lu6 figure; subplot(2,1,1); set(groot,'defaultLineLineWidth',1) set(gca,'FontSize',14,'Box','on') hold all; plot(T4.Time,T4.s05,'DisplayName','left LU-6, duo. waves (bp filt 0.286 - 0.5 Hz; 3.5 - 2 s)'); plot(T5.Time,T5.s05,'DisplayName','left LU-6, resp. waves (bp filt 0.200 - 0.333 Hz; 5 - 3 s)'); yyaxis right; plot(Tb.Time,Tb.s02, 'Color', 'black', 'DisplayName','breath at nostril (detrended)'); hold on axis([0 600 -0.12 0.7 ]) ylabel('Temperature at nostril (Celcius)') yyaxis left; ylabel('Impedance at 40 kHz (K\Omega)') legend('show', 'Location', 'northwest') grid title('Impedance at left Lung-6, bandpass filter to show duodenal and respiration waves') xlabel('Time (seconds)') subplot(2,1,2); set(groot,'defaultLineLineWidth',1) set(gca,'FontSize',14,'Box','on') hold all; plot(T4.Time,T4.s05,'DisplayName','left LU-6, duo. waves'); yyaxis right; plot(T5.Time,T5.s05,'DisplayName','left LU-6, resp. waves'); yyaxis left; ylabel('Impedance at 40 kHz (K\Omega)') legend('show', 'Location', 'northwest') grid % title('Impedance at left Lung-6, bandpass filter to show duodenal and respiration waves') xlabel('Time (seconds)') %======== breath and st19, bp filt figure set(groot,'defaultLineLineWidth',1); set(gca,'FontSize',14, 'Box' , 'on'); hold all; plot(T4.Time,T4.s09,'DisplayName','duodenal pace signal at left ST-19'); yyaxis right; plot(Tb.Time,Tb.s02,'DisplayName','breathing pattern'); ylabel('Temperature at nostril (Celcius), detrended') yyaxis left; ylabel('Impedance at 40 kHz (K\Omega), detrended') legend('show', 'Location', 'northwest') grid title('Duodenal pace signal at Stomach-19, and breathing pattern (bandpass filters applied') xlabel('Time (seconds)') % closeup box axes('position',[.65 .175 .25 .25]) box on indexOfInterest = (T4.Time > 67) & (T4.Time < 83); % range of t near perturbation plot(T4.Time(indexOfInterest),T4.s09(indexOfInterest)) % plot on new axes hold on %axis([120 128 1.62 1.635 ]) %axis tight yyaxis right plot(Tb.Time(indexOfInterest),Tb.s02(indexOfInterest)) hold on %axis([120 128 2.875 2.89 ]) title('Close-up of phase shift') grid % ======== St-19, duo pace signal, breathing patter, bp filt figure set(groot,'defaultLineLineWidth',1); set(gca,'FontSize',14, 'Box' , 'on'); hold all; plot(T4.Time,T4.s09,'DisplayName','duodenal pace signal at left ST-19'); yyaxis right; plot(T4.Time,T4.s10,'DisplayName','duodenal pace signal at left ST-19 +6 mm'); yyaxis left; ylabel('Impedance at 40 kHz (K\Omega), detrended') legend('show', 'Location', 'northwest') grid title('Duodenal pace signal at ST-19, at +6mm, and breathing pattern (bandpass filters applied') xlabel('Time (seconds)') axes('position',[0.13 0.11 0.775 0.815]); box on plot(Tb.Time,Tb.s02, 'Color', 'black', 'DisplayName','breathing pattern'); hold on axis([15 600 -0.12 0.7 ]) %axis tight legend('show', 'Location', 'north'); % sigh marker yyaxis right; yMax=0.05; yMin=-0.04; marker=136; x=[marker,marker]; y=[yMin,yMax]; plot(x,y,'--','Color',[0.25 0.25 0.25],'DisplayName','first sigh'); %===== ST19 T=T2; figure set(groot,'defaultLineLineWidth',1); set(gca,'FontSize',14, 'Box' , 'on'); set(gca, 'LineStyleOrder', {'-', '--', ':', '-.'}); hold all; plot(T.Time,T.s10,'DisplayName','left ST-19'); yyaxis right; plot(T.Time,T.s09,'DisplayName','left ST-19 + 6mm'); yyaxis left; ylabel('Impedance at 40 kHz (K\Omega)') legend('show', 'Location', 'northwest') grid title('Impedance at LU-19; lowpass filter at 0.435 Hz') xlabel('Time (seconds)') %==== markers yyaxis right; yMax=0.05; yMin=-0.04; yyaxis right marker=458.862; x=[marker,marker]; y=[yMin,yMax]; plot(x,y,'--','Color',[0.277 0.473 0.098],'DisplayName','hold breath'); marker=476.038; x=[marker,marker]; y=[yMin,yMax]; plot(x,y,'--','Color',[0.277 0.473 0.098],'DisplayName','end'); % ========== sigh marker yyaxis right; yMax=0.05; yMin=-0.04; yyaxis right marker=137; x=[marker,marker]; y=[yMin,yMax]; plot(x,y,'--','Color',[0.25 0.25 0.25],'DisplayName','sigh'); %===== breath (detrend) axes('position',[0.13 0.11 0.775 0.815]); box on % put box around new pair of axes opol = 22; T=TT; dt=T; [p,s,mu] = polyfit(T.Time,T.(3),opol); f_y = polyval(p,T.Time,[],mu); dt.(3) = T.(3) - f_y; plot(T.Time,dt.(3),'Color', 'black', 'DisplayName','Breath (detrended)'); % ylabel('Temperature at nostril (Celcius)') %axis([0 300 17.9 44.9 ]) %axis tight legend('show', 'Location', 'north'); % ====== markers yyaxis right m1=458.862; m2=476.038; yMax=1.5; yMin=-.5; x=[m1,m1]; plot(x,y,'--','Color',[0.277 0.473 0.098],'DisplayName','hold breath'); hold on; x=[m2,m2]; plot(x,y,'--','Color',[0.277 0.473 0.098],'HandleVisibility','off'); yyaxis left; ylabel('Impedance at 40 kHz (K\Omega)') legend('show', 'Location', 'northwest') grid title('Impedance at LU-19; lowpass filter at 0.435 Hz') xlabel('Time (seconds)') % =========== st-19 filtered, resp and duo figure set(groot,'defaultLineLineWidth',1); set(gca,'FontSize',14, 'Box' , 'on'); set(gca, 'LineStyleOrder', {'-', '--', ':', '-.'}); hold all; T=T4; plot(T.Time,T.s09,'DisplayName','left ST-19 bandpass filter 0.286 - 0.5 hz (waves between 3.5 - 2 s '); yyaxis right; T=T5; plot(T.Time,T.s09,'DisplayName','left ST-19 bandpass filter 0.2 - 0.333 Hz (waves between 5 - 3 s)'); yyaxis left; ylabel('Impedance at 40 kHz (K\Omega)') legend('show', 'Location', 'northwest') grid title('Impedance at ST-19 (s09); bandpass filters for duodenal and respiration waves') xlabel('Time (seconds)') % ======== impedance T=T4; figure set(groot,'defaultLineLineWidth',1); set(gca,'FontSize',14, 'Box' , 'on'); set(gca, 'LineStyleOrder', {'-', '--', ':', '-.'}); hold all; plot(T.Time,T.s01,'DisplayName','left Kid-3'); yyaxis right; plot(T.Time,T.s02,'DisplayName','left Kid-3 + 6mm'); yyaxis left; plot(T.Time,T.s03,'DisplayName','right Kid-3'); yyaxis right; plot(T.Time,T.s04,'DisplayName','right Kid-3 + 6mm'); yyaxis left; plot(T.Time,T.s05,'DisplayName','left LU-6'); yyaxis right; plot(T.Time,T.s06,'DisplayName','left LU-6 + 6mm'); yyaxis left; plot(T.Time,T.s07,'DisplayName','left LU-9'); yyaxis right; plot(T.Time,T.s08,'DisplayName','left LU-9 + 6mm'); yyaxis left; plot(T.Time,T.s09,'DisplayName','left ST-19'); yyaxis right; plot(T.Time,T.s10,'DisplayName','left ST-19 + 6mm'); yyaxis left; plot(T.Time,T.s11,'DisplayName','left ST-36'); yyaxis right; plot(T.Time,T.s12,'DisplayName','left ST-36 + 6mm'); yyaxis left; % temperature % yyaxis right; % T=TT; % plot(T.Time,T.s01,'DisplayName','Breath 01'); % %plot(T.Time,T.s02,'DisplayName','Breath 02'); % ylabel('Temperature at nostril (Celcius)') % yyaxis left; ylabel('Impedance at 40 kHz (K\Omega)') legend('show', 'Location', 'northwest') grid title('Impedance; bandpass filter at 0.286 - 0.5 hz (3.5 - 2 s)') xlabel('Time (seconds)') %====== peaks [pks,locs] = findpeaks(T4.s05); locs=locs/1000; % ================ detrend opol = 22; T=TT; dt=T; [p,s,mu] = polyfit(T.Time,T.(3),opol); f_y = polyval(p,T.Time,[],mu); dt.(3) = T.(3) - f_y; figure set(groot,'defaultLineLineWidth',1); set(gca,'FontSize',14, 'Box' , 'on', 'YColor', 'black'); set(gca, 'LineStyleOrder', {'-', '--', ':', '-.'}); hold all; plot(T.Time,dt.(3),'DisplayName','Breath (detrend)'); ylabel('Impedance at 40kHz (K\Omega), DC removed, plots spaced by 5\Omega each') legend('show', 'Location', 'northwest') grid title('Impedance perpendicular to right LU-6; bandpass filter 0.435 - 0.250 Hz') xlabel('Time (seconds)') % ====== markers yyaxis right m1=458.862; m2=476.038; yMax=1.5; yMin=-.5; x=[m1,m1]; plot(x,y,'--','Color',[0.277 0.473 0.098],'DisplayName','hold breath'); hold on; x=[m2,m2]; plot(x,y,'--','Color',[0.277 0.473 0.098],'HandleVisibility','off');