Cerebral Haemodynamic Autoregulatory Information System GUI 1.0.0

File: <base>/CHARIS_GUI_CODE/CHARISGUIpacketAve2.m (2,782 bytes)
function [PRx,PacketAvg_Time,PacketAvg_ABP,PacketAvg_ICP]=CHARISGUIpacketAve2(indBot, indTop,ABP,ICP,Time,All)
% Packet Averaging ICP


% Inputs: indBot and indTop can be used to specify start/end 
% indices for the ABP, ICP, and Time channels. 
% All must = 0 for indBot and indTop be used.
% Otherwise, the entire signal will be packet averaged. 



%% Packet Averaging ICP


rate = 50; % 50 Hz.
seconds = 5; % 5 seconds packet size gives PRx distortion threshold (more than 5 s gives errorneously lowered PRx).
packet_size = seconds*rate; % 10 seconds packet size @50Hz = 500 data points for first packet size.

if All==0
    ICP=ICP(indBot:indTop,1);
    ABP=ABP(indBot:indTop,1);
    Time=Time(indBot:indTop,1);
end


%% Concatenate time, ABP, ICP columns from all the LVM files.
Time_cat=[ ];
ABP_cat= [ ];
ICP_cat= [ ];
Time_cat = cat(1, Time_cat, Time);
ABP_cat = cat(1, ABP_cat, ABP);
ICP_cat = cat(1, ICP_cat, ICP);


%% Time, ABP, ICP  Packeting 

No_of_packet_windows = ceil(length(Time_cat)/packet_size);

Time_cat_pkted=[ ];
ABP_cat_pkted= [ ];
ICP_cat_pkted= [ ];

for N_packets = 1:No_of_packet_windows
    if N_packets ~= No_of_packet_windows
        Time_cat_pkted(N_packets) = mean(Time_cat((packet_size*(N_packets-1))+1 : (packet_size*N_packets)));
        ABP_cat_pkted(N_packets) = mean(ABP_cat((packet_size*(N_packets-1))+1 : (packet_size*N_packets)));
        ICP_cat_pkted(N_packets) = mean(ICP_cat((packet_size*(N_packets-1))+1 : (packet_size*N_packets)));
    elseif N_packets == No_of_packet_windows
        Time_cat_pkted(N_packets) = mean(Time_cat((packet_size*(N_packets-1))+1 : end));
        ABP_cat_pkted(N_packets) = mean(ABP_cat((packet_size*(N_packets-1))+1 : end));
        ICP_cat_pkted(N_packets) = mean(ICP_cat((packet_size*(N_packets-1))+1 : end));
    end
end 


%% Plotting

% 5 minutes 
for c = 1:length(ICP_cat_pkted) - 60 % 1min = 12 pkted data pts, 5min = 60 pkted data pts. 
    PRx_temp_5min = corrcoef(ABP_cat_pkted(c:c+60), ICP_cat_pkted(c:c+60));
    PRx(c, 1)  = PRx_temp_5min(1,2);
end



% 10 minutes 
for c = 1:length(ICP_cat_pkted) - 120
    PRx_temp_10min = corrcoef(ABP_cat_pkted(c:c+120), ICP_cat_pkted(c:c+120));
    PRx(c, 2)  = PRx_temp_10min(1,2);
end


% 20 minutes
for c = 1:length(ICP_cat_pkted) - 240
    PRx_temp_20min = corrcoef(ABP_cat_pkted(c:c+240), ICP_cat_pkted(c:c+240));
    PRx(c, 3)  = PRx_temp_20min(1,2);
end


PacketAvg_Time=Time_cat_pkted';
PacketAvg_ABP=ABP_cat_pkted';
PacketAvg_ICP=ICP_cat_pkted';

PRx5=PRx(:,1);
PRx10=PRx(:,2);
PRx20=PRx(:,3);

fix5=zeros(60,1);
PRx5=[fix5;PRx5];
PRx10=[fix5;fix5;PRx10(1:end-60,1)];
PRx20=[fix5;fix5;fix5;fix5;PRx20(1:end-180,1)];

PRx=[PRx5,PRx10,PRx20];

end