Commit 8faaab06 authored by Julius Welzel's avatar Julius Welzel

Replace ana07_TOPOdiff.m

parent 47525d52
......@@ -7,38 +7,52 @@
% Topography analysis
% Author: Julius Welzel // University of Oldenburg, 2019
% Version: 1.0 // 28.02.2019 // Initial setup
% Version: 1.1 // 16.03.2019 // Analysis for 3 FBs
% define paths
PATHIN_ERD = [MAIN '04_Data\ana04_erd\'];
PATHIN_RT = [MAIN '04_Data\'];
PATHIN_EMG = [MAIN '04_Data\ana03_emg\'];
PATHOUT_TOPODIFF = [MAIN '04_Data\ana07_TOPOdiff\'];
setGlobal(PATHOUT_TOPODIFF);
PATHOUT_TOODIFF = [MAIN '04_Data\ana07_topdiff\'];
PATHOUT_IND_PLOT = [PATHOUT_TOODIFF 'ind_plot\'];
if ~exist(PATHOUT_TOODIFF)
mkdir(PATHOUT_TOODIFF);
end
if ~exist(PATHOUT_TOPODIFF)
mkdir(PATHOUT_TOPODIFF);
if ~exist(PATHOUT_IND_PLOT)
mkdir(PATHOUT_IND_PLOT);
end
load([PATHIN_ERD 'cfg.mat']);
list = dir(fullfile([PATHIN_RT 'ana02_clean\*clean*.set']));
SUBJ = extractBefore({list.name},'_');
load([PATHIN_ERD 'ERD_mue.mat']);
load([PATHIN_ERD 'cfg_mue.mat']);
load([PATHIN_EMG 'emg_all.mat']);
SUBJ = str2double(SUBJ);
old = (SUBJ>=80);
young = (SUBJ<80);
% define trails of interest
ME_trials = [cfg.blck_idx{[1 4],1}];
MI_trials = [cfg.blck_idx{[2 3],1}];
SUBJ = str2double(SUBJ);
old = (SUBJ>=80);
young = (SUBJ<80);
FB = {'mue','beta','broad'};
%% loop over FBs
for fb = 1:length(FB)
%%
load([PATHIN_ERD 'ERD_' FB{fb} '.mat']);
load([PATHIN_EMG 'emg_all.mat']);
%% Zscore data over all participants only for MI trials
z_top = zscore(nanmean(m_rERD_trial(:,:,MI_trials),3),[],2);
top_old = mean(z_top(old,:));
top_young = mean(z_top(young,:));
top_old = nanmean(z_top(old,:));
top_young = nanmean(z_top(young,:));
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
......@@ -55,6 +69,17 @@ xlin = linspace(min(elocsX),max(elocsX),p_interp);
ylin = linspace(min(elocsY),max(elocsY),p_interp);
[Xgrid, Ygrid] = meshgrid(xlin,ylin);
%channel distances
d_mat = distmat([elocsX;elocsY]');
d_min = min(d_mat(d_mat > 0));
d_max = max(d_mat(d_mat > 0));
% calculate spatial frequency
spat_freq = d_max/(2*d_min);
n_level = 6; %number of rings from equiDist layout EASYCAP
n_intersect = ceil(n_level*spat_freq+(n_level*spat_freq)*0.2); % round up plus extra 20% for extra resolution
%% calculate surface area of topoplot for each trial
%{
surf_old = {};
......@@ -93,96 +118,54 @@ end
% 3D topographies of ERD maps
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot topographie interpolated with surface area scatter
figure
ax1 = subplot(2,4,[1 2]);
Z_young = griddata(elocsX,elocsY,top_young,Xgrid,Ygrid,'cubic');
mesh(Xgrid,Ygrid,Z_young) % interpolate
colormap(ax1,c_young_map)
axis tight;hold on;
plot3(elocsX,elocsY,top_young,'.k','MarkerSize',15)
title 'Interpolated Topoplot Young'
hold on
surf(Xgrid,Ygrid,min(min(Z_young))*0.5*ones(size(Z_young)),'FaceAlpha',0.5,'EdgeColor','none')
stlwrite('mod_young3D.stl',Xgrid,Ygrid,Z_young*0.2,'FaceColor',c_young)
ax2 = subplot(2,4,[5 6]);
Z_old = griddata(elocsX,elocsY,top_old,Xgrid,Ygrid,'cubic');
mesh(Xgrid,Ygrid,Z_old) % interpolate
colormap(ax2,c_old_map)
axis tight;hold on;
plot3(elocsX,elocsY,top_old,'.k','MarkerSize',15)
title 'Interpolated Topoplot Old'
hold on
surf(Xgrid,Ygrid,min(min(Z_old))*0.5*ones(size(Z_old)),'FaceAlpha',0.5,'EdgeColor','none')
stlwrite('mod_old3D.stl',Xgrid,Ygrid,Z_old*0.2,'FaceColor',c_old*255)
x_values = linspace(0,3,length(surf_old));
subplot(2,4,[3 4 7 8])
pd = fitdist([surf_old{:}]','normal');
y = pdf(pd,x_values);
p1 = plot(x_values,y,'Color',c_old,'LineWidth',2);
hold on
scatter([surf_old{:}],x_values,2,c_old)
hold on
pd = fitdist([surf_young{:}]','normal');
y = pdf(pd,x_values);
p2 = plot(x_values,y,'Color',c_young,'LineWidth',2);
hold on
scatter([surf_young{:}],x_values,2,c_young)
legend([p1 p2],{'OLD','YOUNG'})
title ({'Surface Area of highest 50% ERD','All trials each group'})
save_fig(gcf,PATHOUT_TOPODIFF,'surf_area_ERD_st','fontsize',15,'figsize',[0 0 35 25]);
%% only 3D topoplots over both groups with topoplot
c_lines = 10;
% only 3D topoplots over both groups with topoplot
c_lines = 200;
figure;
ax1 = subplot(1,2,1);
Z_young = griddata(elocsX,elocsY,mean(z_top(young,:)),Xgrid,Ygrid,'cubic');
Z_young = griddata(elocsX,elocsY,top_young,Xgrid,Ygrid,'cubic');
mesh(Xgrid,Ygrid,Z_young) % interpolate
colormap(ax1,c_map)
axis tight;hold on;
plot3(elocsX,elocsY,mean(z_top(young,:)),'.k','MarkerSize',15) %plot electrodes
plot3(elocsX,elocsY,top_young,'.k','MarkerSize',15) %plot electrodes
title '3D Topoplot Young'
zlabel 'z-Score'
zlabel 'z-Score [\sigma]'
set(gca,'YTickLabel',[]);
set(gca,'XTickLabel',[]);
hold on
%intersect lines
surf(Xgrid,Ygrid,0*ones(size(Z_young)),'FaceColor','k','FaceAlpha',0.08,'EdgeColor','none')
% surf(Xgrid,Ygrid,0*ones(size(Z_young)),'FaceColor','k','FaceAlpha',0.08,'EdgeColor','none')
%topoplot
[~,h] = contourf(Xgrid,Ygrid,Z_young,c_lines); %# get handle to contourgroup object
[~,h_o] = contourf(Xgrid,Ygrid,Z_young,c_lines,'LineStyle','none'); %# get handle to contourgroup object
colormap (ax1,c_map)
%# change the ZData property of the inner patches
h.ContourZLevel = 1.1*min(min(Z_young));
h_o.ContourZLevel = 1.1*min(min(Z_young));
% OLD 3D PLOT
ax2 = subplot(1,2,2);
Z_old = griddata(elocsX,elocsY,mean(z_top(old,:)),Xgrid,Ygrid,'cubic');
Z_old = griddata(elocsX,elocsY,top_old,Xgrid,Ygrid,'cubic');
mesh(Xgrid,Ygrid,Z_old) % interpolate
colormap(ax2,c_map)
axis tight;hold on;
plot3(elocsX,elocsY,mean(z_top(old,:)),'.k','MarkerSize',15)
plot3(elocsX,elocsY,top_old,'.k','MarkerSize',15)
title '3D Topolot Old'
zlabel 'z-Score'
zlabel 'z-Score [\sigma]'
set(gca,'YTickLabel',[]);
set(gca,'XTickLabel',[]);
hold on
%intetsect planes
surf(Xgrid,Ygrid,0*ones(size(Z_old)),'FaceColor','k','FaceAlpha',0.08,'EdgeColor','none')
hold on
% surf(Xgrid,Ygrid,0*ones(size(Z_old)),'FaceColor','k','FaceAlpha',0.08,'EdgeColor','none')
% hold on
%topoplot
[~,h] = contourf(Xgrid,Ygrid,Z_old,c_lines); %# get handle to contourgroup object
[~,h_o] = contourf(Xgrid,Ygrid,Z_old,c_lines,'LineStyle','none'); %# get handle to contourgroup object
colormap (ax1,c_map)
%# change the ZData property of the inner patches
h.ContourZLevel = 1.1*min(min(Z_old));
h_o.ContourZLevel = 1.3*min(min(Z_old));
% save_fig(gcf,PATHOUT_TOPODIFF,'3D_tops','figtype','.fig')
save_fig(gcf,PATHOUT_TOODIFF,['3D_tops_' FB{fb}],'figtype','.png','figsize',[0 0 55 25],'fontsize',20)
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
......@@ -190,9 +173,9 @@ h.ContourZLevel = 1.1*min(min(Z_old));
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{
gd(1).Z= griddata(elocsX,elocsY,mean(z_top(young,:)),Xgrid,Ygrid,'cubic'); %young
gd(2).Z = griddata(elocsX,elocsY,mean(z_top(old,:)),Xgrid,Ygrid,'cubic'); %old
gd(1).Z= griddata(elocsX,elocsY,top_young,Xgrid,Ygrid,'cubic'); %young
gd(2).Z = griddata(elocsX,elocsY,top_old,Xgrid,Ygrid,'cubic'); %old
group = {'Young','Old'};
plane_sect = linspace(0,-1.2,6);
......@@ -218,31 +201,149 @@ for g = 1:length(gd)
title(['Area : ' num2str(a) ' at z = ' num2str(plane_sect(i))])
end
sgtitle ([group{g} ' participants'])
save_fig(gcf,PATHOUT_TOPODIFF,['SurfArea_' group{g}],'figtype','.fig')
save_fig(gcf,PATHOUT_TOODIFF,['SurfArea_' FB{fb} '_' group{g}],'figtype','.fig')
end
%}
maps_st = zscore(nanmean(m_rERD_trial(:,:,MI_trials),3),[],2);
for s = 1:length(SUBJ)
if SUBJ(s)<50;c_map = c_y_map;else;c_map = c_o_map;end;
area_z_t_avg(s,:) = inter_area(cfg.chanlocs,maps_st(s,:),48,SUBJ(s),PATHOUT_TOPODIFF,c_map);
if SUBJ(s)<50;c_map_ind = c_y_map;else;c_map_ind = c_o_map;end
area_z_t_avg(s,:) = inter_area(cfg.chanlocs,maps_st(s,:),n_intersect,SUBJ(s),PATHOUT_IND_PLOT,c_map_ind,FB{fb});
end
[m_a_old se_a_old] = mean_SEM(area_z_t_avg(old,:)');
[m_a_young se_a_young] = mean_SEM(area_z_t_avg(young,:)');
shadedErrorBar(1:size(area_z_t_avg,2),m_a_old,se_a_old,'lineprops',{'-','Color',c_old,'LineWidth',2})
save([PATHOUT_TOODIFF 'inter_area_' FB{fb} '.mat'],'area_z_t_avg')
%% Plot topographie interpolated with surface area fun
[v i] = max(mean(area_z_t_avg(old,:))-mean(area_z_t_avg(young,:))); % max diff in area
figure
ax1 = subplot(2,7,[1 2]);
Z_young = griddata(elocsX,elocsY,top_young,Xgrid,Ygrid,'cubic');
sy = mesh(Xgrid,Ygrid,Z_young); % interpolate
py = surf2patch(sy);
colormap(ax1,c_y_map)
axis tight;hold on;
plot3(elocsX,elocsY,top_young,'.k','MarkerSize',15)
title 'Interpolated Topoplot Young'
hold on
AO = plot(1:size(area_z_t_avg,2),m_a_old,'-','Color',c_old,'LineWidth',2)
surf(Xgrid,Ygrid,v*ones(size(Z_young)),'FaceAlpha',0.2,'EdgeColor','none')
zlabel 'z-Score [\sigma]'
set(gca,'YTickLabel',[]);
set(gca,'XTickLabel',[]);
ax2 = subplot(2,7,[7 8]+1);
Z_old = griddata(elocsX,elocsY,top_old,Xgrid,Ygrid,'cubic');
mesh(Xgrid,Ygrid,Z_old) % interpolate
colormap(ax2,c_o_map)
axis tight;hold on;
plot3(elocsX,elocsY,top_old,'.k','MarkerSize',15)
title 'Interpolated Topoplot Old'
hold on
shadedErrorBar(1:size(area_z_t_avg,2),m_a_young,se_a_young,'lineprops',{'-','Color',c_young,'LineWidth',2})
surf(Xgrid,Ygrid,v*ones(size(Z_old)),'FaceAlpha',0.2,'EdgeColor','none')
zlabel 'z-Score [\sigma]'
set(gca,'YTickLabel',[]);
set(gca,'XTickLabel',[]);
ax3 = subplot(2,7,[4:7,11:14]); % area
[m_a_old, se_a_old] = mean_SEM(area_z_t_avg(old,:)');
[m_a_young, se_a_young] = mean_SEM(area_z_t_avg(young,:)');
% scatter(1:n_intersect,m_a_old,[],c_o_map(c_idx,:),'fill')
bo = boundedline(flip(m_a_old),1:n_intersect,flip(se_a_old),'orientation', 'horiz','alpha','cmap',c_old);
bo.Color = c_old;
hold on
AY = plot(1:size(area_z_t_avg,2),m_a_young,'-','Color',c_young,'LineWidth',2)
by = boundedline(flip(m_a_young),1:n_intersect,flip(se_a_young),'orientation', 'horiz','alpha','cmap',c_young);
by.Color = c_young;
ylabel 'z-Score of intersect [\sigma]'
xlabel 'Area at intersect [u]'
yticks([1 size(area_z_t_avg,2)])
yticklabels({'min Z','max Z'})
hline(n_intersect-i+1,'--k')
legend ([bo,by],{'Old','Young'})
legend boxoff
save_fig(gcf,PATHOUT_TOODIFF,['surf_area_overview_' FB{fb}],'fontsize',20,'figsize',[0 0 40 20]);
%% 3D topo only
figure
ax1 = subplot(2,1,1);
Z_young = griddata(elocsX,elocsY,top_young,Xgrid,Ygrid,'cubic');
sy = mesh(Xgrid,Ygrid,Z_young); % interpolate
py = surf2patch(sy);
colormap(ax1,c_y_map)
axis tight;hold on;
plot3(elocsX,elocsY,top_young,'.k','MarkerSize',15)
title 'Interpolated Topoplot Young'
zlabel 'z-Score [\sigma]'
set(gca,'YTickLabel',[]);
set(gca,'XTickLabel',[]);
% write 3D modle file
stlwrite([PATHOUT_TOODIFF 'mod_young3D.stl'],Xgrid,Ygrid,Z_old*0.2);
fv = stlread([PATHOUT_TOODIFF 'mod_young3D.stl']);
stlwrite([PATHOUT_TOODIFF 'mod_young3D_' FB{fb} '.stl'],fv,'FaceColor',c_old);
ax2 = subplot(2,1,2);
Z_old = griddata(elocsX,elocsY,top_old,Xgrid,Ygrid,'cubic');
mesh(Xgrid,Ygrid,Z_old) % interpolate
colormap(ax2,c_o_map)
axis tight;hold on;
plot3(elocsX,elocsY,top_old,'.k','MarkerSize',15)
title 'Interpolated Topoplot Old'
zlabel 'z-Score [\sigma]'
set(gca,'YTickLabel',[]);
set(gca,'XTickLabel',[]);
% write 3D modle file
stlwrite([PATHOUT_TOODIFF 'mod_old3D.stl'],Xgrid,Ygrid,Z_old*0.2);
fv = stlread([PATHOUT_TOODIFF 'mod_old3D.stl']);
stlwrite([PATHOUT_TOODIFF 'mod_old3D_' FB{fb} '.stl'],fv,'FaceColor',c_old);
save_fig(gcf,PATHOUT_TOODIFF,['3D_topo_plain_' FB{fb}],'fontsize',18,'figsize',[0 0 12 20]);
%% Disttribution params
if exist ('area_z_t_avg') ~= 1; load([PATHOUT_TOODIFF 'fun_surf_area.mat']);end
p = numSubplots(size(area_z_t_avg,2)); % for subplot config
% Kurtosis
x_val = linspace(min(min(z_top)),max(max(z_top)),length(area_z_t_avg));
kurt = round(kurtosis(area_z_t_avg,[],1),1);
skew = round(skewness(area_z_t_avg,[],1),1);
c_idx = 56:-1:9;
figure
for i = 1:size(area_z_t_avg,2)
subplot(p(1),p(2),i)
%plot dist old
h_o = histfit(area_z_t_avg(old,i));
h_o(1).FaceColor = c_o_map(c_idx(i),:);
h_o(2).Color = c_o_map(c_idx(i),:);
h_o(1).FaceAlpha = 0.5;
h_o(1).EdgeColor = 'none';
hold on
%plot dist young
h_y = histfit(area_z_t_avg(young,i));
h_y(1).FaceColor = c_y_map(c_idx(i),:);
h_y(2).Color = c_y_map(c_idx(i),:);
h_y(1).FaceAlpha = 0.5;
h_y(1).EdgeColor = 'none';
hold on
%add title & legend info
legend([h_o(2) h_y(2)],{'Old','Young'},'Location','northeast');
legend boxoff
title (['Kurt: ' num2str(kurt(i)) ' // Skew: ' num2str(skew(i))]);
end
xlabel 'Z-Score map [Z]'
ylabel 'Area [u]'
xticks([1 size(area_z_t_avg,2)/2 size(area_z_t_avg,2)])
xticklabels({'max Z','0','min Z'})
save_fig(gcf,PATHOUT_TOODIFF,['dist_surf_area_' FB{fb}],'fontsize',8,'figsize',[0 0 50 40]);
legend ([AO,AY],{'Old','Young'})
\ No newline at end of file
end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment