eeg_topo_surface_script - explore surface interpolation/plots of ERP potentials
0001 % eeg_topo_surface_script - explore surface interpolation/plots of ERP potentials 0002 0003 clear; 0004 0005 shape = 'ellipse'; 0006 shade = 'interp'; 0007 0008 elecpath = 'D:\MyDocuments\emse_data\ptsd-pet\source modelling\c07\meshes\'; 0009 elecfile = 'c07_124fit.txt'; 0010 0011 voltpath = 'D:\MyDocuments\emse_data\ptsd-pet\source modelling\c07\eeg\'; 0012 voltfile = 'c07oac.dat'; 0013 0014 lappath = 'D:\MyDocuments\emse_data\ptsd-pet\lap14hz\'; 0015 lapfile = 'c07oac_lap14hz.dat'; 0016 0017 hjorthpath = 'D:\MyDocuments\emse_data\ptsd-pet\source modelling\c07\eeg\'; 0018 hjorthfile = 'c07oac_hjorth.dat'; 0019 0020 0021 0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0023 % load electrode co-ordinates and create 3D interpolated surface 0024 0025 file = strcat(elecpath,elecfile); 0026 [elec,type,X,Y,Z,th,phi,r] = elec_load(file,'cart'); 0027 % Get electrode dataset centroid and reload 0028 index = find(type == 99); xo = X(index); yo = Y(index); zo = Z(index); 0029 [elec,type,X,Y,Z,th,phi,r] = elec_load(file,'cart',xo,yo,zo); 0030 0031 % Select electrodes only 0032 index = find(type == 69); 0033 elec = elec(index); 0034 X = X(index); Y = Y(index); Z = Z(index); 0035 th = th(index); phi = phi(index); r = r(index); 0036 0037 % Gradations within co-ordinates 0038 Xmin = floor(min(X)); Xmax = ceil(max(X)); 0039 Ymin = floor(min(Y)); Ymax = ceil(max(Y)); 0040 0041 if abs(Xmin) < abs(Xmax) x = abs(Xmax); else x = abs(Xmin); end 0042 if abs(Ymin) < abs(Ymax) y = abs(Ymax); else y = abs(Ymin); end 0043 if (x < y) m = y; else m = x; end 0044 0045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0046 % Interpolate the electrode co-ordinates 0047 0048 % grid, given cm input for electrode locations 0049 grid = 1.0; xi = -m:grid:m; yi = xi'; gridSize = length(xi); 0050 0051 switch shape 0052 case 'ellipse' 0053 [r,Xe,Ye,Ze,Xes,Yes,Zes] = elec_ellipse_fit(X,Y,Z,xo,yo,0,gridSize); % Fit ellipse to X,Y,Z 0054 [Xi,Yi,Zi] = griddata(Xe,Ye,Ze,xi,yi,'cubic'); % Cubic spline interpolation 0055 %figure; plot3(X,Y,Z,'d'), hold on; plot3(Xe,Ye,Ze,'r.'), hold off; rotate3D 0056 %figure; surf(Xes,Yes,Zes); shading (shade); view([-20 20]); rotate3D 0057 clear Xes Yes Zes; 0058 case 'sphere' 0059 [r,Xs,Ys,Zs,Xss,Yss,Zss] = elec_sphere_fit1(X,Y,Z,xo,yo,0,gridSize); % Fit sphere to Z 0060 [Xi,Yi,Zi] = griddata(Xs,Ys,Zs,xi,yi,'cubic'); % Cubic spline interpolation 0061 %figure; plot3(X,Y,Z,'d'), hold on; plot3(Xs,Ys,Zs,'r.'), hold off; rotate3D 0062 %figure; surf(Xss,Yss,Zss); shading (shade); view([-20 20]); rotate3D 0063 clear Xss Yss Zss; 0064 otherwise 0065 [Xi,Yi,Zi] = griddata(X,Y,Z,xi,yi,'cubic'); % Cubic spline interpolation 0066 end 0067 0068 0069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0070 % load and plot data (124 rows x 680 columns) 0071 0072 timecol = 450; 0073 0074 % Original Voltage 0075 file = strcat(voltpath,voltfile); 0076 volt = eeg_ascii_load(file); 0077 %volt = eeg_uv2volt(volt); 0078 V = volt(:,timecol); 0079 Vi = griddata(X,Y,V,xi,yi,'cubic'); 0080 % figure; surfc(Xi,Yi,Vi); title 'Orig Potential'; shading (shade); colorbar; rotate3d 0081 figure; surf(Xi,Yi,Zi,Vi); title 'Orig Potential'; shading (shade); colorbar; rotate3d 0082 0083 % May have to convert Vi to spherical coordinates for this to work. 0084 % figure; surf(Xes,Yes,Zes,Vi); title 'Orig Potential'; shading (shade); colorbar; rotate3d 0085 0086 0087 % EMSE Laplacian of spherical spline 0088 % file = strcat(lappath,lapfile); 0089 % lap = eeg_ascii_load(file); 0090 % L = lap(:,timecol); 0091 % Li = griddata(X,Y,L,xi,yi,'cubic'); 0092 % figure; surfc(Xi,Yi,Li); title 'EMSE Laplacian'; shading (shade); colorbar; rotate3d 0093 % figure; surf(Xi,Yi,Zi,Li); title 'EMSE Laplacian'; shading (shade); colorbar; rotate3d 0094 0095 0096 % My Laplacian of spherical spline 0097 % Lsn = eeg_lap(V,X,Y,Z,xo,yo,zo); 0098 % Lsni = griddata(X,Y,Lsn,xi,yi,'cubic'); 0099 % figure; surf(Xi,Yi,Lsni); title 'My Spline Laplacian'; shading (shade); colorbar; rotate3d 0100 % figure; surf(Xi,Yi,Zi,Lsni); title 'My Spline Laplacian'; shading (shade); colorbar; rotate3d 0101 0102 0103 % EMSE hjorth 0104 % file = strcat(hjorthpath,hjorthfile); 0105 % hjorth = eeg_ascii_load(file); 0106 % hjorth = hjorth(:,1:124)'; 0107 % H = hjorth(:,timecol); 0108 % Hi = griddata(X,Y,H,xi,yi,'cubic'); 0109 % figure; surf(Xi,Yi,Zi,Hi); title 'EMSE Hjorth'; shading (shade); colorbar; rotate3d 0110 0111 0112 % My Hjorth 0113 Hji = eeg_lap_hjorth(Vi,xi,yi); 0114 % figure; surfc(Xi,Yi,Hji); title 'My Hjorth Laplacian'; shading (shade); colorbar; rotate3d 0115 figure; surf(Xi,Yi,Zi,Hji); title 'My Hjorth Laplacian'; shading (shade); colorbar; rotate3d 0116 0117 0118 % Scalp current density 0119 % SCDi = eeg_lap2scd(Li); 0120 % figure; surf(Xi,Yi,Zi,SCDi); title 'Spline SCD'; shading (shade); colorbar; rotate3d