plateform
stringclasses 1
value | repo_name
stringlengths 13
113
| name
stringlengths 3
74
| ext
stringclasses 1
value | path
stringlengths 12
229
| size
int64 23
843k
| source_encoding
stringclasses 9
values | md5
stringlengths 32
32
| text
stringlengths 23
843k
|
---|---|---|---|---|---|---|---|---|
github
|
adelbibi/Tensor_CSC-master
|
region_zca.m
|
.m
|
Tensor_CSC-master/Training/image_helpers/contrast_normalization/region_zca.m
| 5,318 |
utf_8
|
c24cbfa1f961dc41ec067dc7f4aa7bf2
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%>
% This functin is used to whiten an image with patch based ZCA whitening that is applied
% convolutionally to the image.
%
% @file
% @author Matthew Zeiler
% @date Jun 28, 2010
%
% @image_file @copybrief region_zca.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%>
% @copybrief region_zca.m
%
% @param img the image to whiten.
%
% @retval w_filt the whitening filter to apply convolutionally.
% @retval d_filt the corresponding de-whitening filter to apply convolutionally.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [w_filt,d_filt] = region_zca(img)
NUM_PATCHES = 1;
PATCH_SIZE = 19;
BORDER_SIZE = 4;
[imx,imy,imc,M] = size(img);
count = 0;
w_filt = zeros(PATCH_SIZE,PATCH_SIZE,3,3);
d_filt = zeros(PATCH_SIZE,PATCH_SIZE,3,3);
for i=1:NUM_PATCHES
i
%% choose start coords of patch
r = floor(rand(1,2).*([imy,imx]-PATCH_SIZE)+1);
%% grab patches & compute covariance matrix
p = img(r(1):r(1)+PATCH_SIZE-1,r(2):r(2)+PATCH_SIZE-1,:,:);
m = reshape(p,[3*PATCH_SIZE^2,M]);
mu = mean(m,2);
cm = double(m) - mu*ones(1,M);
CC = cm * cm';
%[u,s,v] = svd(CC);
[u,s] = eig(CC);
q = diag(s);
qi = find(q>0);
q1(qi) = q(qi).^-0.5;
q2(qi) = q(qi).^0.5;
W = u(:,qi)*diag(q1(qi))*u(:,qi)';
D = u(:,qi)*diag(q2(qi))*u(:,qi)';
for d=1:imc
for j=[(d-1)*floor(size(W,1)/3)+1:d*floor(size(W,1)/3)]
r = reshape(W(j,:),[PATCH_SIZE PATCH_SIZE 3]);
dr = reshape(D(j,:),[PATCH_SIZE PATCH_SIZE 3]);
[sy,sx] = ind2sub([1 1]*PATCH_SIZE,j-(d-1)*floor(size(W,1)/3));
sx = -(sx - floor(PATCH_SIZE/2));
sy = -(sy - floor(PATCH_SIZE/2));
if (abs(sx)<floor(PATCH_SIZE/2)-BORDER_SIZE) & (abs(sy)<floor(PATCH_SIZE/2)-BORDER_SIZE)
for c=1:imc
r2(:,:,c) = circshift(r(:,:,c),[sy sx]+1);
dr2(:,:,c) = circshift(dr(:,:,c),[sy sx]+1);
end
w_filt(:,:,:,d) = w_filt(:,:,:,d) + r2;
d_filt(:,:,:,d) = d_filt(:,:,:,d) + dr2;
count = count + 1;
% figure(99); imagesc(uint8(1e-1*dr2)); pause(0.1); drawnow;
end
end
end
figure(1); clf; montage(reshape(w_filt/sum(w_filt(:).^2),PATCH_SIZE,PATCH_SIZE,1,imc^2)); caxis([-0.1 0.1]);
figure(2); clf; montage(reshape(d_filt/sum(d_filt(:).^2),PATCH_SIZE,PATCH_SIZE,1,imc^2)); caxis([-1e-3 1e-3]);
%keyboard
%%% check conv vs patch based efforts
for d=1:3
im_w(:,:,d)=convn(img(:,:,:,1),w_filt(:,:,3:-1:1,d),'valid');
end
for d=1:3
im_dw(:,:,d)=convn(im_w,d_filt(:,:,3:-1:1,d),'valid');
filt_check(:,:,:,d)=convn(w_filt(:,:,3:-1:1,d),d_filt(:,:,3:-1:1,d),'same');
end
figure(6); clf; montage(reshape(filt_check,PATCH_SIZE,PATCH_SIZE,1,imc^2)); caxis([-1e3 1e3]);
im_w = im_w - min(im_w(:));
im_w = im_w / max(im_w(:));
im_dw = im_dw - min(im_dw(:));
im_dw = im_dw / max(im_dw(:));
q = [];
for c=1:3
q= [ q ; im2col(img(:,:,c,1),[1 1]*PATCH_SIZE,'distinct') ];
end
block_w = W*double(q);
for c=1:3
im_w2(:,:,c) = col2im(block_w((c-1)*PATCH_SIZE^2+1:c*PATCH_SIZE^2,:),[1 1]*PATCH_SIZE,[imy imx],'distinct');
end
q = [];
for c=1:3
q= [ q ; im2col(im_w2(:,:,c),[1 1]*PATCH_SIZE,'distinct') ];
end
block_dw = D*double(q);
for c=1:3
im_dw2(:,:,c) = col2im(block_dw((c-1)*PATCH_SIZE^2+1:c*PATCH_SIZE^2,:),[1 1]*PATCH_SIZE,[imy imx],'distinct');
end
im_w2 = im_w2 - min(im_w2(:));
im_w2 = im_w2 / max(im_w2(:));
figure(3); clf;
ultimateSubplot(1,2,1,1,0.1); imagesc(uint8(255*im_dw));
ultimateSubplot(1,2,1,2,0.1); imagesc(uint8(im_dw2));
figure(4); clf;
ultimateSubplot(1,2,1,1,0.1); imagesc(uint8(255*im_w));
ultimateSubplot(1,2,1,2,0.1); imagesc(uint8(255*im_w2));
end
w_filt = w_filt(:,:,3:-1:1,:) / (count/3);
d_filt = d_filt(:,:,3:-1:1,:) / (count/3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Solve least squares system for the dewhitening fitlers.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d_filt2 = zeros(size(d_filt));
% Get middle index (where the filters are in ZCAtransform.
middle = sub2ind([PATCH_SIZE PATCH_SIZE],ceil(PATCH_SIZE/2),ceil(PATCH_SIZE/2));
for d=1:size(w_filt,4) %% The output channels.
for c=1:size(w_filt,3) % The input image color channels.
W = conv2mat(w_filt(:,:,c,d),[PATCH_SIZE PATCH_SIZE],'full');
rhs = zeros(size(W,1),1);
rhs(middle) = 1;
d_filt2(:,:,c,d) = reshape(W\rhs,PATCH_SIZE,PATCH_SIZE);
end
figure(200+d)
imshow(d_filt2(:,:,:,d));
% keyboard
end
for c=1:3
filt_check2(:,:,:,c)=convn(w_filt(:,:,3:-1:1,c),d_filt2(:,:,3:-1:1,c),'same');
end
figure(7); clf; montage(reshape(filt_check2,PATCH_SIZE,PATCH_SIZE,1,imc^2)); caxis([-1e3 1e3]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
keyboard
|
github
|
adelbibi/Tensor_CSC-master
|
inv_f_dewhiten.m
|
.m
|
Tensor_CSC-master/Training/image_helpers/contrast_normalization/inv_f_dewhiten.m
| 1,601 |
utf_8
|
6083f4eb9343995c663452f48e0e7475
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%>
% The function to dewhiten an image with 1/f whitening.
%
% @file
% @author Matthew Zeiler
% @date Jun 28, 2010
%
% @image_file @copybrief inv_f_dewhiten.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%>
% @copybrief inf_f_dewhiten.m
%
% @param img the image to dewhiten.
% @param filt the filter to
%
% @retval dewhiten_img the whitened image.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [dewhiten_img] = inv_f_dewhiten(img,filt)
[imx,imy,imc,M] = size(img);
%N=image_size;
%M=num_images;
if nargin==1
WHITEN_POWER = 4;
WHITEN_SCALE = 0.4;
EPSILON = 1e-3;
[fx fy]=meshgrid(-imy/2:imy/2-1,-imx/2:imx/2-1);
rho=sqrt(fx.*fx+fy.*fy);
f_0=WHITEN_SCALE*mean([imx,imy]);
filt=rho.*exp(-(rho/f_0).^WHITEN_POWER) + EPSILON;
end
% img = img(2:end-1,2:end-1,:,:);
% filt = filt(2:end-1,2:end-1,:,:);
dewhiten_img = zeros(size(img));
for i=1:M
for c=1:imc
If=fft2(img(:,:,c,i));
imagew=real(ifft2(If./fftshift(filt)));
dewhiten_img(:,:,c,i) = imagew;
end
% If=fftn(img(:,:,:,i));
% imagew = real(ifftn(If./fftshift(filt)));
% dewhiten_img(:,:,:,i) = imagew;
%
end
% mm = min(dewhiten_img(:));
% dewhiten_img = dewhiten_img - mm;
% mx = max(dewhiten_img(:));
% dewhiten_img = dewhiten_img / mx;
figure(3), sdispims(dewhiten_img,'ycbcr');
figure(4), sdispims(filt);
|
github
|
adelbibi/Tensor_CSC-master
|
inv_f_whiten.m
|
.m
|
Tensor_CSC-master/Training/image_helpers/contrast_normalization/inv_f_whiten.m
| 2,510 |
utf_8
|
7b586cde91c557cf3a3faaf992eeaf2b
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%>
% The function to whiten an image with 1/f whitening.
%
% @file
% @author Matthew Zeiler
% @date Jun 28, 2010
%
% @image_file @copybrief inv_f_whiten.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%>
% @copybrief inf_f_whiten.m
%
% @param img the image to whiten.
%
% @retval whiten_img the whitened image.
% @retval filt the corresponding dwhitening filter that was applied convolutionally.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [whiten_img,filt] = inv_f_whiten(img)
img = double(img);
WHITEN_POWER = 4
WHITEN_SCALE = 0.4
EPSILON = 1e-6
[imx1,imy1,imc1,M1] = size(img);
%N=image_size;
%M=num_images;
%
%
%
% ly = imy1;
% lx = imx1;
% sy = imy1;
% sx = imx1;
%
% %% These values are the index of the small mtx that falls on the
% %% border pixel of the large matrix when computing the first
% %% convolution response sample:
% ctr=1;
% sy2 = floor((sy+ctr+1)/2);
% sx2 = floor((sx+ctr+1)/2);
%
% % pad:
% img = [ ...
% img(ly-sy+sy2+1:ly,lx-sx+sx2+1:lx,:,:),...
% img(ly-sy+sy2+1:ly,:,:,:), ...
% img(ly-sy+sy2+1:ly,1:sx2-1,:,:); ...
% img(:,lx-sx+sx2+1:lx,:,:), ...
% img, ...
% img(:,1:sx2-1,:,:); ...
% img(1:sy2-1,lx-sx+sx2+1:lx,:,:), ...
% img(1:sy2-1,:,:,:), ...
% img(1:sy2-1,1:sx2-1,:,:) ];
% img = padarray(img,[100 100]);
% keyboard
[imx,imy,imc,M] = size(img);
whiten_img = zeros(size(img));
[fx fy]=meshgrid(-imy/2:imy/2-1,-imx/2:imx/2-1);
rho=sqrt(fx.*fx+fy.*fy);
f_0=WHITEN_SCALE*mean([imx,imy]);
filt=rho.*exp(-(rho/f_0).^WHITEN_POWER) + EPSILON;
for i=1:M
for c=1:imc
If=fft2(img(:,:,c,i));
imagew=real(ifft2(If.*fftshift(filt)));
whiten_img(:,:,c,i) = imagew;
end
% If=fftn(img(:,:,:,i));
% imagew = real(ifftn(If.*fftshift(filt)));
% whiten_img(:,:,:,i) = imagew;
%
end
% starty = ly-(ly-sy+sy2);
% startx = lx-(lx-sx+sx2);
% whiten_img = whiten_img(starty:starty+imy1,startx:startx+imx1,:,:);
%
figure(1), sdispims(whiten_img);
figure(2), sdispims(filt);
%whiten_img(1:2,:,:,:) = EPSILON;
%whiten_img(:,1:2,:,:) = EPSILON;
%whiten_img(end-1:end,:,:,:) = EPSILON;
%whiten_img(:,end-1:end,:,:) = EPSILON;
%IMAGES=sqrt(0.1)*IMAGES/sqrt(mean(var(IMAGES)));
%save MY_IMAGES IMAGES
|
github
|
zhuwei378287521/px4-master
|
ellipsoid_fit.m
|
.m
|
px4-master/Tools/Matlab/ellipsoid_fit.m
| 6,102 |
utf_8
|
b8fff7152313707a347ab528f7fbce9b
|
% Copyright (c) 2009, Yury Petrov
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
function [ center, radii, evecs, v ] = ellipsoid_fit( X, flag, equals )
%
% Fit an ellispoid/sphere to a set of xyz data points:
%
% [center, radii, evecs, pars ] = ellipsoid_fit( X )
% [center, radii, evecs, pars ] = ellipsoid_fit( [x y z] );
% [center, radii, evecs, pars ] = ellipsoid_fit( X, 1 );
% [center, radii, evecs, pars ] = ellipsoid_fit( X, 2, 'xz' );
% [center, radii, evecs, pars ] = ellipsoid_fit( X, 3 );
%
% Parameters:
% * X, [x y z] - Cartesian data, n x 3 matrix or three n x 1 vectors
% * flag - 0 fits an arbitrary ellipsoid (default),
% - 1 fits an ellipsoid with its axes along [x y z] axes
% - 2 followed by, say, 'xy' fits as 1 but also x_rad = y_rad
% - 3 fits a sphere
%
% Output:
% * center - ellispoid center coordinates [xc; yc; zc]
% * ax - ellipsoid radii [a; b; c]
% * evecs - ellipsoid radii directions as columns of the 3x3 matrix
% * v - the 9 parameters describing the ellipsoid algebraically:
% Ax^2 + By^2 + Cz^2 + 2Dxy + 2Exz + 2Fyz + 2Gx + 2Hy + 2Iz = 1
%
% Author:
% Yury Petrov, Northeastern University, Boston, MA
%
error( nargchk( 1, 3, nargin ) ); % check input arguments
if nargin == 1
flag = 0; % default to a free ellipsoid
end
if flag == 2 && nargin == 2
equals = 'xy';
end
if size( X, 2 ) ~= 3
error( 'Input data must have three columns!' );
else
x = X( :, 1 );
y = X( :, 2 );
z = X( :, 3 );
end
% need nine or more data points
if length( x ) < 9 && flag == 0
error( 'Must have at least 9 points to fit a unique ellipsoid' );
end
if length( x ) < 6 && flag == 1
error( 'Must have at least 6 points to fit a unique oriented ellipsoid' );
end
if length( x ) < 5 && flag == 2
error( 'Must have at least 5 points to fit a unique oriented ellipsoid with two axes equal' );
end
if length( x ) < 3 && flag == 3
error( 'Must have at least 4 points to fit a unique sphere' );
end
if flag == 0
% fit ellipsoid in the form Ax^2 + By^2 + Cz^2 + 2Dxy + 2Exz + 2Fyz + 2Gx + 2Hy + 2Iz = 1
D = [ x .* x, ...
y .* y, ...
z .* z, ...
2 * x .* y, ...
2 * x .* z, ...
2 * y .* z, ...
2 * x, ...
2 * y, ...
2 * z ]; % ndatapoints x 9 ellipsoid parameters
elseif flag == 1
% fit ellipsoid in the form Ax^2 + By^2 + Cz^2 + 2Gx + 2Hy + 2Iz = 1
D = [ x .* x, ...
y .* y, ...
z .* z, ...
2 * x, ...
2 * y, ...
2 * z ]; % ndatapoints x 6 ellipsoid parameters
elseif flag == 2
% fit ellipsoid in the form Ax^2 + By^2 + Cz^2 + 2Gx + 2Hy + 2Iz = 1,
% where A = B or B = C or A = C
if strcmp( equals, 'yz' ) || strcmp( equals, 'zy' )
D = [ y .* y + z .* z, ...
x .* x, ...
2 * x, ...
2 * y, ...
2 * z ];
elseif strcmp( equals, 'xz' ) || strcmp( equals, 'zx' )
D = [ x .* x + z .* z, ...
y .* y, ...
2 * x, ...
2 * y, ...
2 * z ];
else
D = [ x .* x + y .* y, ...
z .* z, ...
2 * x, ...
2 * y, ...
2 * z ];
end
else
% fit sphere in the form A(x^2 + y^2 + z^2) + 2Gx + 2Hy + 2Iz = 1
D = [ x .* x + y .* y + z .* z, ...
2 * x, ...
2 * y, ...
2 * z ]; % ndatapoints x 4 sphere parameters
end
% solve the normal system of equations
v = ( D' * D ) \ ( D' * ones( size( x, 1 ), 1 ) );
% find the ellipsoid parameters
if flag == 0
% form the algebraic form of the ellipsoid
A = [ v(1) v(4) v(5) v(7); ...
v(4) v(2) v(6) v(8); ...
v(5) v(6) v(3) v(9); ...
v(7) v(8) v(9) -1 ];
% find the center of the ellipsoid
center = -A( 1:3, 1:3 ) \ [ v(7); v(8); v(9) ];
% form the corresponding translation matrix
T = eye( 4 );
T( 4, 1:3 ) = center';
% translate to the center
R = T * A * T';
% solve the eigenproblem
[ evecs evals ] = eig( R( 1:3, 1:3 ) / -R( 4, 4 ) );
radii = sqrt( 1 ./ diag( evals ) );
else
if flag == 1
v = [ v(1) v(2) v(3) 0 0 0 v(4) v(5) v(6) ];
elseif flag == 2
if strcmp( equals, 'xz' ) || strcmp( equals, 'zx' )
v = [ v(1) v(2) v(1) 0 0 0 v(3) v(4) v(5) ];
elseif strcmp( equals, 'yz' ) || strcmp( equals, 'zy' )
v = [ v(2) v(1) v(1) 0 0 0 v(3) v(4) v(5) ];
else % xy
v = [ v(1) v(1) v(2) 0 0 0 v(3) v(4) v(5) ];
end
else
v = [ v(1) v(1) v(1) 0 0 0 v(2) v(3) v(4) ];
end
center = ( -v( 7:9 ) ./ v( 1:3 ) )';
gam = 1 + ( v(7)^2 / v(1) + v(8)^2 / v(2) + v(9)^2 / v(3) );
radii = ( sqrt( gam ./ v( 1:3 ) ) )';
evecs = eye( 3 );
end
|
github
|
wf8/IB290-master
|
afunc.m
|
.m
|
IB290-master/lecture_slides/Mtg05_Carl_misc/bugs_in_a_box/bugsinbox.app/Contents/Resources/lib/python2.6/scipy/io/matlab/tests/afunc.m
| 198 |
utf_8
|
001c8b39c33bf4f7513b2e87a13478f2
|
function [a, b] = afunc(c, d)
% A function
a = c + 1;
b = d + 10;
function [a, b] = afunc(c, d)
% A function
a = c + 1;
b = d + 10;
function [a, b] = afunc(c, d)
% A function
a = c + 1;
b = d + 10;
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_conditions_333.m
|
.m
|
CorticoHippocampal-master/plot_inter_conditions_333.m
| 12,130 |
utf_8
|
e61ed84f6d5a52d1bdb7e3797793bc5d
|
%This one requires running data from Non Learning condition
function [h]=plot_inter_conditions_33(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% ripple3=ripple_nl;
%ran=randi(length(p),100,1);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
[p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
[ran_nl]=select_rip(p_nl);
%
% av=cat(1,p_nl{1:end});
% %av=cat(1,q_nl{1:end});
% av=av(1:3:end,:); %Only Hippocampus
%
% %AV=max(av.');
% %[B I]= maxk(AV,1000);
%
% %AV=max(av.');
% %[B I]= maxk(max(av.'),1000);
%
%
% [ach]=max(av.');
% achinga=sort(ach,'descend');
% %achinga=achinga(1:1000);
% if length(achinga)>1000
% if Rat==24
% achinga=achinga(6:1005);
% else
% achinga=achinga(1:1000);
% end
% end
%
% B=achinga;
% I=nan(1,length(B));
% for hh=1:length(achinga)
% % I(hh)= min(find(ach==achinga(hh)));
% I(hh)= find(ach==achinga(hh),1,'first');
% end
%
%
% [ajal ind]=unique(B);
% if length(ajal)>500
% ajal=ajal(end-499:end);
% ind=ind(end-499:end);
% end
% dex=I(ind);
%
% ran_nl=dex.';
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
timecell_nl=timecell_nl([ran_nl]);
%Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,timecell_nl);
P2_nl=avg_samples(p_nl,timecell_nl);
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
%%
h(1)=subplot(3,4,1)
plot(timecell_nl{1},P2_nl(w,:))
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('Wide Band No Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (t)')
ylabel('uV')
%%
h(3)=subplot(3,4,3)
plot(timecell_nl{1},P1_nl(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('High Gamma No Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
xlabel('Time (t)')
ylabel('uV')
%%
h(2)=subplot(3,4,2)
plot(timecell{1},P2(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(4)=subplot(3,4,4)
plot(timecell{1},P1(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%% Time Frequency plots
% Calculate Freq1 and Freq2
if ro==1200
toy = [-1.2:.01:1.2];
else
toy = [-10.2:.1:10.2];
end
%toy = [-1.2:.01:1.2];
if length(p)>length(p_nl)
p=p(1:length(p_nl));
timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
timecell_nl=timecell_nl(1:length(p));
end
freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10,toy);
freq2=justtesting(p,timecell,[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
h(5)=subplot(3,4,5)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band No Learning');
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
h(6)=subplot(3,4,6)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
ylim([0.5 30])
%%
if ro==1200
[stats]=stats_between_trials(freq1,freq2,label1,w);
else
[stats]=stats_between_trials10(freq1,freq2,label1,w);
end
%%
h(9)=subplot(3,4,10)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
g=title(strcat(labelconditions{iii},' vs No Learning'))
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%Calculate Freq3 and Freq4
%toy=[-1:.01:1];
if ro==1200
toy=[-1:.01:1];
else
toy=[-10:.1:10];
end
if length(q)>length(q_nl)
q=q(1:length(q_nl));
timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
timecell_nl=timecell_nl(1:length(q));
end
if ro==1200
freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w,toy);
freq4=barplot2_ft(q,timecell,[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,timecell_nl,[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,timecell,[100:2:300],w,toy);
end
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
cfg = [];
cfg.channel = freq3.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq3);
[zmin2, zmax2] = ft_getminmax(cfg, freq4);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;
cfg.channel = freq3.label{w};
cfg.colormap=colormap(jet(256));
%%
h(7)=subplot(3,4,7)
ft_singleplotTFR(cfg, freq3);
% freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
g=title('High Gamma No Learning');
g.FontSize=12;
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%
h(8)=subplot(3,4,8);
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
ft_singleplotTFR(cfg, freq4);
g=title(strcat('High Gamma',{' '},labelconditions{iii}));
g.FontSize=12;
%title(strcat('High Gamma',{' '},labelconditions{iii}))
%xo
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
if ro==1200
[stats1]=stats_between_trials(freq3,freq4,label1,w);
else
[stats1]=stats_between_trials10(freq3,freq4,label1,w);
end
%% %
h(10)=subplot(3,4,12);
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%% EXTRA STATISTICS
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_conditions_278.m
|
.m
|
CorticoHippocampal-master/plot_inter_conditions_278.m
| 10,948 |
utf_8
|
de2d5417349d8d733e64ae186ce3e625
|
%This one requires running data from Non Learning condition
function plot_inter_conditions_278(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
ripple3=ripple_nl;
%ran=randi(length(p),100,1);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
[p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
av=cat(1,p_nl{1:end});
%av=cat(1,q_nl{1:end});
av=av(1:3:end,:); %Only Hippocampus
%AV=max(av.');
%[B I]= maxk(AV,1000);
%AV=max(av.');
%[B I]= maxk(max(av.'),1000);
[ach]=max(av.');
achinga=sort(ach,'descend');
achinga=achinga(1:1000);
B=achinga;
I=nan(1,length(B));
for hh=1:length(achinga)
% I(hh)= min(find(ach==achinga(hh)));
I(hh)= find(ach==achinga(hh),1,'first');
end
[ajal ind]=unique(B);
if length(ajal)>500
ajal=ajal(end-499:end);
ind=ind(end-499:end);
end
dex=I(ind);
ran_nl=dex.';
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
timecell_nl=timecell_nl([ran_nl]);
%Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,timecell_nl);
P2_nl=avg_samples(p_nl,timecell_nl);
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
%%
subplot(2,3,1)
plot(timecell_nl{1},P2_nl(w,:))
xlim([-1,1])
%xlim([-0.8,0.8])
grid minor
narrow_colorbar()
title('Wide Band NO Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (t)')
ylabel('uV')
%%
% subplot(3,3,3)
% plot(timecell_nl{1},P1_nl(w,:))
% xlim([-1,1])
% %xlim([-0.8,0.8])
% grid minor
% narrow_colorbar()
% title('High Gamma NO Learning')
%
% win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
% win2=[(min(win2)) (max(win2))];
% ylim(win2)
%%
subplot(2,3,2)
plot(timecell{1},P2(w,:))
xlim([-1,1])
%xlim([-0.8,0.8])
grid minor
narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii-3}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
% subplot(2,3,4)
% plot(timecell{1},P1(w,:))
% xlim([-1,1])
% %xlim([-0.8,0.8])
% grid minor
% narrow_colorbar()
% %title('High Gamma RIPPLE')
% title(strcat('High Gamma',{' '},labelconditions{iii-3}))
% %title(strcat('High Gamma',{' '},labelconditions{iii}))
% ylim(win2)
%% Time Frequency plots
% Calculate Freq1 and Freq2
toy = [-1.2:.01:1.2];
if length(p)>length(p_nl)
p=p(1:length(p_nl));
timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
timecell_nl=timecell_nl(1:length(p));
end
freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10,toy);
freq2=justtesting(p,timecell,[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
subplot(2,3,4)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band NO Learning');
g.FontSize=10;
xlim([-1 1])
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
subplot(2,3,5)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii-3}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=10;
xlim([-1 1])
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
%%
%
[stats]=stats_between_trials(freq1,freq2,label1,w);
%%
subplot(2,3,6)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
g=title(strcat(labelconditions{iii-3},' vs No Learning'))
g.FontSize=10;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%Calculate Freq3 and Freq4
toy=[-1:.01:1];
if length(q)>length(q_nl)
q=q(1:length(q_nl));
timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
timecell_nl=timecell_nl(1:length(q));
end
freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w,toy);
freq4=barplot2_ft(q,timecell,[100:1:300],w,toy);
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
% cfg = [];
% cfg.channel = freq3.label{w};
% [ zmin1, zmax1] = ft_getminmax(cfg, freq30);
% [zmin2, zmax2] = ft_getminmax(cfg, freq40);
%
% zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
%
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
% cfg = [];
% cfg.zlim=zlim;
% cfg.channel = freq3.label{w};
% cfg.colormap=colormap(jet(256));
%%
% subplot(2,3,3)
% ft_singleplotTFR(cfg, freq3);
% % freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
% title('High Gamma NO Learning')
%%
%
% subplot(2,3,3)
% % freq4=barplot2_ft(q,timecell,[100:1:300],w)
% %freq=justtesting(q,timecell,[100:1:300],w,0.5)
% %title('High Gamma RIPPLE')
% ft_singleplotTFR(cfg, freq4);
% title(strcat('High Gamma',{' '},labelconditions{iii-3}))
% %title(strcat('High Gamma',{' '},labelconditions{iii}))
%%
[stats1]=stats_between_trials(freq3,freq4,label1,w);
%% %
subplot(2,3,3)
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
grid minor
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
g=title(strcat(labelconditions{iii-3},' vs No Learning'));
g.FontSize=10;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%% EXTRA STATISTICS
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_FIXED.m
|
.m
|
CorticoHippocampal-master/plot_inter_FIXED.m
| 16,482 |
utf_8
|
8827d94eadd29318f7f74e9458d35119
|
%This one requires running data from Non Learning condition
function plot_inter_FIXED(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,selectripples,acer,P1_nl,P2_nl,p_nl,q_nl,freq1,freq3,freq2,freq4)
%function plot_inter_conditions_27(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,selectripples)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
%ran=randi(length(p),100,1);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
% % % % % % % % % % % % % % [p_nl,q_nl,timecell,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % % % % % % % % % % % % % % % ran_nl=ran;
% % % % % % % % % % % % % % if selectripples==1
% % % % % % % % % % % % % %
% % % % % % % % % % % % % % [ran_nl]=rip_select(p);
% % % % % % % % % % % % % % % av=cat(1,p_nl{1:end});
% % % % % % % % % % % % % % % %av=cat(1,q_nl{1:end});
% % % % % % % % % % % % % % % av=av(1:3:end,:); %Only Hippocampus
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % %AV=max(av.');
% % % % % % % % % % % % % % % %[B I]= maxk(AV,1000);
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % %AV=max(av.');
% % % % % % % % % % % % % % % %[B I]= maxk(max(av.'),1000);
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % [ach]=max(av.');
% % % % % % % % % % % % % % % achinga=sort(ach,'descend');
% % % % % % % % % % % % % % % achinga=achinga(1:1000);
% % % % % % % % % % % % % % % B=achinga;
% % % % % % % % % % % % % % % I=nan(1,length(B));
% % % % % % % % % % % % % % % for hh=1:length(achinga)
% % % % % % % % % % % % % % % % I(hh)= min(find(ach==achinga(hh)));
% % % % % % % % % % % % % % % I(hh)= find(ach==achinga(hh),1,'first');
% % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % [ajal ind]=unique(B);
% % % % % % % % % % % % % % % if length(ajal)>500
% % % % % % % % % % % % % % % ajal=ajal(end-499:end);
% % % % % % % % % % % % % % % ind=ind(end-499:end);
% % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % % dex=I(ind);
% % % % % % % % % % % % % % % ran_nl=dex.';
% % % % % % % % % % % % % %
% % % % % % % % % % % % % % p_nl=p_nl([ran_nl]);
% % % % % % % % % % % % % % q_nl=q_nl([ran_nl]);
% % % % % % % % % % % % % % timecell=timecell([ran_nl]);
% % % % % % % % % % % % % %
% % % % % % % % % % % % % %
% % % % % % % % % % % % % % end
%Need: P1, P2 ,p, q.
% % % % % % % % % % % % % P1_nl=avg_samples(q_nl,timecell);
% % % % % % % % % % % % % P2_nl=avg_samples(p_nl,timecell);
% % % if acer==0
% % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % %
% % % else
% % % cd(strcat('D:\internship\',num2str(Rat)))
% % % end
% % % cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
H1=subplot(3,4,1);
plot(timecell{1},P2_nl(w,:))
xlim([-1,1])
%xlim([-0.8,0.8])
grid minor
Hc1=narrow_colorbar();
title('Wide Band NO Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
%%
H3=subplot(3,4,3)
plot(timecell{1},P1_nl(w,:))
xlim([-1,1])
%xlim([-0.8,0.8])
grid minor
Hc3=narrow_colorbar()
title('High Gamma NO Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
%%
H2=subplot(3,4,2)
plot(timecell{1},P2(w,:))
xlim([-1,1])
%xlim([-0.8,0.8])
grid minor
Hc2=narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii-3}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
%%
H4=subplot(3,4,4)
plot(timecell{1},P1(w,:))
xlim([-1,1])
%xlim([-0.8,0.8])
grid minor
Hc4=narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii-3}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
%% Time Frequency plots
% Calculate Freq1 and Freq2
toy = [-1.2:.01:1.2];
% if selectripples==1
%
% if length(p)>length(p_nl)
% p=p(1:length(p_nl));
% timecell=timecell(1:length(p_nl));
% end
%
% if length(p)<length(p_nl)
% p_nl=p_nl(1:length(p));
% timecell=timecell(1:length(p));
% end
% end
%This is what I uncommented:
% freq1=justtesting(p_nl,timecell,[1:0.5:30],w,10,toy);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5,toy);
% FREQ1=justtesting(p_nl,timecell,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%% Baseline normalization (UNCOMMENT THE NEXT LINES IF YOU NEED IT)
% % % % % % % % % % % % % % % % % % % % % % % % cfg=[];
% % % % % % % % % % % % % % % % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % % % % % % % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % % % % % % % % % % % % % % % cfg.baselinetype ='db';
% % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % freq10=ft_freqbaseline(cfg,freq1);
% % % % % % % % % % % % % % % % % % % % % % % % freq20=ft_freqbaseline(cfg,freq2);
% % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % [achis]=baseline_norm(freq1,w);
% % % % % % % % % % % % % % % % % % % % % % % % [achis2]=baseline_norm(freq2,w);
% % % % % % % % % % % % % % % % % % % % % % % % climdb=[-3 3];
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
% % % % % cfg = [];
% % % % % cfg.channel = freq1.label{w};
% % % % % [ zmin1, zmax1] = ft_getminmax(cfg, freq10);
% % % % % [zmin2, zmax2] = ft_getminmax(cfg, freq20);
% % % % %
% % % % % zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% % % % %
% % % % % zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
% % % % % % % % % % % % % % % % % % % cfg = [];
% % % % % % % % % % % % % % % % % % % cfg.zlim=zlim;% Uncomment this!
% % % % % % % % % % % % % % % % % % % cfg.channel = freq1.label{w};
% % % % % % % % % % % % % % % % % % % cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%% NEW SECTION I ADDED
achis=freq1.powspctrm;
achis=squeeze(mean(achis,1));
achis=squeeze(achis(w,:,:));
achis2=freq2.powspctrm;
achis2=squeeze(mean(achis2,1));
achis2=squeeze(achis2(w,:,:));
%%
ax1 =subplot(3,4,5);
contourf(toy,freq1.freq,achis,40,'linecolor','none');
colormap(jet(256));%narrow_colorbar();
% set(gca,'clim',climdb,'ydir','normal','xlim',[-1 1])
set(gca,'ydir','normal','xlim',[-1 1])
c1=colorbar();
h1 = get(H1, 'position'); % get axes position
hn1= get(Hc1, 'Position'); % Colorbar Width for c1
x1 = get(ax1, 'position'); % get axes position
cw1= get(c1, 'Position'); % Colorbar Width for c1
cw1(3)=hn1(3);
cw1(1)=hn1(1);
set(c1,'Position',cw1)
x1(3)=h1(3);
set(ax1,'Position',x1)
% freq1=justtesting(p_nl,timecell,[1:0.5:30],w,10)
title('Wide Band NO Learning')
%xlim([-1 1])
%%
% subplot(3,4,6)
%%ft_singleplotTFR(cfg, freq20);
ax2 =subplot(3,4,6);
contourf(toy,freq2.freq,achis2,40,'linecolor','none');
colormap(jet(256));%narrow_colorbar();
%set(gca,'clim',climdb,'ydir','normal','xlim',[-1 1])
set(gca,'ydir','normal','xlim',[-1 1])
c2=colorbar();
h2 = get(H2, 'position'); % get axes position
hn2= get(Hc2, 'Position'); % Colorbar Width for c1
x2 = get(ax2, 'position'); % get axes position
cw2= get(c2, 'Position'); % Colorbar Width for c1
cw2(3)=hn2(3);
cw2(1)=hn2(1);
set(c2,'Position',cw2)
x2(3)=h2(3);
set(ax2,'Position',x2)
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
title(strcat('Wide Band',{' '},labelconditions{iii-3}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
xlim([-1 1])
%%
%
[stats]=stats_between_trials(freq1,freq2,label1,w);
%
subplot(3,4,10)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
title(strcat(labelconditions{iii-3},' vs No Learning'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
%Calculate Freq3 and Freq4
toy=[-1:.01:1];
%
% if selectripples==1
%
% if length(q)>length(q_nl)
% q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
% end
%
% if length(q)<length(q_nl)
% q_nl=q_nl(1:length(q));
% timecell=timecell(1:length(q));
% end
% end
%THis is what I uncommented:
% freq3=barplot2_ft(q_nl,timecell,[100:1:300],w,toy);
% freq4=barplot2_ft(q,timecell,[100:1:300],w,toy);
%% UNCOMMENT THIS IF YOU WANT TO NORMALIZE WRT TO THE BASELINE
% % % % % % % % % % % % cfg=[];
% % % % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
% % % % % % % % % % % % [achis3]=baseline_norm(freq3,w);
% % % % % % % % % % % % [achis4]=baseline_norm(freq4,w);
% % % % % % % % % % % % climdb=[-3 3];
%% NEW SECTION I ADDED
achis3=freq3.powspctrm;
achis3=squeeze(mean(achis3,1));
achis3=squeeze(achis3(w,:,:));
achis4=freq4.powspctrm;
achis4=squeeze(mean(achis4,1));
achis4=squeeze(achis4(w,:,:));
%%
% Calculate zlim
% % % % cfg = [];
% % % % cfg.channel = freq3.label{w};
% % % % [ zmin1, zmax1] = ft_getminmax(cfg, freq30);
% % % % [zmin2, zmax2] = ft_getminmax(cfg, freq40);
% % % %
% % % % zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% % % %
% % % % zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
% % % % cfg = [];
% % % % cfg.zlim=zlim;
% % % % cfg.channel = freq3.label{w};
% % % % cfg.colormap=colormap(jet(256));
%%
%subplot(3,4,7)
%ft_singleplotTFR(cfg, freq30);
ax3 =subplot(3,4,7);
contourf(toy,freq3.freq,achis3,40,'linecolor','none');
colormap(jet(256));%narrow_colorbar();
% set(gca,'clim',climdb,'ydir','normal','xlim',[-1 1])
set(gca,'ydir','normal','xlim',[-1 1])
c3=colorbar();
h3 = get(H3, 'position'); % get axes position
hn3= get(Hc3, 'Position'); % Colorbar Width for c1
x3 = get(ax3, 'position'); % get axes position
cw3= get(c3, 'Position'); % Colorbar Width for c1
cw3(3)=hn3(3);
cw3(1)=hn3(1);
set(c3,'Position',cw3)
x3(3)=h3(3);
set(ax3,'Position',x3)
% freq3=barplot2_ft(q_nl,timecell,[100:1:300],w);
title('High Gamma NO Learning')
%%
ax4 =subplot(3,4,8);
contourf(toy,freq4.freq,achis4,40,'linecolor','none');
colormap(jet(256));%narrow_colorbar();
% set(gca,'clim',climdb,'ydir','normal','xlim',[-1 1])
set(gca,'ydir','normal','xlim',[-1 1])
c4=colorbar();
h4 = get(H4, 'position'); % get axes position
hn4= get(Hc4, 'Position'); % Colorbar Width for c1
x4 = get(ax4, 'position'); % get axes position
cw4= get(c4, 'Position'); % Colorbar Width for c1
cw4(3)=hn4(3);
cw4(1)=hn4(1);
set(c4,'Position',cw4)
x4(3)=h4(3);
set(ax4,'Position',x4)
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
%%%%%%%%%%%%%%ft_singleplotTFR(cfg, freq40);
title(strcat('High Gamma',{' '},labelconditions{iii-3}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
%%
[stats1]=stats_between_trials(freq3,freq4,label1,w);
% %
subplot(3,4,12)
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
grid minor
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
title(strcat(labelconditions{iii-3},' vs No Learning'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%% EXTRA STATISTICS
% % % % [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % % % % %
% % % % subplot(3,4,11)
% % % % cfg = [];
% % % % cfg.channel = label1{2*w-1};
% % % % cfg.parameter = 'stat';
% % % % cfg.maskparameter = 'mask';
% % % % cfg.zlim = 'maxabs';
% % % % cfg.colorbar = 'yes';
% % % % cfg.colormap=colormap(jet(256));
% % % % grid minor
% % % % ft_singleplotTFR(cfg, stats1);
% % % % %title('Ripple vs No Ripple')
% % % % title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% % % % % % %title(strcat(labelconditions{iii},' vs No Learning'))
% % % % % % %%
% % % %
% % % %
% % % % [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % % % % %
% % % % subplot(3,4,9)
% % % % cfg = [];
% % % % cfg.channel = label1{2*w-1};
% % % % cfg.parameter = 'stat';
% % % % cfg.maskparameter = 'mask';
% % % % cfg.zlim = 'maxabs';
% % % % cfg.colorbar = 'yes';
% % % % cfg.colormap=colormap(jet(256));
% % % % grid minor
% % % % ft_singleplotTFR(cfg, stats1);
% % % % %title('Ripple vs No Ripple')
% % % % title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% % % % %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_FIXED_10.m
|
.m
|
CorticoHippocampal-master/plot_inter_FIXED_10.m
| 16,729 |
utf_8
|
62909012b3f4cd2fb0b77e6c4eb54755
|
%This one requires running data from Non Learning condition
function plot_inter_FIXED_10(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,selectripples,acer,P1_nl,P2_nl,p_nl,q_nl,freq1,freq3,freq2,freq4)
%function plot_inter_conditions_27(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,selectripples)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
%ran=randi(length(p),100,1);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
% % % % % % % % % % % % % % [p_nl,q_nl,timecell,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % % % % % % % % % % % % % % % ran_nl=ran;
% % % % % % % % % % % % % % if selectripples==1
% % % % % % % % % % % % % %
% % % % % % % % % % % % % % [ran_nl]=rip_select(p);
% % % % % % % % % % % % % % % av=cat(1,p_nl{1:end});
% % % % % % % % % % % % % % % %av=cat(1,q_nl{1:end});
% % % % % % % % % % % % % % % av=av(1:3:end,:); %Only Hippocampus
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % %AV=max(av.');
% % % % % % % % % % % % % % % %[B I]= maxk(AV,1000);
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % %AV=max(av.');
% % % % % % % % % % % % % % % %[B I]= maxk(max(av.'),1000);
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % [ach]=max(av.');
% % % % % % % % % % % % % % % achinga=sort(ach,'descend');
% % % % % % % % % % % % % % % achinga=achinga(1:1000);
% % % % % % % % % % % % % % % B=achinga;
% % % % % % % % % % % % % % % I=nan(1,length(B));
% % % % % % % % % % % % % % % for hh=1:length(achinga)
% % % % % % % % % % % % % % % % I(hh)= min(find(ach==achinga(hh)));
% % % % % % % % % % % % % % % I(hh)= find(ach==achinga(hh),1,'first');
% % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % [ajal ind]=unique(B);
% % % % % % % % % % % % % % % if length(ajal)>500
% % % % % % % % % % % % % % % ajal=ajal(end-499:end);
% % % % % % % % % % % % % % % ind=ind(end-499:end);
% % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % % dex=I(ind);
% % % % % % % % % % % % % % % ran_nl=dex.';
% % % % % % % % % % % % % %
% % % % % % % % % % % % % % p_nl=p_nl([ran_nl]);
% % % % % % % % % % % % % % q_nl=q_nl([ran_nl]);
% % % % % % % % % % % % % % timecell=timecell([ran_nl]);
% % % % % % % % % % % % % %
% % % % % % % % % % % % % %
% % % % % % % % % % % % % % end
%Need: P1, P2 ,p, q.
% % % % % % % % % % % % % P1_nl=avg_samples(q_nl,timecell);
% % % % % % % % % % % % % P2_nl=avg_samples(p_nl,timecell);
% % % if acer==0
% % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % %
% % % else
% % % cd(strcat('D:\internship\',num2str(Rat)))
% % % end
% % % cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
H1=subplot(3,4,1);
plot(timecell{1},P2_nl(w,:))
xlim([-10,10])
%xlim([-0.8,0.8])
grid minor
Hc1=narrow_colorbar();
title('Wide Band NO Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
%%
H3=subplot(3,4,3)
plot(timecell{1},P1_nl(w,:))
xlim([-10,10])
%xlim([-0.8,0.8])
grid minor
Hc3=narrow_colorbar()
title('High Gamma NO Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
%%
H2=subplot(3,4,2)
plot(timecell{1},P2(w,:))
xlim([-10,10])
%xlim([-0.8,0.8])
grid minor
Hc2=narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii-3}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
%%
H4=subplot(3,4,4)
plot(timecell{1},P1(w,:))
xlim([-10,10])
%xlim([-0.8,0.8])
grid minor
Hc4=narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii-3}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
%% Time Frequency plots
% Calculate Freq1 and Freq2
%toy = [-10.2:.2:10.2];
toy = [-10.2:.1:10.2];
% if selectripples==1
%
% if length(p)>length(p_nl)
% p=p(1:length(p_nl));
% timecell=timecell(1:length(p_nl));
% end
%
% if length(p)<length(p_nl)
% p_nl=p_nl(1:length(p));
% timecell=timecell(1:length(p));
% end
% end
%This is what I uncommented:
% freq1=justtesting(p_nl,timecell,[1:0.5:30],w,10,toy);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5,toy);
% FREQ1=justtesting(p_nl,timecell,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%% Baseline normalization (UNCOMMENT THE NEXT LINES IF YOU NEED IT)
% % % % % % % % % % % % % % % % % % % % % % % % cfg=[];
% % % % % % % % % % % % % % % % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % % % % % % % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % % % % % % % % % % % % % % % cfg.baselinetype ='db';
% % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % freq10=ft_freqbaseline(cfg,freq1);
% % % % % % % % % % % % % % % % % % % % % % % % freq20=ft_freqbaseline(cfg,freq2);
% % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % [achis]=baseline_norm(freq1,w);
% % % % % % % % % % % % % % % % % % % % % % % % [achis2]=baseline_norm(freq2,w);
% % % % % % % % % % % % % % % % % % % % % % % % climdb=[-3 3];
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
% % % % % cfg = [];
% % % % % cfg.channel = freq1.label{w};
% % % % % [ zmin1, zmax1] = ft_getminmax(cfg, freq10);
% % % % % [zmin2, zmax2] = ft_getminmax(cfg, freq20);
% % % % %
% % % % % zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% % % % %
% % % % % zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
% % % % % % % % % % % % % % % % % % % cfg = [];
% % % % % % % % % % % % % % % % % % % cfg.zlim=zlim;% Uncomment this!
% % % % % % % % % % % % % % % % % % % cfg.channel = freq1.label{w};
% % % % % % % % % % % % % % % % % % % cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%% NEW SECTION I ADDED
achis=freq1.powspctrm;
achis=squeeze(mean(achis,1));
achis=squeeze(achis(w,:,:));
achis2=freq2.powspctrm;
achis2=squeeze(mean(achis2,1));
achis2=squeeze(achis2(w,:,:));
%%
ax1 =subplot(3,4,5);
contourf(toy,freq1.freq,achis,40,'linecolor','none');
colormap(jet(256));%narrow_colorbar();
% set(gca,'clim',climdb,'ydir','normal','xlim',[-1 1])
set(gca,'ydir','normal','xlim',[-10 10])
c1=colorbar();
h1 = get(H1, 'position'); % get axes position
hn1= get(Hc1, 'Position'); % Colorbar Width for c1
x1 = get(ax1, 'position'); % get axes position
cw1= get(c1, 'Position'); % Colorbar Width for c1
cw1(3)=hn1(3);
cw1(1)=hn1(1);
set(c1,'Position',cw1)
x1(3)=h1(3);
set(ax1,'Position',x1)
% freq1=justtesting(p_nl,timecell,[1:0.5:30],w,10)
title('Wide Band NO Learning')
%xlim([-1 1])
%%
% subplot(3,4,6)
%%ft_singleplotTFR(cfg, freq20);
ax2 =subplot(3,4,6);
contourf(toy,freq2.freq,achis2,40,'linecolor','none');
colormap(jet(256));%narrow_colorbar();
%set(gca,'clim',climdb,'ydir','normal','xlim',[-1 1])
set(gca,'ydir','normal','xlim',[-10 10])
c2=colorbar();
h2 = get(H2, 'position'); % get axes position
hn2= get(Hc2, 'Position'); % Colorbar Width for c1
x2 = get(ax2, 'position'); % get axes position
cw2= get(c2, 'Position'); % Colorbar Width for c1
cw2(3)=hn2(3);
cw2(1)=hn2(1);
set(c2,'Position',cw2)
x2(3)=h2(3);
set(ax2,'Position',x2)
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
title(strcat('Wide Band',{' '},labelconditions{iii-3}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
xlim([-10 10])
c1.Limits=[min([c1.Limits c2.Limits]) max([c1.Limits c2.Limits])];
c2.Limits=c1.Limits;
%%
%
[stats]=stats_between_trials10(freq1,freq2,label1,w);
%
subplot(3,4,10)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
title(strcat(labelconditions{iii-3},' vs No Learning'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
%Calculate Freq3 and Freq4
toy=[-10:.1:10];
%toy=[-10:.2:10];
%
% if selectripples==1
%
% if length(q)>length(q_nl)
% q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
% end
%
% if length(q)<length(q_nl)
% q_nl=q_nl(1:length(q));
% timecell=timecell(1:length(q));
% end
% end
%THis is what I uncommented:
% freq3=barplot2_ft(q_nl,timecell,[100:1:300],w,toy);
% freq4=barplot2_ft(q,timecell,[100:1:300],w,toy);
%% UNCOMMENT THIS IF YOU WANT TO NORMALIZE WRT TO THE BASELINE
% % % % % % % % % % % % cfg=[];
% % % % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
% % % % % % % % % % % % [achis3]=baseline_norm(freq3,w);
% % % % % % % % % % % % [achis4]=baseline_norm(freq4,w);
% % % % % % % % % % % % climdb=[-3 3];
%% NEW SECTION I ADDED
achis3=freq3.powspctrm;
achis3=squeeze(mean(achis3,1));
achis3=squeeze(achis3(w,:,:));
achis4=freq4.powspctrm;
achis4=squeeze(mean(achis4,1));
achis4=squeeze(achis4(w,:,:));
%%
% Calculate zlim
% % % % cfg = [];
% % % % cfg.channel = freq3.label{w};
% % % % [ zmin1, zmax1] = ft_getminmax(cfg, freq30);
% % % % [zmin2, zmax2] = ft_getminmax(cfg, freq40);
% % % %
% % % % zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% % % %
% % % % zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
% % % % cfg = [];
% % % % cfg.zlim=zlim;
% % % % cfg.channel = freq3.label{w};
% % % % cfg.colormap=colormap(jet(256));
%%
%subplot(3,4,7)
%ft_singleplotTFR(cfg, freq30);
ax3 =subplot(3,4,7);
contourf(toy,freq3.freq,achis3,40,'linecolor','none');
colormap(jet(256));%narrow_colorbar();
% set(gca,'clim',climdb,'ydir','normal','xlim',[-1 1])
set(gca,'ydir','normal','xlim',[-10 10])
c3=colorbar();
h3 = get(H3, 'position'); % get axes position
hn3= get(Hc3, 'Position'); % Colorbar Width for c1
x3 = get(ax3, 'position'); % get axes position
cw3= get(c3, 'Position'); % Colorbar Width for c1
cw3(3)=hn3(3);
cw3(1)=hn3(1);
set(c3,'Position',cw3)
x3(3)=h3(3);
set(ax3,'Position',x3)
% freq3=barplot2_ft(q_nl,timecell,[100:1:300],w);
title('High Gamma NO Learning')
%%
ax4 =subplot(3,4,8);
contourf(toy,freq4.freq,achis4,40,'linecolor','none');
colormap(jet(256));%narrow_colorbar();
% set(gca,'clim',climdb,'ydir','normal','xlim',[-1 1])
set(gca,'ydir','normal','xlim',[-10 10])
c4=colorbar();
h4 = get(H4, 'position'); % get axes position
hn4= get(Hc4, 'Position'); % Colorbar Width for c1
x4 = get(ax4, 'position'); % get axes position
cw4= get(c4, 'Position'); % Colorbar Width for c1
cw4(3)=hn4(3);
cw4(1)=hn4(1);
set(c4,'Position',cw4)
x4(3)=h4(3);
set(ax4,'Position',x4)
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
%%%%%%%%%%%%%%ft_singleplotTFR(cfg, freq40);
title(strcat('High Gamma',{' '},labelconditions{iii-3}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
c3.Limits=[min([c3.Limits c4.Limits]) max([c3.Limits c4.Limits])];
c4.Limits=c3.Limits;
%%
[stats1]=stats_between_trials10(freq3,freq4,label1,w);
% %
subplot(3,4,12)
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
grid minor
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
title(strcat(labelconditions{iii-3},' vs No Learning'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%% EXTRA STATISTICS
% % % % [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % % % % %
% % % % subplot(3,4,11)
% % % % cfg = [];
% % % % cfg.channel = label1{2*w-1};
% % % % cfg.parameter = 'stat';
% % % % cfg.maskparameter = 'mask';
% % % % cfg.zlim = 'maxabs';
% % % % cfg.colorbar = 'yes';
% % % % cfg.colormap=colormap(jet(256));
% % % % grid minor
% % % % ft_singleplotTFR(cfg, stats1);
% % % % %title('Ripple vs No Ripple')
% % % % title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% % % % % % %title(strcat(labelconditions{iii},' vs No Learning'))
% % % % % % %%
% % % %
% % % %
% % % % [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % % % % %
% % % % subplot(3,4,9)
% % % % cfg = [];
% % % % cfg.channel = label1{2*w-1};
% % % % cfg.parameter = 'stat';
% % % % cfg.maskparameter = 'mask';
% % % % cfg.zlim = 'maxabs';
% % % % cfg.colorbar = 'yes';
% % % % cfg.colormap=colormap(jet(256));
% % % % grid minor
% % % % ft_singleplotTFR(cfg, stats1);
% % % % %title('Ripple vs No Ripple')
% % % % title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% % % % %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_conditions_3.m
|
.m
|
CorticoHippocampal-master/plot_inter_conditions_3.m
| 10,938 |
utf_8
|
52cf9545fea32ab18d7e4cc300ec5d29
|
%This one requires running data from Non Learning condition
function plot_inter_conditions_3(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
ripple3=ripple_nl;
%ran=randi(length(p),100,1);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
[p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
av=cat(1,p_nl{1:end});
%av=cat(1,q_nl{1:end});
av=av(1:3:end,:); %Only Hippocampus
%AV=max(av.');
%[B I]= maxk(AV,1000);
%AV=max(av.');
%[B I]= maxk(max(av.'),1000);
[ach]=max(av.');
achinga=sort(ach,'descend');
achinga=achinga(1:1000);
B=achinga;
I=nan(1,length(B));
for hh=1:length(achinga)
% I(hh)= min(find(ach==achinga(hh)));
I(hh)= find(ach==achinga(hh),1,'first');
end
[ajal ind]=unique(B);
if length(ajal)>500
ajal=ajal(end-499:end);
ind=ind(end-499:end);
end
dex=I(ind);
ran_nl=dex.';
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
timecell_nl=timecell_nl([ran_nl]);
%Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,timecell_nl);
P2_nl=avg_samples(p_nl,timecell_nl);
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
%%
subplot(2,3,1)
plot(timecell_nl{1},P2_nl(w,:))
xlim([-1,1])
%xlim([-0.8,0.8])
grid minor
narrow_colorbar()
title('Wide Band No Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (t)')
ylabel('uV')
%%
% subplot(3,3,3)
% plot(timecell_nl{1},P1_nl(w,:))
% xlim([-1,1])
% %xlim([-0.8,0.8])
% grid minor
% narrow_colorbar()
% title('High Gamma NO Learning')
%
% win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
% win2=[(min(win2)) (max(win2))];
% ylim(win2)
%%
subplot(2,3,2)
plot(timecell{1},P2(w,:))
xlim([-1,1])
%xlim([-0.8,0.8])
grid minor
narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
% subplot(2,3,4)
% plot(timecell{1},P1(w,:))
% xlim([-1,1])
% %xlim([-0.8,0.8])
% grid minor
% narrow_colorbar()
% %title('High Gamma RIPPLE')
% title(strcat('High Gamma',{' '},labelconditions{iii-3}))
% %title(strcat('High Gamma',{' '},labelconditions{iii}))
% ylim(win2)
%% Time Frequency plots
% Calculate Freq1 and Freq2
toy = [-1.2:.01:1.2];
if length(p)>length(p_nl)
p=p(1:length(p_nl));
timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
timecell_nl=timecell_nl(1:length(p));
end
freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10,toy);
freq2=justtesting(p,timecell,[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
subplot(2,3,4)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band No Learning');
g.FontSize=12;
xlim([-1 1])
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
subplot(2,3,5)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=12;
xlim([-1 1])
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
%%
%
[stats]=stats_between_trials(freq1,freq2,label1,w);
%%
subplot(2,3,6)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
g=title(strcat(labelconditions{iii},' vs No Learning'))
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%Calculate Freq3 and Freq4
toy=[-1:.01:1];
if length(q)>length(q_nl)
q=q(1:length(q_nl));
timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
timecell_nl=timecell_nl(1:length(q));
end
freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w,toy);
freq4=barplot2_ft(q,timecell,[100:1:300],w,toy);
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
% cfg = [];
% cfg.channel = freq3.label{w};
% [ zmin1, zmax1] = ft_getminmax(cfg, freq30);
% [zmin2, zmax2] = ft_getminmax(cfg, freq40);
%
% zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
%
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
% cfg = [];
% cfg.zlim=zlim;
% cfg.channel = freq3.label{w};
% cfg.colormap=colormap(jet(256));
%%
% subplot(2,3,3)
% ft_singleplotTFR(cfg, freq3);
% % freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
% title('High Gamma NO Learning')
%%
%
% subplot(2,3,3)
% % freq4=barplot2_ft(q,timecell,[100:1:300],w)
% %freq=justtesting(q,timecell,[100:1:300],w,0.5)
% %title('High Gamma RIPPLE')
% ft_singleplotTFR(cfg, freq4);
% title(strcat('High Gamma',{' '},labelconditions{iii-3}))
% %title(strcat('High Gamma',{' '},labelconditions{iii}))
%%
[stats1]=stats_between_trials(freq3,freq4,label1,w);
%% %
subplot(2,3,3)
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
grid minor
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%% EXTRA STATISTICS
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
psi_paper.m
|
.m
|
CorticoHippocampal-master/HFOs/psi_paper.m
| 900 |
utf_8
|
05f374b0c680c596604100ddab1e03e6
|
function [freq,freq2]=psi_paper(q,timecell,freqrange,fn)
%fn=1000;
data1.trial=q;
data1.time= timecell; %Might have to change this one
data1.fsample=fn;
data1.label=cell(3,1);
% data1.label{1}='Hippocampus';
% data1.label{2}='Parietal';
% data1.label{3}='PFC';
data1.label{1}='PAR';
data1.label{2}='PFC';
data1.label{3}='HPC';
% %Non parametric
% [granger]=createauto_np(data1,freqrange,[]);
cfg = [];
cfg.method = 'mtmfft';
cfg.taper = 'dpss';
cfg.output = 'fourier';
cfg.tapsmofrq = 2; %1/1.2
% cfg.tapsmofrq = 4; %1/1.2
cfg.pad = 10;
cfg.foi=freqrange;
%[0:1:500]
freq = ft_freqanalysis(cfg, data1);
%Parametric
cfg2 = [];
cfg2.order = 10;
cfg2.toolbox = 'bsmart';
mdata2 = ft_mvaranalysis(cfg2, data1);
cfg2 = [];
cfg2.method = 'mvar';
freq2 = ft_freqanalysis(cfg2, mdata2);
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
gui_table.m
|
.m
|
CorticoHippocampal-master/GUI/gui_table.m
| 2,823 |
utf_8
|
4f9a203664bc006a67ec7260f427590e
|
function varargout = gui_table(varargin)
% GUI_TABLE MATLAB code for gui_table.fig
% GUI_TABLE, by itself, creates a new GUI_TABLE or raises the existing
% singleton*.
%
% H = GUI_TABLE returns the handle to a new GUI_TABLE or the handle to
% the existing singleton*.
%
% GUI_TABLE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_TABLE.M with the given input arguments.
%
% GUI_TABLE('Property','Value',...) creates a new GUI_TABLE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_table_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_table_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help gui_table
% Last Modified by GUIDE v2.5 20-Jun-2019 22:50:15
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_table_OpeningFcn, ...
'gui_OutputFcn', @gui_table_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before gui_table is made visible.
function gui_table_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to gui_table (see VARARGIN)
% Choose default command line output for gui_table
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui_table wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_table_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
|
github
|
Aleman-Z/CorticoHippocampal-master
|
gui_spectral.m
|
.m
|
CorticoHippocampal-master/GUI/gui_spectral.m
| 18,734 |
utf_8
|
7ee7efd8bbdcd52c1c4025dcdc5c57d1
|
function varargout = gui_spectral(varargin)
% GUI_SPECTRAL MATLAB code for gui_spectral.fig
% GUI_SPECTRAL, by itself, creates a new GUI_SPECTRAL or raises the existing
% singleton*.
%
% H = GUI_SPECTRAL returns the handle to a new GUI_SPECTRAL or the handle to
% the existing singleton*.
%
% GUI_SPECTRAL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_SPECTRAL.M with the given input arguments.
%
% GUI_SPECTRAL('Property','Value',...) creates a new GUI_SPECTRAL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_spectral_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_spectral_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help gui_spectral
% Last Modified by GUIDE v2.5 14-Apr-2020 14:52:28
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_spectral_OpeningFcn, ...
'gui_OutputFcn', @gui_spectral_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before gui_spectral is made visible.
function gui_spectral_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to gui_spectral (see VARARGIN)
% Choose default command line output for gui_spectral
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% Genzel lab LOGO
% uiwait(handles.figure1);
axes(handles.axes2)
%imshow('memdyn.png')
imshow('butt_sitting_irene.jpg')
axes(handles.axes1)
%imshow('trace.PNG')
[gifImage cmap] = imread('rip_colour.gif', 'Frames', 'all');
[rows, columns, numColorChannels, numImages] = size(gifImage);
% Construct an RGB movie.
rgbImage = zeros(rows, columns, 3, numImages, 'uint8'); % Initialize dimensions.
% set(hObject, 'DeleteFcn', @myhandle)
% get(hObject)
% get(hObject,'DeleteFcn')
% ishandle(gui_spectral)
set(0,'userdata',0)
% RIPPLE CHANGING COLOR
for k = 1 : numImages
% if k==1
% load gong.mat
% sound(y)
% end
thisFrame = gifImage(:,:,:, k);
thisRGB = uint8(255 * ind2rgb(thisFrame, cmap));
imshow(thisRGB);
pause(0.05)
rgbImage(:,:,:,k) = thisRGB;
% caption = sprintf('Frame %#d of %d', k, numImages);
% title(caption);
drawnow;
end
%% Animation attempt.
% % % % % if get(0,'userdata')
% % % % % break
% % % % % end
% % % % % %
% % % % % % fi = get(groot,'CurrentFigure');
% % % % % % fi_val=isvalid(fi);
% % % % % % if fi_val==0
% % % % % % break
% % % % % % end
% % % % %
% % % % % end
% % % % % close all
% % % % % delete(hObject)
% while 1<2
% for k = 1 : numImages
% thisFrame = gifImage(:,:,:, k);
% thisRGB = uint8(255 * ind2rgb(thisFrame, cmap));
% imshow(thisRGB);
% pause(0.1)
% rgbImage(:,:,:,k) = thisRGB;
% % caption = sprintf('Frame %#d of %d', k, numImages);
% % title(caption);
% % drawnow;
% end
% end
% imshow('trace.png')
%%
% --- Outputs from this function are returned to the command line.
function varargout = gui_spectral_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
%BEEP sound.
% --------------------------------------------------------------------
function File_Callback(hObject, eventdata, handles)
% hObject handle to File (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% beepnoise
% pause(.1)
%GUI BUTTONS.
% --------------------------------------------------------------------
function New_experiment_Callback(hObject, eventdata, handles)
% hObject handle to New_experiment (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% gui_new_experiment
% global x
%Ask for experiment information.
x = inputdlg({'Rats ID number','Condition Names','Brain Areas'},'Fill and separate with commas', [1 70; 1 70; 1 70])
rats=str2num(x{1});
label1=split(x{3},',');
labelconditions=split(x{2},',');
%Avoid Windows reserved word CON.
labelconditions2=labelconditions;
labelconditions2(ismember(labelconditions,'CON'))={'CN'}
z= zeros(length(label1),length(rats));
[channels]=gui_table_channels(z,rats,label1,'channels');
assignin('base','rats',rats)
assignin('base','labelconditions',labelconditions)
assignin('base','labelconditions2',labelconditions2)
assignin('base','label1',label1)
assignin('base','channels',channels)
% dname = uigetdir([],'Select folder to save experiment data');
%Save file in folder.
[file,dname,~] = uiputfile('TypeExperimentNameHere.mat','Select folder to save experiment data');
cd(dname)
save (file, 'rats','labelconditions','labelconditions2','label1','channels')
% --------------------------------------------------------------------
function Load_experiment_Callback(hObject, eventdata, handles)
% hObject handle to Load_experiment (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% uiopen('*.mat')
[file,pat]=uigetfile('*.mat','Select the experiment file');
f_name=fullfile(pat,file);
load(f_name, 'rats','labelconditions','labelconditions2','label1','channels');
assignin('base','rats',rats)
assignin('base','labelconditions',labelconditions)
assignin('base','labelconditions2',labelconditions2)
assignin('base','label1',label1)
assignin('base','channels',channels)
messbox('Experiment was loaded','Success')
% f = msgbox('Experiment was loaded','Success');
% --------------------------------------------------------------------
function exit_gui_Callback(hObject, eventdata, handles)
% hObject handle to exit_gui (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
beepnoise
pause(.1)
close all
%PREPROCESSING
% --------------------------------------------------------------------
function Preprocessing_Callback(hObject, eventdata, handles)
% hObject handle to Preprocessing (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
beepnoise
pause(.1)
% --------------------------------------------------------------------
function Downsample_data_Callback(hObject, eventdata, handles)
% hObject handle to Downsample_data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
channels = evalin('base','channels');
label1 = evalin('base','label1');
labelconditions = evalin('base','labelconditions');
labelconditions2 = evalin('base','labelconditions2');
rats = evalin('base','rats');
gui_downsample(channels,label1,labelconditions,labelconditions2,rats);
% % --------------------------------------------------------------------
% function Extract_stages_Callback(hObject, eventdata, handles)
% % hObject handle to Sleep_scoring (see GCBO)
% % eventdata reserved - to be defined in a future version of MATLAB
% % handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Sleep_scoring_Callback(hObject, eventdata, handles)
% hObject handle to Sleep_scoring (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
channels = evalin('base','channels');
label1 = evalin('base','label1');
labelconditions = evalin('base','labelconditions');
labelconditions2 = evalin('base','labelconditions2');
rats = evalin('base','rats');
gui_sleep_scoring(channels,label1,labelconditions,labelconditions2,rats);
% --------------------------------------------------------------------
function Check_sleep_scoring_Callback(hObject, eventdata, handles)
% hObject handle to Check_sleep_scoring (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
channels = evalin('base','channels');
label1 = evalin('base','label1');
labelconditions = evalin('base','labelconditions');
labelconditions2 = evalin('base','labelconditions2');
rats = evalin('base','rats');
fs=1000; %Frequency after downsampling
gui_check_sleep_scoring(channels,label1,labelconditions,labelconditions2,rats,fs);
% --------------------------------------------------------------------
function SWR_detection_Callback(hObject, eventdata, handles)
% hObject handle to SWR_detection (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
beepnoise
pause(.1)
% --------------------------------------------------------------------
function Threshold_plots_Callback(hObject, eventdata, handles)
% hObject handle to Threshold_plots (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
channels = evalin('base','channels');
label1 = evalin('base','label1');
labelconditions = evalin('base','labelconditions');
labelconditions2 = evalin('base','labelconditions2');
rats = evalin('base','rats');
gui_threshold_ripples;
% --------------------------------------------------------------------
% --------------------------------------------------------------------
function THR_select_Callback(hObject, eventdata, handles)
% hObject handle to THR_select (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
channels = evalin('base','channels');
label1 = evalin('base','label1');
labelconditions = evalin('base','labelconditions');
labelconditions2 = evalin('base','labelconditions2');
rats = evalin('base','rats');
gui_thr_selection
% --------------------------------------------------------------------
function Run_SWR_Callback(hObject, eventdata, handles)
% hObject handle to Run_SWR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
channels = evalin('base','channels');
label1 = evalin('base','label1');
labelconditions = evalin('base','labelconditions');
labelconditions2 = evalin('base','labelconditions2');
rats = evalin('base','rats');
gui_swr_test2
% --------------------------------------------------------------------
function Detection_OS_Callback(hObject, eventdata, handles)
% hObject handle to Detection_OS (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
channels = evalin('base','channels');
label1 = evalin('base','label1');
labelconditions = evalin('base','labelconditions');
labelconditions2 = evalin('base','labelconditions2');
rats = evalin('base','rats');
swr_analysis
% --------------------------------------------------------------------
function Sleep_description_Callback(hObject, eventdata, handles)
% hObject handle to Sleep_description (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
beepnoise
pause(.1)
% --------------------------------------------------------------------
function Sleep_amount_Callback(hObject, eventdata, handles)
% hObject handle to Sleep_amount (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
channels = evalin('base','channels');
label1 = evalin('base','label1');
labelconditions = evalin('base','labelconditions');
labelconditions2 = evalin('base','labelconditions2');
rats = evalin('base','rats');
% gui_sleep_amount(channels,label1,labelconditions,labelconditions2,rats);
gui_sleep_amount_2020;
% --------------------------------------------------------------------
function Hypnogram_Callback(hObject, eventdata, handles)
% hObject handle to Hypnogram (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
channels = evalin('base','channels');
label1 = evalin('base','label1');
labelconditions = evalin('base','labelconditions');
labelconditions2 = evalin('base','labelconditions2');
rats = evalin('base','rats');
gui_hypnogram;
% --------------------------------------------------------------------
function Spectral_analysis_Callback(hObject, eventdata, handles)
% hObject handle to Spectral_analysis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
beepnoise
pause(.1)
% --------------------------------------------------------------------
function Periodogram_Callback(hObject, eventdata, handles)
% hObject handle to Periodogram (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
channels = evalin('base','channels');
label1 = evalin('base','label1');
labelconditions = evalin('base','labelconditions');
labelconditions2 = evalin('base','labelconditions2');
rats = evalin('base','rats');
%gui_periodogram(channels,rats,label1,labelconditions,labelconditions2)
% gui_periodogram;
gui_periodogram_2020;
% --------------------------------------------------------------------
function Spectrogram_Callback(hObject, eventdata, handles)
% hObject handle to Spectrogram (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Granger_causality_Callback(hObject, eventdata, handles)
% hObject handle to Granger_causality (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Help_Callback(hObject, eventdata, handles)
% hObject handle to Help (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
beepnoise
pause(.1)
% --------------------------------------------------------------------
function Github_Callback(hObject, eventdata, handles)
% hObject handle to Github (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
url = 'https://github.com/Aleman-Z/CorticoHippocampal/tree/master/GUI';
web(url,'-browser')
% --------------------------------------------------------------------
function MemoryDynamics_Callback(hObject, eventdata, handles)
% hObject handle to MemoryDynamics (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
url = ' http://www.genzellab.com/';
web(url,'-browser')
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
% close all
set(0,'userdata',1)
delete(hObject);
% --- Executes during object deletion, before destroying properties.
function figure1_DeleteFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
|
github
|
Aleman-Z/CorticoHippocampal-master
|
gui_main.m
|
.m
|
CorticoHippocampal-master/GUI/gui_main.m
| 19,659 |
utf_8
|
8a29a785d1558a3774e623ba15e00786
|
function varargout = gui_main(varargin)
% MAR M-file for mar.fig
% MAR, by itself, creates a new MAR or raises the existing
% singleton*.
%
% H = MAR returns the handle to a new MAR or the handle to
% the existing singleton*.
%
% MAR('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAR.M with the given input arguments.
%
% MAR('Property','Value',...) creates a new MAR or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before mar_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to mar_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Copyright 2002-2003 The MathWorks, Inc.
% Copyright (c) 2006-2007 BSMART Group
% by Richard Cui
% $Revision: 0.2$ $Date: 14-Sep-2007 11:11:11$
% SHIS UT-Houston, Houston, TX 77030, USA.
%
% Lei Xu, Hualou Liang
% Edit the above text to modify the response to help mar
% Last Modified by GUIDE v2.5 01-Jun-2019 09:36:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @mar_OpeningFcn, ...
'gui_OutputFcn', @mar_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before mar is made visible.
function mar_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to mar (see VARARGIN)
% Choose default command line output for mar
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% draw bsmart face figures
axes(handles.memdyn) % Select the proper axes
imshow('memdyn.png');
% UIWAIT makes mar wait for user response (see UIRESUME)
% uiwait(handles.bsmart);
% --- Outputs from this function are returned to the command line.
function varargout = mar_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
hToolbar=uitoolbar(... % Toolbar for Open and Print buttons
'Parent',hObject,...
'HandleVisibility','callback');
hOpenPushtool = uipushtool(... %Open toolbar button
'Parent',hToolbar,...
'TooltipString','Open File',...
'CData',iconRead(fullfile(matlabroot,...
'toolbox/matlab/icons/opendoc.mat')),...
'HandleVisibility','callback',...
'ClickedCallback',@Open_menu_Callback);
hPrintPushtool = uipushtool(... % Print toolbar button
'Parent',hToolbar,...
'TooltipString','Print Figure',...
'CData',iconRead(fullfile(matlabroot,...
'toolbox/matlab/icons/printdoc.mat')),...
'HandleVisibility','callback',...
'ClickedCallback',@Print_menu_Callback);
% --------------------------------------------------------------------
function import_data_menu_Callback(hObject, eventdata, handles)
% hObject handle to import_data_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
readdata;
% --------------------------------------------------------------------
function Data_write_menu_Callback(hObject, eventdata, handles)
% hObject handle to Data_write_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
writedata;
% --------------------------------------------------------------------
function Print_menu_Callback(hObject, eventdata, handles)
% hObject handle to Print_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Callback function run when the Print menu item is selected
printdlg();
% --------------------------------------------------------------------
function exitbsmart_Callback(hObject, eventdata, handles) %#ok<DEFNU>
% hObject handle to exitbsmart (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Callback function run when the Close menu item is selected
% close confirmation
% selection=...
% questdlg(['Close ' get(handles.bsmart,'Name') '?'],...
% ['Close ' get(handles.bsmart,'Name') '?'],...
% 'Yes','No','Yes');
% if strcmp(selection,'No')
% return;
% end
delete(handles.gui_main);
% --------------------------------------------------------------------
function aic_Callback(hObject, eventdata, handles)
% hObject handle to aic (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
aic;
% --------------------------------------------------------------------
function FFT_menu_Callback(hObject, eventdata, handles)
% hObject handle to FFT_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
mar_fft;
% --------------------------------------------------------------------
function AMAR_menu_Callback(hObject, eventdata, handles)
% hObject handle to AMAR_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function View_menu_Callback(hObject, eventdata, handles)
% hObject handle to View_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function File_menu_Callback(hObject, eventdata, handles)
% hObject handle to File_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Edit_menu_Callback(hObject, eventdata, handles)
% hObject handle to Edit_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Tools_menu_Callback(hObject, eventdata, handles)
% hObject handle to Tools_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Plot_menu_Callback(hObject, eventdata, handles)
% hObject handle to Plot_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Help_menu_Callback(hObject, eventdata, handles)
% hObject handle to Help_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function whiteness_Callback(hObject, eventdata, handles)
% hObject handle to whiteness (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
whiteness;
% --------------------------------------------------------------------
function consist_Callback(hObject, eventdata, handles)
% hObject handle to consist (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
consistency_test;
% --------------------------------------------------------------------
function Lyapunov_Callback(hObject, eventdata, handles)
% hObject handle to Lyapunov (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Lyapunov;
% --------------------------------------------------------------------
function whole_Callback(hObject, eventdata, handles)
% hObject handle to whole (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
one_window;
% --------------------------------------------------------------------
function moving_Callback(hObject, eventdata, handles)
% hObject handle to moving (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
moving_window;
% --------------------------------------------------------------------
function analysis_Callback(hObject, eventdata, handles)
% hObject handle to analysis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function spectrum_Callback(hObject, eventdata, handles)
% hObject handle to spectrum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
spectrum_analysis;
% --------------------------------------------------------------------
function coherence_Callback(hObject, eventdata, handles)
% hObject handle to coherence (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
coherence;
% --------------------------------------------------------------------
function granger_causality_Callback(hObject, eventdata, handles)
% hObject handle to granger_causality (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%granger_causality;
% --------------------------------------------------------------------
function Grid_View_Callback(hObject, eventdata, handles)
% hObject handle to Grid_View (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Topo_Plotview_Callback(hObject, eventdata, handles)
% hObject handle to Topo_Plotview (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Synoptic_Plotview_Callback(hObject, eventdata, handles)
% hObject handle to Synoptic_Plotview (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Topo_Mapview_Callback(hObject, eventdata, handles)
% hObject handle to Topo_Mapview (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function view_Callback(hObject, eventdata, handles)
% hObject handle to view (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
dataview;
% --------------------------------------------------------------------
function coherence_network_Callback(hObject, eventdata, handles)
% hObject handle to coherence_network (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
coherence_network;
% --------------------------------------------------------------------
function granger_causality_network_Callback(hObject, eventdata, handles)
% hObject handle to granger_causality_network (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
granger_causality_network;
function whole_pairwise_Callback(hObject, eventdata, handles)
% hObject handle to whole_pairwise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
one_window_pariwise;
% --------------------------------------------------------------------
function moving_window_pairwise_Callback(hObject, eventdata, handles)
% hObject handle to moving_window_pairwise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
moving_window_pairwise;
% --------------------------------------------------------------------
function coherence_view_Callback(hObject, eventdata, handles)
% hObject handle to coherence_view (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
coherence_view;
% --------------------------------------------------------------------
function granger_causality_view_Callback(hObject, eventdata, handles)
% hObject handle to granger_causality_view (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
granger_causality_view
% --------------------------------------------------------------------
function power_view_Callback(hObject, eventdata, handles)
% hObject handle to power_view (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
power_view;
% --------------------------------------------------------------------
function Preprocessing_Callback(hObject, eventdata, handles)
% hObject handle to Preprocessing (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
preprocessing;
% --------------------------------------------------------------------
function power_mul_Callback(hObject, eventdata, handles)
% hObject handle to power_mul (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
spectrum_analysis;
% --------------------------------------------------------------------
function power_bi_Callback(hObject, eventdata, handles)
% hObject handle to power_bi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
power_pairwise
% --------------------------------------------------------------------
function Coherence_mul_Callback(hObject, eventdata, handles)
% hObject handle to Coherence_mul (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
coherence;
% --------------------------------------------------------------------
function Granger_mul_Callback(hObject, eventdata, handles)
% hObject handle to Granger_mul (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Granger_bi_Callback(hObject, eventdata, handles)
% hObject handle to Granger_bi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Coherence_bi_Callback(hObject, eventdata, handles)
% hObject handle to Coherence_bi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pairwise_coherence;
% --------------------------------------------------------------------
function GC_bi_Callback(hObject, eventdata, handles)
% hObject handle to GC_bi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pairwise_granger_causality;
% --------------------------------------------------------------------
function gr_Callback(hObject, eventdata, handles)
% hObject handle to gr (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function test_Callback(hObject, eventdata, handles)
% hObject handle to test (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function about_bsmart_Callback(hObject, eventdata, handles)
% hObject handle to about_bsmart (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
msgstr = sprintf('BSMART ver 0.5 build 102\n2006 - 2007 BSMART Goup\n(Under construction)');
msgbox(msgstr,'About BSMART','help');
% --------------------------------------------------------------------
function user_manual_Callback(hObject, eventdata, handles)
% hObject handle to user_manual (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ispc
open('Users_guide.pdf');
else
msgbox('Please read Users_guide.PDF (under construction)','How to use BSMART','help');
end%if
% --------------------------------------------------------------------
function fun_ref_Callback(hObject, eventdata, handles)
% hObject handle to fun_ref (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ispc
open('Function_reference.pdf');
else
msgbox('Please read Function_reference.PDF','Function Reference','help');
end%if
% --- Executes during object creation, after setting all properties.
function memdyn_CreateFcn(hObject, eventdata, handles)
% hObject handle to memdyn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate memdyn
|
github
|
Aleman-Z/CorticoHippocampal-master
|
gui_new_experiment.m
|
.m
|
CorticoHippocampal-master/GUI/gui_new_experiment.m
| 8,488 |
utf_8
|
27b4d457a5ad8c4722899fc41d98d0b0
|
function varargout = gui_new_experiment(varargin)
% GUI_NEW_EXPERIMENT MATLAB code for gui_new_experiment.fig
% GUI_NEW_EXPERIMENT, by itself, creates a new GUI_NEW_EXPERIMENT or raises the existing
% singleton*.
%
% H = GUI_NEW_EXPERIMENT returns the handle to a new GUI_NEW_EXPERIMENT or the handle to
% the existing singleton*.
%
% GUI_NEW_EXPERIMENT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_NEW_EXPERIMENT.M with the given input arguments.
%
% GUI_NEW_EXPERIMENT('Property','Value',...) creates a new GUI_NEW_EXPERIMENT or raises
% the existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_new_experiment_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_new_experiment_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help gui_new_experiment
% Last Modified by GUIDE v2.5 19-Jun-2019 23:09:02
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_new_experiment_OpeningFcn, ...
'gui_OutputFcn', @gui_new_experiment_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before gui_new_experiment is made visible.
function gui_new_experiment_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to gui_new_experiment (see VARARGIN)
% Choose default command line output for gui_new_experiment
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
initialize_gui(hObject, handles, false);
% UIWAIT makes gui_new_experiment wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_new_experiment_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.
function density_CreateFcn(hObject, eventdata, handles)
% hObject handle to density (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function density_Callback(hObject, eventdata, handles)
% hObject handle to density (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of density as text
% str2double(get(hObject,'String')) returns contents of density as a double
density = str2double(get(hObject, 'String'));
if isnan(density)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
% Save the new density value
handles.metricdata.density = density;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function volume_CreateFcn(hObject, eventdata, handles)
% hObject handle to volume (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function volume_Callback(hObject, eventdata, handles)
% hObject handle to volume (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of volume as text
% str2double(get(hObject,'String')) returns contents of volume as a double
volume = str2double(get(hObject, 'String'));
if isnan(volume)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
% Save the new volume value
handles.metricdata.volume = volume;
guidata(hObject,handles)
% --- Executes on button press in calculate.
function calculate_Callback(hObject, eventdata, handles)
% hObject handle to calculate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
mass = handles.metricdata.density * handles.metricdata.volume;
set(handles.mass, 'String', mass);
% --- Executes on button press in reset.
function reset_Callback(hObject, eventdata, handles)
% hObject handle to reset (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
initialize_gui(gcbf, handles, true);
% --- Executes when selected object changed in unitgroup.
function unitgroup_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object in unitgroup
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (hObject == handles.english)
set(handles.text4, 'String', 'lb/cu.in');
set(handles.text5, 'String', 'cu.in');
set(handles.text6, 'String', 'lb');
else
set(handles.text4, 'String', 'kg/cu.m');
set(handles.text5, 'String', 'cu.m');
set(handles.text6, 'String', 'kg');
end
% --------------------------------------------------------------------
function initialize_gui(fig_handle, handles, isreset)
% If the metricdata field is present and the reset flag is false, it means
% we are we are just re-initializing a GUI by calling it from the cmd line
% while it is up. So, bail out as we dont want to reset the data.
if isfield(handles, 'metricdata') && ~isreset
return;
end
handles.metricdata.density = 0;
handles.metricdata.volume = 0;
set(handles.density, 'String', handles.metricdata.density);
set(handles.volume, 'String', handles.metricdata.volume);
set(handles.mass, 'String', 0);
set(handles.unitgroup, 'SelectedObject', handles.english);
set(handles.text4, 'String', 'lb/cu.in');
set(handles.text5, 'String', 'cu.in');
set(handles.text6, 'String', 'lb');
% Update handles structure
guidata(handles.figure1, handles);
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
baseline_norm.m
|
.m
|
CorticoHippocampal-master/Spectral_Normalization/baseline_norm.m
| 393 |
utf_8
|
2ce407f3cf9d5ad7bdce9da53b179f67
|
function [achis]=baseline_norm(freq1,w)
%%Average trials
TF=freq1.powspctrm;
TF=squeeze(mean(TF,1));
TF=squeeze(TF(w,:,:));
TFt=freq1.time;
tind=([-1 -0.5]);
% ind1=find(TFt==tind(1));
% ind2=find(TFt==tind(2));
ind1=find((ismembertol(TFt,tind(1))));
ind2=find((ismembertol(TFt,tind(2))));
FF=mean(squeeze(TF(:,ind1:ind2)),2); %baseline
achis=10*log10( bsxfun(@rdivide, TF, FF) );
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
select_trial.m
|
.m
|
CorticoHippocampal-master/Object space task/select_trial.m
| 775 |
utf_8
|
4a10d338bc79493b2fc6f0dcbd1a2d56
|
function [A,str2]=select_trial(str,Rat)
% A = dir(cd);
% A={A.name};
A=getfolder;
aver=cellfun(@(x) strfind(x,str),A,'UniformOutput',false);
aver=cellfun(@(x) length(x),aver,'UniformOutput',false);
aver=cell2mat(aver);
A=A(find(aver));
A=A.';
% %% Removes the PNG files.
% str='PNG';
% % B = dir(cd);
% % B={B.name};
% B=getfolder;
% aver=cellfun(@(x) strfind(x,str),B,'UniformOutput',false);
% aver=cellfun(@(x) length(x),aver,'UniformOutput',false);
% aver=cell2mat(aver);
% B=B(find(aver));
%
% B=B.';
% %%
% [C,ia,ib] = intersect(A,B, 'stable');
% l=1:length(A);
% ll= l(l~=ia);
% A=A(ll,1);
%%
str2=cell(size(A,1),1);
for n=1:size(A,1)
% str2{n,1}=strcat('F:\Lisa_files\',num2str(Rat),'\PT',num2str(n));
str2{n,1}=strcat('PT',num2str(n));
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
data_lisa.m
|
.m
|
CorticoHippocampal-master/Object space task/data_lisa.m
| 4,059 |
utf_8
|
ff89275104728a49771271c18cfab5b9
|
%%
function data_lisa(num,acer)
str1=cell(5,1);
if acer==0
str1{1,1}='/media/raleman/My Book/ObjectSpace/rat_1/study_day_2_OR/post_trial1_2017-09-25_11-26-43';
str1{2,1}='/media/raleman/My Book/ObjectSpace/rat_1/study_day_2_OR/post_trial2_2017-09-25_12-17-49';
str1{3,1}='/media/raleman/My Book/ObjectSpace/rat_1/study_day_2_OR/post_trial3_2017-09-25_13-08-52';
str1{4,1}='/media/raleman/My Book/ObjectSpace/rat_1/study_day_2_OR/post_trial4_2017-09-25_14-01-00';
str1{5,1}='/media/raleman/My Book/ObjectSpace/rat_1/study_day_2_OR/post_trial5_2017-09-25_14-52-04';
%str1{6,1}='/media/raleman/My Book/ObjectSpace/rat_1/study_day_2_OR/post_trial6_2017-09-26_11-10-21';
str2=cell(5,1);
str2{1,1}='/home/raleman/Documents/internship/Lisa_files/data/PT1';
str2{2,1}='/home/raleman/Documents/internship/Lisa_files/data/PT2';
str2{3,1}='/home/raleman/Documents/internship/Lisa_files/data/PT3';
str2{4,1}='/home/raleman/Documents/internship/Lisa_files/data/PT4';
str2{5,1}='/home/raleman/Documents/internship/Lisa_files/data/PT5';
%str2{6,1}='/home/raleman/Documents/internship/Lisa_files/data/PT6';
else
str1{1,1}='F:/ephys/rat1/study_day_2_OR/post_trial1_2017-09-25_11-26-43';
str1{2,1}='F:/ephys/rat1/study_day_2_OR/post_trial2_2017-09-25_12-17-49';
str1{3,1}='F:/ephys/rat1/study_day_2_OR/post_trial3_2017-09-25_13-08-52';
str1{4,1}='F:/ephys/rat1/study_day_2_OR/post_trial4_2017-09-25_14-01-00';
str1{5,1}='F:/ephys/rat1/study_day_2_OR/post_trial5_2017-09-25_14-52-04';
%str1{6,1}='F:/ObjectSpace/rat_1/study_day_2_OR/post_trial6_2017-09-26_11-10-21';
str2=cell(5,1);
str2{1,1}='F:/Lisa_files/data/PT1';
str2{2,1}='F:/Lisa_files/data/PT2';
str2{3,1}='F:/Lisa_files/data/PT3';
str2{4,1}='F:/Lisa_files/data/PT4';
str2{5,1}='F:/Lisa_files/data/PT5';
%str2{6,1}='G:/Lisa_files/data/PT6';
end
% cd('/media/raleman/My Book/ObjectSpace/rat_1/study_day_2_OR/post_trial1_2017-09-25_11-26-43');
cd(str1{num,1});
fs=20000;
[data9m, ~, ~] = load_open_ephys_data_faster('100_CH14.continuous');
% if num==5
% st=30*(60)*(fs);
% dat=cell(6,1);
% dat{1,1}=data9m(1:st);
% dat{2,1}=data9m(st+1:2*st);
% dat{3,1}=data9m(2*st+1:3*st);
% dat{4,1}=data9m(3*st+1:4*st);
% dat{5,1}=data9m(4*st+1:5*st);
% dat{6,1}=data9m(5*st+1:end);
% clear data9m
% end
% save('dat.mat','dat')
[data17m, ~, ~] = load_open_ephys_data_faster('100_CH46.continuous');
% if num==5
% st=30*(60)*(fs);
% dat2=cell(6,1);
% dat2{1,1}=data17m(1:st);
% dat2{2,1}=data17m(st+1:2*st);
% dat2{3,1}=data17m(2*st+1:3*st);
% dat2{4,1}=data17m(3*st+1:4*st);
% dat2{5,1}=data17m(4*st+1:5*st);
% dat2{6,1}=data17m(5*st+1:end);
% clear data17m
% end
%
% save('dat2.mat','dat2')
% Loading accelerometer data
[ax1, ~, ~] = load_open_ephys_data_faster('100_AUX1.continuous');
[ax2, ~, ~] = load_open_ephys_data_faster('100_AUX2.continuous');
[ax3, ~, ~] = load_open_ephys_data_faster('100_AUX3.continuous');
% Verifying time
l=length(ax1); %samples
% t=l*(1/fs); % 2.7276e+03 seconds
% Equivalent to 45.4596 minutes
t=1:l;
t=t*(1/fs);
sos=ax1.^2+ax2.^2+ax3.^2;
clear ax1 ax2 ax3
% close all
%[vtr]=findsleep(sos,0.006,t); %post_trial2
[vtr]=findsleep(sos,0.006,t); %post_trial3
vin=find(vtr~=1);
%tvin=vin*(1/fs);
C9=data9m(vin).*(0.195);
C17=data17m(vin).*(0.195);
clear data17m data9m
cd(str2{num,1});
% cd('/home/raleman/Documents/internship/Lisa_files/data/PT1')
save('C9.mat','C9')
save('C17.mat','C17')
clear all
end
% %
% st=30*(60)*(fs);
% C17m=cell(6,1);
% C17m{1,1}=C17(1:st);
% C17m{2,1}=C17(st+1:2*st);
% C17m{3,1}=C17(2*st+1:3*st);
% C17m{4,1}=C17(3*st+1:4*st);
% C17m{5,1}=C17(4*st+1:5*st);
% C17m{6,1}=C17(5*st+1:end);
%
% %%
% st=30*(60)*(fs);
% C9m=cell(6,1);
% C9m{1,1}=C9(1:st);
% C9m{2,1}=C9(st+1:2*st);
% C9m{3,1}=C9(2*st+1:3*st);
% C9m{4,1}=C9(3*st+1:4*st);
% C9m{5,1}=C9(4*st+1:5*st);
% C9m{6,1}=C9(5*st+1:end);
%
|
github
|
Aleman-Z/CorticoHippocampal-master
|
meth_selection.m
|
.m
|
CorticoHippocampal-master/Ripple_selection/meth_selection.m
| 4,073 |
utf_8
|
713c17f3c898ce7006eb2d73d7527aae
|
%Methods of ripples selection
function [sig1,sig2,ripple,cara,veamos,RipFreq2,timeasleep,ti,vec_nrem, vec_trans ,vec_rem,vec_wake,labels,transitions,transitions2,ripples_times,riptable,chtm,CHTM]=meth_selection(meth,level,notch,Rat,datapath,nFF,acer,iii,w,rat26session3,base,rat27session3)
switch meth
case 1
[sig1,sig2,ripple,cara,veamos,CHTM,RipFreq2,timeasleep]=newest_only_ripple_level_ERASETHIS(level);
case 2
[sig1,sig2,ripple,cara,veamos,CHTM,RipFreq2,timeasleep]=median_std;
case 3
chtm=load('vq_loop2.mat');
chtm=chtm.vq;
[sig1,sig2,ripple,cara,veamos,RipFreq2,timeasleep,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM=[chtm chtm];
case 4
%Find threshold on Baseline which gives 2000 ripples during the whole NREM.
if acer==0
cd(strcat('/home/adrian/Documents/downsampled_NREM_data/',num2str(Rat)))
else
cd(strcat(datapath,'/',num2str(Rat)))
end
cd(nFF{1}) %Baseline
[timeasleep]=find_thr_base;
ror=2000/timeasleep; %2000 Ripples during whole NREM sleep.
%Find thresholds vs ripple freq plot.
if acer==0
cd(strcat('/home/adrian/Dropbox/Figures/Figure2/',num2str(Rat)))
else
%cd(strcat('C:\Users\Welt Meister\Dropbox\Figures\Figure2\',num2str(Rat)))
cd(strcat('C:\Users\addri\Dropbox\Figures\Figure2\',num2str(Rat)))
end
if Rat==26 || Rat==24
Base=[{'Baseline1'} {'Baseline2'}];
end
if Rat==26 && rat26session3==1
Base=[{'Baseline3'} {'Baseline2'}];
end
if Rat==27
Base=[{'Baseline2'} {'Baseline1'}];% We run Baseline 2 first, cause it is the one we prefer.
end
if Rat==27 && rat27session3==1
Base=[{'Baseline2'} {'Baseline3'}];% We run Baseline 2 first, cause it is the one we prefer.
end
%openfig('Ripples_per_condition_best.fig')
h=openfig(strcat('Ripples_per_condition_',Base{base},'.fig'))
%h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes
ydata=dataObjs{2}(8).YData;
xdata=dataObjs{2}(8).XData;
chtm = interp1(ydata,xdata,ror); %Interpolate for value ror.
close(h)
%xo
if acer==0
cd(strcat('/home/adrian/Documents/downsampled_NREM_data/',num2str(Rat)))
else
cd(strcat(datapath,'/',num2str(Rat)))
end
cd(nFF{iii})
w='HPC';
[sig1,sig2,ripple,cara,veamos,RipFreq2,timeasleep,ti,vec_nrem, vec_trans ,vec_rem,vec_wake,labels,transitions,transitions2,ripples_times]=nrem_fixed_thr_Vfiles(chtm,notch,w);
CHTM=[chtm chtm]; %Threshold
%Fill table with ripple information.
riptable(iii,1)=ripple; %Number of ripples.
riptable(iii,2)=timeasleep;
riptable(iii,3)=RipFreq2;
case 5
% if Rat~=24
chtm=20;
% chtm=25;
% else
% chtm=35;
% end
% chtm=10;
if acer==0
cd(strcat('/home/adrian/Documents/downsampled_NREM_data/',num2str(Rat)))
else
cd(strcat(datapath,'/',num2str(Rat)))
end
cd(nFF{iii})
[sig1,sig2,ripple,cara,veamos,RipFreq2,timeasleep,ti,vec_nrem, vec_trans ,vec_rem,vec_wake,labels,transitions,transitions2,ripples_times]=nrem_fixed_thr_Vfiles(chtm,notch,w);
CHTM=[chtm chtm]; %Threshold
%Fill table with ripple information.
riptable(iii,1)=ripple; %Number of ripples.
riptable(iii,2)=timeasleep;
riptable(iii,3)=RipFreq2;
% continue
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
stats_between_cfc.m
|
.m
|
CorticoHippocampal-master/Cross_Frequency/stats_between_cfc.m
| 1,242 |
utf_8
|
f0e7c07e9634a2f0fb7324193ed00590
|
%%
function [stats]=stats_between_cfc(freq1,freq2,label1,w)
cfg = [];
cfg.latency = [30 100]; % time of interest (exclude baseline: it doesn't make sense to compute statistics on a region we expect to be zero)
cfg.method = 'montecarlo';
cfg.statistic = 'ft_statfun_indepsamplesT';
cfg.correctm = 'cluster';
%cfg.channel = 'chan0'; % only one channel at the time, you should correct the p-value for the number of channels
cfg.channel = label1{2*w-1}; % only one channel at the time, you should correct the p-value for the number of channels
cfg.alpha = 0.05 / length(freq1.label);
cfg.correcttail = 'prob';
cfg.numrandomization = 500; % this value won't change the statistics. Use a higher value to have a more accurate p-value
% design = zeros(2, n_trl * 2);
% design(1, 1:n_trl) = 1;
% design(1, n_trl+1:end) = 2;
% design(2, :) = [1:n_trl 1:n_trl];
design = zeros(1,size(freq1.powspctrm,1) + size(freq2.powspctrm,1));
design(1,1:size(freq1.powspctrm,1)) = 1;
design(1,(size(freq1.powspctrm,1)+1):(size(freq1.powspctrm,1)+...
size(freq1.powspctrm,1))) = 2;
cfg.design = design;
cfg.ivar = 1;
% cfg.uvar = 2;
stats = ft_freqstatistics(cfg, freq2, freq1);
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
ft_crossfrequencyanalysis.m
|
.m
|
CorticoHippocampal-master/Cross_Frequency/ft_crossfrequencyanalysis.m
| 12,538 |
utf_8
|
a1943ecc311520e5d729a7ae47f380db
|
function crossfreq = ft_crossfrequencyanalysis(cfg, freqlow, freqhigh)
% FT_CROSSFREQUENCYANALYSIS performs cross-frequency analysis
%
% Use as
% crossfreq = ft_crossfrequencyanalysis(cfg, freq)
% crossfreq = ft_crossfrequencyanalysis(cfg, freqlo, freqhi)
%
% The input data should be organised in a structure as obtained from the
% FT_FREQANALYSIS function. The configuration should be according to
%
% cfg.freqlow = scalar or vector, selection of frequencies for the low frequency data
% cfg.freqhigh = scalar or vector, selection of frequencies for the high frequency data
% cfg.channel = cell-array with selection of channels, see FT_CHANNELSELECTION
% cfg.method = string, can be
% 'coh' - coherence
% 'plv' - phase locking value
% 'mvl' - mean vector length
% 'mi' - modulation index
% cfg.keeptrials = string, can be 'yes' or 'no'
%
% Various metrics for cross-frequency coupling have been introduced in a number of
% scientific publications, but these do not use a sonsistent method naming scheme,
% nor implement it in exactly the same way. The particular implementation in this
% code tries to follow the most common format, generalizing where possible. If you
% want details about the algorithms, please look into the code.
%
% The modulation index implements
% Tort A. B. L., Komorowski R., Eichenbaum H., Kopell N. (2010). Measuring Phase-Amplitude
% Coupling Between Neuronal Oscillations of Different Frequencies. J Neurophysiol 104:
% 1195?1210. doi:10.1152/jn.00106.2010
%
% See also FT_FREQANALYSIS, FT_CONNECTIVITYANALYSIS
% Copyright (C) 2014-2017, Donders Centre for Cognitive Neuroimaging
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
% FieldTrip is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% FieldTrip is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id$
% these are used by the ft_preamble/ft_postamble function and scripts
ft_revision = '$Id$';
ft_nargin = nargin;
ft_nargout = nargout;
% do the general setup of the function
ft_defaults
ft_preamble init
ft_preamble debug
ft_preamble loadvar freqlow freqhigh
ft_preamble provenance freqlow freqhi
ft_preamble trackconfig
% the ft_abort variable is set to true or false in ft_preamble_init
if ft_abort
% do not continue function execution in case the outputfile is present and the user indicated to keep it
return
end
if nargin<3
% use the same data for the low and high frequencies
freqhigh = freqlow;
end
% ensure that the input data is valid for this function, this will also do
% backward-compatibility conversions of old data that for example was read from
% an old *.mat file
freqlow = ft_checkdata(freqlow, 'datatype', 'freq', 'feedback', 'yes');
freqhigh = ft_checkdata(freqhigh, 'datatype', 'freq', 'feedback', 'yes');
% prior to 19 Jan 2017 this function had input options cfg.chanlow and cfg.chanhigh,
% but nevertheless did not support between-channel CFC computations
cfg = ft_checkconfig(cfg, 'forbidden', {'chanlow', 'chanhigh'});
cfg.channel = ft_getopt(cfg, 'channel', 'all');
cfg.freqlow = ft_getopt(cfg, 'freqlow', 'all');
cfg.freqhigh = ft_getopt(cfg, 'freqhigh', 'all');
cfg.keeptrials = ft_getopt(cfg, 'keeptrials');
% ensure that we are working on the intersection of the channels
cfg.channel = ft_channelselection(cfg.channel, intersect(freqlow.label, freqhigh.label));
% make selection of frequencies and channels
tmpcfg = [];
tmpcfg.channel = cfg.channel;
tmpcfg.frequency = cfg.freqlow;
freqlow = ft_selectdata(tmpcfg, freqlow);
[tmpcfg, freqlow] = rollback_provenance(cfg, freqlow);
try, cfg.channel = tmpcfg.channel; end
try, cfg.freqlow = tmpcfg.frequency; end
% make selection of frequencies and channels
tmpcfg = [];
tmpcfg.channel = cfg.channel;
tmpcfg.frequency = cfg.freqhigh;
freqhigh = ft_selectdata(tmpcfg, freqhigh);
[tmpcfg, freqhigh] = rollback_provenance(cfg, freqhigh);
try, cfg.channel = tmpcfg.channel; end
try, cfg.freqhigh = tmpcfg.frequency; end
LF = freqlow.freq;
HF = freqhigh.freq;
ntrial = size(freqlow.fourierspctrm,1); % FIXME the dimord might be different
nchan = size(freqlow.fourierspctrm,2); % FIXME the dimord might be different
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% prepare the data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch cfg.method
case 'coh'
% coherence
cohdatas = zeros(ntrial,nchan,numel(LF),numel(HF)) ;
for i =1:nchan
chandataLF = freqlow.fourierspctrm(:,i,:,:);
chandataHF = freqhigh.fourierspctrm(:,i,:,:);
for j = 1:ntrial
cohdatas(j,i,:,:) = data2coh(squeeze(chandataLF(j,:,:,:)),squeeze(chandataHF(j,:,:,:)));
end
end
cfcdata = cohdatas;
case 'plv'
% phase locking value
plvdatas = zeros(ntrial,nchan,numel(LF),numel(HF)) ;
for i =1:nchan
chandataLF = freqlow.fourierspctrm(:,i,:,:);
chandataHF = freqhigh.fourierspctrm(:,i,:,:);
for j = 1:ntrial
plvdatas(j,i,:,:) = data2plv(squeeze(chandataLF(j,:,:,:)),squeeze(chandataHF(j,:,:,:)));
end
end
cfcdata = plvdatas;
case 'mvl'
% mean vector length
mvldatas = zeros(ntrial,nchan,numel(LF),numel(HF));
for i =1:nchan
chandataLF = freqlow.fourierspctrm(:,i,:,:);
chandataHF = freqhigh.fourierspctrm(:,i,:,:);
for j = 1:ntrial
mvldatas(j,i,:,:) = data2mvl(squeeze(chandataLF(j,:,:,:)),squeeze(chandataHF(j,:,:,:)));
end
end
cfcdata = mvldatas;
case 'mi'
% modulation index
nbin = 20; % number of phase bin
pacdatas = zeros(ntrial,nchan,numel(LF),numel(HF),nbin) ;
for i =1:nchan
chandataLF = freqlow.fourierspctrm(:,i,:,:);
chandataHF = freqhigh.fourierspctrm(:,i,:,:);
for j = 1:ntrial
pacdatas(j,i,:,:,:) = data2pac(squeeze(chandataLF(j,:,:,:)),squeeze(chandataHF(j,:,:,:)),nbin);
end
end
cfcdata = pacdatas;
end % switch method for data preparation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% do the actual computation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch cfg.method
case 'coh'
[ntrial,nchan,nlf,nhf] = size(cfcdata);
if strcmp(cfg.keeptrials, 'no')
crsspctrm = reshape(abs(mean(cfcdata,1)), [nchan, nlf, nhf]);
dimord = 'chan_freqlow_freqhigh' ;
else
crsspctrm = abs(cfcdata);
dimord = 'rpt_chan_freqlow_freqhigh' ;
end
case 'plv'
[ntrial,nchan,nlf,nhf] = size(cfcdata);
if strcmp(cfg.keeptrials, 'no')
crsspctrm = reshape(abs(mean(cfcdata,1)), [nchan, nlf, nhf]);
dimord = 'chan_freqlow_freqhigh' ;
else
crsspctrm = abs(cfcdata);
dimord = 'rpt_chan_freqlow_freqhigh' ;
end
case 'mvl'
[ntrial,nchan,nlf,nhf] = size(cfcdata);
if strcmp(cfg.keeptrials, 'no')
crsspctrm = reshape(abs(mean(cfcdata,1)), [nchan, nlf, nhf]);
dimord = 'chan_freqlow_freqhigh' ;
else
crsspctrm = abs(cfcdata);
dimord = 'rpt_chan_freqlow_freqhigh' ;
end
case 'mi'
[ntrial,nchan,nlf,nhf,nbin] = size(cfcdata);
if strcmp(cfg.keeptrials, 'yes')
dimord = 'rpt_chan_freqlow_freqhigh' ;
crsspctrm = zeros(ntrial,nchan,nlf,nhf);
for k =1:ntrial
for n=1:nchan
pac = squeeze(cfcdata(k,n,:,:,:));
Q =ones(nbin,1)/nbin; % uniform distribution
mi = zeros(nlf,nhf);
for i=1:nlf
for j=1:nhf
P = squeeze(pac(i,j,:))/ nansum(pac(i,j,:)); % normalized distribution
% KL distance
mi(i,j) = nansum(P.* log2(P./Q))./log2(nbin);
end
end
crsspctrm(k,n,:,:) = mi;
end
end
else
dimord = 'chan_freqlow_freqhigh' ;
crsspctrm = zeros(nchan,nlf,nhf);
cfcdatamean = squeeze(mean(cfcdata,1));
for k =1:nchan
pac = squeeze(cfcdatamean(k,:,:,:));
Q =ones(nbin,1)/nbin; % uniform distribution
mi = zeros(nlf,nhf);
for i=1:nlf
for j=1:nhf
P = squeeze(pac(i,j,:))/ nansum(pac(i,j,:)); % normalized distribution
% KL distance
mi(i,j) = nansum(P.* log2(P./Q))./log2(nbin);
end
end
crsspctrm(k,:,:) = mi;
end
end % if keeptrials
end % switch method for actual computation
crossfreq.label = cfg.channel;
crossfreq.crsspctrm = crsspctrm;
crossfreq.dimord = dimord;
crossfreq.freqlow = LF;
crossfreq.freqhigh = HF;
ft_postamble debug
ft_postamble trackconfig
ft_postamble previous freqlow freqhigh
ft_postamble provenance crossfreq
ft_postamble history crossfreq
ft_postamble savevar crossfreq
end % function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUBFUNCTION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [cohdata] = data2coh(LFsigtemp,HFsigtemp)
HFamp = abs(HFsigtemp);
HFamp(isnan(HFamp(:))) = 0; % replace nan with 0
HFphas = angle(hilbert(HFamp'))';
HFsig = HFamp .* exp(sqrt(-1)*HFphas);
LFsig = LFsigtemp;
LFsig(isnan(LFsig(:))) = 0; % replace nan with 0
cohdata = zeros(size(LFsig,1),size(HFsig,1));
for i = 1:size(LFsig,1)
for j = 1:size(HFsig,1)
Nx = sum(~isnan(LFsigtemp(i,:) .* LFsigtemp(i,:)));
Ny = sum(~isnan(HFsigtemp(j,:) .* HFsigtemp(j,:)));
Nxy = sum(~isnan(LFsigtemp(i,:) .* HFsigtemp(j,:)));
Px = LFsig(i,:) * ctranspose(LFsig(i,:)) ./ Nx;
Py = HFsig(j,:) * ctranspose(HFsig(j,:)) ./ Ny;
Cxy = LFsig(i,:) * ctranspose(HFsig(j,:)) ./ Nxy;
cohdata(i,j) = Cxy / sqrt(Px * Py);
end
end
end % function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUBFUNCTION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [plvdata] = data2plv(LFsigtemp,HFsigtemp)
LFphas = angle(LFsigtemp);
HFamp = abs(HFsigtemp);
HFamp(isnan(HFamp(:))) = 0; % replace nan with 0
HFphas = angle(hilbert(HFamp'))';
plvdata = zeros(size(LFsigtemp,1),size(HFsigtemp,1)); % phase locking value
for i = 1:size(LFsigtemp,1)
for j = 1:size(HFsigtemp,1)
plvdata(i,j) = nanmean(exp(1i*(LFphas(i,:)-HFphas(j,:))));
end
end
end % function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUBFUNCTION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [mvldata] = data2mvl(LFsigtemp,HFsigtemp)
% calculate mean vector length (complex value) per trial
% mvldata dim: LF*HF
LFphas = angle(LFsigtemp);
HFamp = abs(HFsigtemp);
mvldata = zeros(size(LFsigtemp,1),size(HFsigtemp,1)); % mean vector length
for i = 1:size(LFsigtemp,1)
for j = 1:size(HFsigtemp,1)
mvldata(i,j) = nanmean(HFamp(j,:).*exp(1i*LFphas(i,:)));
end
end
end % function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUBFUNCTION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function pacdata = data2pac(LFsigtemp,HFsigtemp,nbin)
% calculate phase amplitude distribution per trial
% pacdata dim: LF*HF*Phasebin
pacdata = zeros(size(LFsigtemp,1),size(HFsigtemp,1),nbin);
Ang = angle(LFsigtemp);
Amp = abs(HFsigtemp);
[dum,bin] = histc(Ang, linspace(-pi,pi,nbin)); % binned low frequency phase
binamp = zeros (size(HFsigtemp,1),nbin); % binned amplitude
for i = 1:size(Ang,1)
for k = 1:nbin
idx = (bin(i,:)==k);
binamp(:,k) = mean(Amp(:,idx),2);
end
pacdata(i,:,:) = binamp;
end
end % function
|
github
|
Aleman-Z/CorticoHippocampal-master
|
pac.m
|
.m
|
CorticoHippocampal-master/Cross_Frequency/pac.m
| 14,805 |
utf_8
|
28fe5502609bbcb542fc4e92c8d503a1
|
% pac() - compute phase-amplitude coupling (power of first input
% correlation with phase of second). There is no graphical output
% to this function.
%
% Usage:
% >> pac(x,y,srate);
% >> [coh,timesout,freqsout1,freqsout2,cohboot] ...
% = pac(x,y,srate,'key1', 'val1', 'key2', val2' ...);
% Inputs:
% x = [float array] 2-D data array of size (times,trials) or
% 3-D (1,times,trials)
% y = [float array] 2-D or 3-d data array
% srate = data sampling rate (Hz)
%
% Most important optional inputs
% 'method' = ['mod'|'corrsin'|'corrcos'|'latphase'] modulation
% method or correlation of amplitude with sine or cosine of
% angle (see ref). 'laphase' compute the phase
% histogram at a specific time and requires the
% 'powerlat' option to be set.
% 'freqs' = [min max] frequency limits. Default [minfreq 50],
% minfreq being determined by the number of data points,
% cycles and sampling frequency. Use 0 for minimum frequency
% to compute default minfreq. You may also enter an
% array of frequencies for the spectral decomposition
% (for FFT, closest computed frequency will be returned; use
% 'padratio' to change FFT freq. resolution).
% 'freqs2' = [float array] array of frequencies for the second
% argument. 'freqs' is used for the first argument.
% By default it is the same as 'freqs'.
% 'wavelet' = 0 -> Use FFTs (with constant window length) { Default }
% = >0 -> Number of cycles in each analysis wavelet
% = [cycles expfactor] -> if 0 < expfactor < 1, the number
% of wavelet cycles expands with frequency from cycles
% If expfactor = 1, no expansion; if = 0, constant
% window length (as in FFT) {default wavelet: 0}
% = [cycles array] -> cycle for each frequency. Size of array
% must be the same as the number of frequencies
% {default cycles: 0}
% 'wavelet2' = same as 'wavelet' for the second argument. Default is
% same as cycles. Note that if the lowest frequency for X
% and Y are different and cycle is [cycles expfactor], it
% may result in discrepencies in the number of cycles at
% the same frequencies for X and Y.
% 'ntimesout' = Number of output times (int<frames-winframes). Enter a
% negative value [-S] to subsample original time by S.
% 'timesout' = Enter an array to obtain spectral decomposition at
% specific time values (note: algorithm find closest time
% point in data and this might result in an unevenly spaced
% time array). Overwrite 'ntimesout'. {def: automatic}
% 'powerlat' = [float] latency in ms at which to compute phase
% histogram
% 'tlimits' = [min max] time limits in ms.
%
% Optional Detrending:
% 'detrend' = ['on'|'off'], Linearly detrend each data epoch {'off'}
% 'rmerp' = ['on'|'off'], Remove epoch mean from data epochs {'off'}
%
% Optional FFT/DFT Parameters:
% 'winsize' = If cycles==0: data subwindow length (fastest, 2^n<frames);
% If cycles >0: *longest* window length to use. This
% determines the lowest output frequency. Note that this
% parameter is overwritten if the minimum frequency has been set
% manually and requires a longer time window {~frames/8}
% 'padratio' = FFT-length/winframes (2^k) {2}
% Multiplies the number of output frequencies by dividing
% their spacing (standard FFT padding). When cycles~=0,
% frequency spacing is divided by padratio.
% 'nfreqs' = number of output frequencies. For FFT, closest computed
% frequency will be returned. Overwrite 'padratio' effects
% for wavelets. Default: use 'padratio'.
% 'freqscale' = ['log'|'linear'] frequency scale. Default is 'linear'.
% Note that for obtaining 'log' spaced freqs using FFT,
% closest correspondant frequencies in the 'linear' space
% are returned.
% 'subitc' = ['on'|'off'] subtract stimulus locked Inter-Trial Coherence
% (ITC) from x and y. This computes the 'intrinsic' coherence
% x and y not arising from common synchronization to
% experimental events. See notes. {default: 'off'}
% 'itctype' = ['coher'|'phasecoher'] For use with 'subitc', see timef()
% for more details {default: 'phasecoher'}.
% 'subwin' = [min max] sub time window in ms (this windowing is
% performed after the spectral decomposition).
%
% Outputs:
% pac = Matrix (nfreqs1,nfreqs2,timesout) of coherence (complex).
% Use 20*log(abs(crossfcoh)) to vizualize log spectral diffs.
% timesout = Vector of output times (window centers) (ms).
% freqsout1 = Vector of frequency bin centers for first argument (Hz).
% freqsout2 = Vector of frequency bin centers for second argument (Hz).
% alltfX = single trial spectral decomposition of X
% alltfY = single trial spectral decomposition of Y
%
% Author: Arnaud Delorme, SCCN/INC, UCSD 2005-
%
% Ref: Testing for Nested Oscilations (2008) J Neuro Methods 174(1):50-61
%
% See also: timefreq(), crossf()
%123456789012345678901234567890123456789012345678901234567890123456789012
% Copyright (C) 2002 Arnaud Delorme, Salk Institute, [email protected]
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
% $Log: not supported by cvs2svn $
% Revision 1.1 2009/07/10 01:50:45 arno
% new function
%
% Revision 1.2 2009/07/08 23:44:47 arno
% Now working with test script
%
% Revision 1.1 2009/07/08 02:21:48 arno
% *** empty log message ***
%
% Revision 1.6 2009/05/22 23:57:06 klaus
% latest compatibility fixes
%
% Revision 1.5 2003/07/09 22:00:55 arno
% fixing normalization problem
%
% Revision 1.4 2003/07/09 01:29:46 arno
% bootstat -> bootcircle
%
% Revision 1.3 2003/07/03 23:43:10 arno
% *** empty log message ***
%
% Revision 1.2 2003/06/28 01:25:23 arno
% help if no arg
%
% Revision 1.1 2003/06/27 23:35:32 arno
% Initial revision
%
function [crossfcoh, timesout1, freqs1, freqs2, alltfX, alltfY] = pac(X, Y, srate, varargin);
if nargin < 1
help pac;
return;
end;
% deal with 3-D inputs
% --------------------
if ndims(X) == 3, X = reshape(X, size(X,2), size(X,3)); end;
if ndims(Y) == 3, Y = reshape(Y, size(Y,2), size(Y,3)); end;
frame = size(X,2);
g = finputcheck(varargin, ...
{ 'alpha' 'real' [0 0.2] [];
'baseboot' 'float' [] 0;
'boottype' 'string' {'times' 'trials' 'timestrials'} 'timestrials';
'detrend' 'string' {'on' 'off'} 'off';
'freqs' 'real' [0 Inf] [0 srate/2];
'freqs2' 'real' [0 Inf] [];
'freqscale' 'string' { 'linear' 'log' } 'linear';
'itctype' 'string' {'phasecoher' 'phasecoher2' 'coher'} 'phasecoher';
'nfreqs' 'integer' [0 Inf] [];
'lowmem' 'string' {'on' 'off'} 'off';
'method' 'string' { 'mod' 'corrsin' 'corrcos' 'latphase' } 'mod';
'naccu' 'integer' [1 Inf] 250;
'newfig' 'string' {'on' 'off'} 'on';
'padratio' 'integer' [1 Inf] 2;
'rmerp' 'string' {'on' 'off'} 'off';
'rboot' 'real' [] [];
'subitc' 'string' {'on' 'off'} 'off';
'subwin' 'real' [] []; ...
'powerlat' 'real' [] []; ...
'timesout' 'real' [] []; ...
'ntimesout' 'integer' [] 200; ...
'tlimits' 'real' [] [0 frame/srate];
'title' 'string' [] '';
'vert' { 'real' 'cell' } [] [];
'wavelet' 'real' [0 Inf] 0;
'wavelet2' 'real' [0 Inf] [];
'winsize' 'integer' [0 Inf] max(pow2(nextpow2(frame)-3),4) }, 'pac');
if isstr(g), error(g); end;
% more defaults
% -------------
if isempty(g.wavelet2), g.wavelet2 = g.wavelet; end;
if isempty(g.freqs2), g.freqs2 = g.freqs; end;
% remove ERP if necessary
% -----------------------
X = squeeze(X);
Y = squeeze(Y);X = squeeze(X);
trials = size(X,2);
if strcmpi(g.rmerp, 'on')
X = X - repmat(mean(X,2), [1 trials]);
Y = Y - repmat(mean(Y,2), [1 trials]);
end;
% perform timefreq decomposition
% ------------------------------
[alltfX freqs1 timesout1] = timefreq(X, srate, 'ntimesout', g.ntimesout, 'timesout', g.timesout, 'winsize', g.winsize, ...
'tlimits', g.tlimits, 'detrend', g.detrend, 'itctype', g.itctype, ...
'subitc', g.subitc, 'wavelet', g.wavelet, 'padratio', g.padratio, ...
'freqs', g.freqs, 'freqscale', g.freqscale, 'nfreqs', g.nfreqs);
[alltfY freqs2 timesout2] = timefreq(Y, srate, 'ntimesout', g.ntimesout, 'timesout', g.timesout, 'winsize', g.winsize, ...
'tlimits', g.tlimits, 'detrend', g.detrend, 'itctype', g.itctype, ...
'subitc', g.subitc, 'wavelet', g.wavelet2, 'padratio', g.padratio, ...
'freqs', g.freqs2, 'freqscale', g.freqscale, 'nfreqs', g.nfreqs);
% check time limits
% -----------------
if ~isempty(g.subwin)
ind1 = find(timesout1 > g.subwin(1) & timesout1 < g.subwin(2));
ind2 = find(timesout2 > g.subwin(1) & timesout2 < g.subwin(2));
alltfX = alltfX(:, ind1, :);
alltfY = alltfY(:, ind2, :);
timesout1 = timesout1(ind1);
timesout2 = timesout2(ind2);
end;
if length(timesout1) ~= length(timesout2) | any( timesout1 ~= timesout2)
disp('Warning: Time points are different for X and Y. Use ''timesout'' to specify common time points');
[vals ind1 ind2 ] = intersect(timesout1, timesout2);
fprintf('Searching for common time points: %d found\n', length(vals));
if length(vals) < 10, error('Less than 10 common data points'); end;
timesout1 = vals;
timesout2 = vals;
alltfX = alltfX(:, ind1, :);
alltfY = alltfY(:, ind2, :);
end;
% scan accross frequency and time
% -------------------------------
%if isempty(g.alpha)
% disp('Warning: if significance mask is not applied, result might be slightly')
% disp('different (since angle is not made uniform and amplitude interpolated)')
%end;
cohboot =[];
if ~strcmpi(g.method, 'latphase')
for find1 = 1:length(freqs1)
for find2 = 1:length(freqs2)
for ti = 1:length(timesout1)
% get data
% --------
tmpalltfx = squeeze(alltfX(find1,ti,:));
tmpalltfy = squeeze(alltfY(find2,ti,:));
%if ~isempty(g.alpha)
% tmpalltfy = angle(tmpalltfy);
% tmpalltfx = abs( tmpalltfx);
% [ tmp cohboot(find1,find2,ti,:) newamp newangle ] = ...
% bootcircle(tmpalltfx, tmpalltfy, 'naccu', g.naccu);
% crossfcoh(find1,find2,ti) = sum ( newamp .* exp(j*newangle) );
%else
tmpalltfy = angle(tmpalltfy);
tmpalltfx = abs( tmpalltfx);
if strcmpi(g.method, 'mod')
crossfcoh(find1,find2,ti) = sum( tmpalltfx .* exp(j*tmpalltfy) );
elseif strcmpi(g.method, 'corrsin')
tmp = corrcoef( sin(tmpalltfy), tmpalltfx);
crossfcoh(find1,find2,ti) = tmp(2);
else
tmp = corrcoef( cos(tmpalltfy), tmpalltfx);
crossfcoh(find1,find2,ti) = tmp(2);
end;
end;
end;
end;
else
% this option computes power at a given latency
% then computes the same as above (vectors)
%if isempty(g.powerlat)
% error('You need to specify a latency for the ''powerlat'' option');
%end;
power = mean(alltfX(:,:,:).*conj(alltfX),1); % average all frequencies for power
for t = 1:size(alltfX,3) % scan trials
% find latency with max power (and store angle)
% ---------------------------------------------
[tmp maxlat] = max(power(1,:,t));
tmpalltfy(:,t) = angle(alltfY(:,maxlat,t));
end;
vect = linspace(-pi,pi,50);
for f = 1:length(freqs2)
crossfcoh(f,:) = hist(tmpalltfy(f,:), vect);
end;
% smoothing of output image
% -------------------------
gs = gauss2d(6, 6);
crossfcoh = conv2(crossfcoh, gs, 'same');
freqs1 = freqs2;
timesout1 = linspace(-180, 180, size(crossfcoh,2));
end;
|
github
|
Aleman-Z/CorticoHippocampal-master
|
load_open_ephys_data_faster.m
|
.m
|
CorticoHippocampal-master/Load_ephys/load_open_ephys_data_faster.m
| 7,995 |
utf_8
|
753aa8b365dfc6fced7ad632290b0f24
|
function [data, timestamps, info] = load_open_ephys_data_faster(filename, varargin)
%
% [data, timestamps, info] = load_open_ephys_data(filename, [outputFormat])
%
% Loads continuous, event, or spike data files into Matlab.
%
% Inputs:
%
% filename: path to file
% outputFormat: (optional) If omitted, continuous data is output in double format and is scaled to reflect microvolts.
% If this argument is 'unscaledInt16' and the file contains continuous data, the output data will be in
% int16 format and will not be scaled; this data must be manually converted to a floating-point format
% and multiplied by info.header.bitVolts to obtain microvolt values. This feature is intended to save memory
% for operations involving large amounts of data.
%
%
% Outputs:
%
% data: either an array continuous samples (in microvolts unless outputFormat is specified, see above),
% a matrix of spike waveforms (in microvolts),
% or an array of event channels (integers)
%
% timestamps: in seconds
%
% info: structure with header and other information
%
%
%
% DISCLAIMER:
%
% Both the Open Ephys data format and this m-file are works in progress.
% There's no guarantee that they will preserve the integrity of your
% data. They will both be updated rather frequently, so try to use the
% most recent version of this file, if possible.
%
%
%
% ------------------------------------------------------------------
%
% Copyright (C) 2014 Open Ephys
%
% ------------------------------------------------------------------
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% <http://www.gnu.org/licenses/>.
%
[~,~,filetype] = fileparts(filename);
if ~any(strcmp(filetype,{'.events','.continuous','.spikes'}))
error('File extension not recognized. Please use a ''.continuous'', ''.spikes'', or ''.events'' file.');
end
bInt16Out = false;
if nargin > 2
error('Too many input arguments.');
elseif nargin == 2
if strcmpi(varargin{1}, 'unscaledInt16')
bInt16Out = true;
else
error('Unrecognized output format.');
end
end
fid = fopen(filename);
fseek(fid,0,'eof');
filesize = ftell(fid);
NUM_HEADER_BYTES = 1024;
fseek(fid,0,'bof');
hdr = fread(fid, NUM_HEADER_BYTES, 'char*1');
info = getHeader(hdr);
if isfield(info.header, 'version')
version = info.header.version;
else
version = 0.0;
end
switch filetype
case '.events'
bStr = {'timestamps' 'sampleNum' 'eventType' 'nodeId' 'eventId' 'data' 'recNum'};
bTypes = {'int64' 'uint16' 'uint8' 'uint8' 'uint8' 'uint8' 'uint16'};
bRepeat = {1 1 1 1 1 1 1};
dblock = struct('Repeat',bRepeat,'Types', bTypes,'Str',bStr);
if version < 0.2, dblock(7) = []; end
if version < 0.1, dblock(1).Types = 'uint64'; end
case '.continuous'
SAMPLES_PER_RECORD = 1024;
bStr = {'ts' 'nsamples' 'recNum' 'data' 'recordMarker'};
bTypes = {'int64' 'uint16' 'uint16' 'int16' 'uint8'};
bRepeat = {1 1 1 SAMPLES_PER_RECORD 10};
dblock = struct('Repeat',bRepeat,'Types', bTypes,'Str',bStr);
if version < 0.2, dblock(3) = []; end
if version < 0.1, dblock(1).Types = 'uint64'; dblock(2).Types = 'int16'; end
case '.spikes'
num_channels = info.header.num_channels;
num_samples = 40;
bStr = {'eventType' 'timestamps' 'timestamps_software' 'source' 'nChannels' 'nSamples' 'sortedId' 'electrodeID' 'channel' 'color' 'pcProj' 'samplingFrequencyHz' 'data' 'gain' 'threshold' 'recordingNumber'};
bTypes = {'uint8' 'int64' 'int64' 'uint16' 'uint16' 'uint16' 'uint16' 'uint16' 'uint16' 'uint8' 'float32' 'uint16' 'uint16' 'float32' 'uint16' 'uint16'};
bRepeat = {1 1 1 1 1 1 1 1 1 3 2 1 num_channels*num_samples num_channels num_channels 1};
dblock = struct('Repeat',bRepeat,'Types', bTypes,'Str',bStr);
if version < 0.4, dblock(7:12) = []; dblock(8).Types = 'uint16'; end
if version == 0.3, dblock = [dblock(1), struct('Repeat',1,'Types','uint32','Str','ts'), dblock(2:end)]; end
if version < 0.3, dblock(2) = []; end
if version < 0.2, dblock(9) = []; end
if version < 0.1, dblock(2).Types = 'uint64'; end
end
blockBytes = str2double(regexp({dblock.Types},'\d{1,2}$','match', 'once')) ./8 .* cell2mat({dblock.Repeat});
numIdx = floor((filesize - NUM_HEADER_BYTES)/sum(blockBytes));
switch filetype
case '.events'
timestamps = segRead('timestamps')./info.header.sampleRate;
info.sampleNum = segRead('sampleNum');
info.eventType = segRead('eventType');
info.nodeId = segRead('nodeId');
info.eventId = segRead('eventId');
data = segRead('data');
if version >= 0.2, info.recNum = segRead('recNum'); end
case '.continuous'
if nargout>1
info.ts = segRead('ts');
end
info.nsamples = segRead('nsamples');
if ~all(info.nsamples == SAMPLES_PER_RECORD)&& version >= 0.1, error('Found corrupted record'); end
if version >= 0.2, info.recNum = segRead('recNum'); end
% read in continuous data
if bInt16Out
data = segRead_int16('data', 'b');
else
data = segRead('data', 'b') .* info.header.bitVolts;
end
if nargout>1 % do not create timestamp arrays unless they are requested
timestamps = nan(size(data));
current_sample = 0;
for record = 1:length(info.ts)
timestamps(current_sample+1:current_sample+info.nsamples(record)) = info.ts(record):info.ts(record)+info.nsamples(record)-1;
current_sample = current_sample + info.nsamples(record);
end
end
case '.spikes'
timestamps = segRead('timestamps')./info.header.sampleRate;
info.source = segRead('source');
info.samplenum = segRead('nSamples');
info.gain = permute(reshape(segRead('gain'), num_channels, numIdx), [2 1]);
info.thresh = permute(reshape(segRead('threshold'), num_channels, numIdx), [2 1]);
if version >= 0.4, info.sortedId = segRead('sortedId'); end
if version >= 0.2, info.recNum = segRead('recordingNumber'); end
data = permute(reshape(segRead('data'), num_samples, num_channels, numIdx), [3 1 2]);
data = (data-32768)./ permute(repmat(info.gain/1000,[1 1 num_samples]), [1 3 2]);
end
fclose(fid);
function seg = segRead_int16(segName, mf)
%% This function is specifically for reading continuous data.
% It keeps the data in int16 precision, which can drastically decrease
% memory consumption
if nargin == 1, mf = 'l'; end
segNum = find(strcmp({dblock.Str},segName));
fseek(fid, sum(blockBytes(1:segNum-1))+NUM_HEADER_BYTES, 'bof');
seg = fread(fid, numIdx*dblock(segNum).Repeat, [sprintf('%d*%s', ...
dblock(segNum).Repeat,dblock(segNum).Types) '=>int16'], sum(blockBytes) - blockBytes(segNum), mf);
end
function seg = segRead(segName, mf)
if nargin == 1, mf = 'l'; end
segNum = find(strcmp({dblock.Str},segName));
fseek(fid, sum(blockBytes(1:segNum-1))+NUM_HEADER_BYTES, 'bof');
seg = fread(fid, numIdx*dblock(segNum).Repeat, sprintf('%d*%s', ...
dblock(segNum).Repeat,dblock(segNum).Types), sum(blockBytes) - blockBytes(segNum), mf);
end
end
function info = getHeader(hdr)
eval(char(hdr'));
info.header = header;
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
load_open_ephys_data.m
|
.m
|
CorticoHippocampal-master/Load_ephys/load_open_ephys_data.m
| 20,184 |
utf_8
|
9344c2dcff444974b5cb51cf8356c985
|
function [data, timestamps, info] = load_open_ephys_data(filename,varargin)
%
% [data, timestamps, info] = load_open_ephys_data(filename)
% [data, timestamps, info] = load_open_ephys_data(filename,'Indices',ind)
%
% Loads continuous, event, or spike data files into Matlab.
%
% Inputs:
%
% filename: path to file
%
%
% Outputs:
%
% data: either an array continuous samples (in microvolts),
% a matrix of spike waveforms (in microvolts),
% or an array of event channels (integers)
%
% timestamps: in seconds
%
% info: structure with header and other information
%
% Optional Parameter/Value Pairs
%
% 'Indices' row vector of ever increasing positive integers | []
% The vector represents the indices for datapoints, allowing
% partial reading of the file using memmapfile. If empty, all
% the data points will be returned.
%
%
% DISCLAIMER:
%
% Both the Open Ephys data format and this m-file are works in progress.
% There's no guarantee that they will preserve the integrity of your
% data. They will both be updated rather frequently, so try to use the
% most recent version of this file, if possible.
%
%
%
% ------------------------------------------------------------------
%
% Copyright (C) 2014 Open Ephys
%
% ------------------------------------------------------------------
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% <http://www.gnu.org/licenses/>.
%
p = inputParser;
p.addRequired('filename');
p.addParameter('Indices',[],@(x) isempty(x) || isrow(x) && all(diff(x) > 0) ...
&& all(fix(x) == x) && all(x > 0));
p.parse(filename,varargin{:});
range_pts = p.Results.Indices;
filetype = filename(max(strfind(filename,'.'))+1:end); % parse filetype
fid = fopen(filename);
filesize = getfilesize(fid);
% constants
NUM_HEADER_BYTES = 1024;
SAMPLES_PER_RECORD = 1024;
RECORD_MARKER = [0 1 2 3 4 5 6 7 8 255]';
RECORD_MARKER_V0 = [0 0 0 0 0 0 0 0 0 255]';
% constants for pre-allocating matrices:
MAX_NUMBER_OF_SPIKES = 1e6;
MAX_NUMBER_OF_RECORDS = 1e6;
MAX_NUMBER_OF_CONTINUOUS_SAMPLES = 1e8;
MAX_NUMBER_OF_EVENTS = 1e6;
SPIKE_PREALLOC_INTERVAL = 1e6;
%-----------------------------------------------------------------------
%------------------------- EVENT DATA ----------------------------------
%-----------------------------------------------------------------------
if strcmp(filetype, 'events')
if ~isempty(range_pts)
error('events data is not supported for memory mapping yet')
end
disp(['Loading events file...']);
index = 0;
hdr = fread(fid, NUM_HEADER_BYTES, 'char*1');
eval(char(hdr'));
info.header = header;
if (isfield(info.header, 'version'))
version = info.header.version;
else
version = 0.0;
end
% pre-allocate space for event data
data = zeros(MAX_NUMBER_OF_EVENTS, 1);
timestamps = zeros(MAX_NUMBER_OF_EVENTS, 1);
info.sampleNum = zeros(MAX_NUMBER_OF_EVENTS, 1);
info.nodeId = zeros(MAX_NUMBER_OF_EVENTS, 1);
info.eventType = zeros(MAX_NUMBER_OF_EVENTS, 1);
info.eventId = zeros(MAX_NUMBER_OF_EVENTS, 1);
if (version >= 0.2)
recordOffset = 15;
else
recordOffset = 13;
end
while ftell(fid) + recordOffset < filesize % at least one record remains
index = index + 1;
if (version >= 0.1)
timestamps(index) = fread(fid, 1, 'int64', 0, 'l');
else
timestamps(index) = fread(fid, 1, 'uint64', 0, 'l');
end
info.sampleNum(index) = fread(fid, 1, 'int16'); % implemented after 11/16/12
info.eventType(index) = fread(fid, 1, 'uint8');
info.nodeId(index) = fread(fid, 1, 'uint8');
info.eventId(index) = fread(fid, 1, 'uint8');
data(index) = fread(fid, 1, 'uint8'); % save event channel as 'data' (maybe not the best thing to do)
if version >= 0.2
info.recordingNumber(index) = fread(fid, 1, 'uint16');
end
end
% crop the arrays to the correct size
data = data(1:index);
timestamps = timestamps(1:index);
info.sampleNum = info.sampleNum(1:index);
info.nodeId = info.nodeId(1:index);
info.eventType = info.eventType(1:index);
info.eventId = info.eventId(1:index);
%-----------------------------------------------------------------------
%---------------------- CONTINUOUS DATA --------------------------------
%-----------------------------------------------------------------------
elseif strcmp(filetype, 'continuous')
% https://open-ephys.atlassian.net/wiki/spaces/OEW/pages/65667092/Open+Ephys+format#OpenEphysformat-Continuousdatafiles(.continuous)
disp(['Loading ' filename '...']);
index = 0;
hdr = fread(fid, NUM_HEADER_BYTES, 'char*1');
eval(char(hdr'));
info.header = header;
if (isfield(info.header, 'version'))
version = info.header.version;
else
version = 0.0;
end
% pre-allocate space for continuous data
data = zeros(MAX_NUMBER_OF_CONTINUOUS_SAMPLES, 1);
info.ts = zeros(1, MAX_NUMBER_OF_RECORDS);
info.nsamples = zeros(1, MAX_NUMBER_OF_RECORDS);
if version >= 0.2
info.recNum = zeros(1, MAX_NUMBER_OF_RECORDS);
end
current_sample = 0;
RECORD_SIZE = 10 + SAMPLES_PER_RECORD*2 + 10; % size of each continuous record in bytes
if version >= 0.2
RECORD_SIZE = RECORD_SIZE + 2; % include recNum
end
if isempty(range_pts)
while ftell(fid) + RECORD_SIZE <= filesize % at least one record remains
go_back_to_start_of_loop = 0;
index = index + 1;
if (version >= 0.1)
timestamp = fread(fid, 1, 'int64', 0, 'l');
nsamples = fread(fid, 1, 'uint16',0,'l');
if version >= 0.2
recNum = fread(fid, 1, 'uint16');
end
else
timestamp = fread(fid, 1, 'uint64', 0, 'l');
nsamples = fread(fid, 1, 'int16',0,'l');
end
if nsamples ~= SAMPLES_PER_RECORD && version >= 0.1
disp([' Found corrupted record...searching for record marker.']);
% switch to searching for record markers
last_ten_bytes = zeros(size(RECORD_MARKER));
for bytenum = 1:RECORD_SIZE*5
byte = fread(fid, 1, 'uint8');
last_ten_bytes = circshift(last_ten_bytes,-1);
last_ten_bytes(10) = double(byte);
if last_ten_bytes(10) == RECORD_MARKER(end)
sq_err = sum((last_ten_bytes - RECORD_MARKER).^2);
if (sq_err == 0)
disp([' Found a record marker after ' int2str(bytenum) ' bytes!']);
go_back_to_start_of_loop = 1;
break; % from 'for' loop
end
end
end
% if we made it through the approximate length of 5 records without
% finding a marker, abandon ship.
if bytenum == RECORD_SIZE*5
disp(['Loading failed at block number ' int2str(index) '. Found ' ...
int2str(nsamples) ' samples.'])
break; % from 'while' loop
end
end
if ~go_back_to_start_of_loop
block = fread(fid, nsamples, 'int16', 0, 'b'); % read in data
fread(fid, 10, 'char*1'); % read in record marker and discard
data(current_sample+1:current_sample+nsamples) = block;
current_sample = current_sample + nsamples;
info.ts(index) = timestamp;
info.nsamples(index) = nsamples;
if version >= 0.2
info.recNum(index) = recNum;
end
end
end
elseif ~isempty(range_pts)
if (version >= 0.1)
if version >= 0.2
m = memmapfile(filename,....
'Format',{'int64',1,'timestamp';...
'uint16',1,'nsamples';...
'uint16',1,'recNum';...
'int16',[SAMPLES_PER_RECORD, 1],'block';...
'uint8',[1, 10],'marker'},...
'Offset',NUM_HEADER_BYTES,'Repeat',Inf);
else
m = memmapfile(filename,....
'Format',{'int64',1,'timestamp';...
'uint16',1,'nsamples';...
'int16',[SAMPLES_PER_RECORD, 1],'block';...
'uint8',[1, 10],'marker'},...
'Offset',NUM_HEADER_BYTES,'Repeat',Inf); %TODO not tested
end
else
m = memmapfile(filename,....
'Format',{'uint64',1,'timestamp';...
'int16',1,'nsamples';...
'int16',[SAMPLES_PER_RECORD, 1],'block';...
'uint8',[1, 10],'marker'},...
'Offset',NUM_HEADER_BYTES,'Repeat',Inf); %TODO not tested
end
tf = false(length(m.Data)*SAMPLES_PER_RECORD,1);
tf(range_pts) = true;
Cblk = cell(length(m.Data),1);
Cts = cell(length(m.Data),1);
Cns = cell(length(m.Data),1);
Ctsinterp = cell(length(m.Data),1);
if version >= 0.2
Crn = cell(length(m.Data),1);
end
for i = 1:length(m.Data)
if any(tf(SAMPLES_PER_RECORD*(i-1)+1:SAMPLES_PER_RECORD*i))
Cblk{i} = m.Data(i).block(tf(SAMPLES_PER_RECORD*(i-1)+1:SAMPLES_PER_RECORD*i));
Cts{i} = double(m.Data(i).timestamp);
Cns{i} = double(m.Data(i).nsamples);
if version >= 0.2
Crn{i} = double(m.Data(i).recNum);
end
tsvec = Cts{i}:Cts{i}+Cns{i}-1;
Ctsinterp{i} = tsvec(tf(SAMPLES_PER_RECORD*(i-1)+1:SAMPLES_PER_RECORD*i));
end
end
data = vertcat(Cblk{:});
data = double(swapbytes(data)); % big endian
info.ts = [Cts{:}];
info.nsamples = [Cns{:}];
if version >= 0.2
info.recNum = [Crn{:}];
end
index = length(info.nsamples);
current_sample = length(range_pts);
timestamps = [Ctsinterp{:}]';
%TODO check for corrupted file, not tested
if any(info.nsamples ~= SAMPLES_PER_RECORD) && version >= 0.1
disp([' Found corrupted record...searching for record marker.']);
k = find(info.nsamples ~= SAMPLES_PER_RECORD,1,'first');
ns = info.nsamples(k);
if version >= 0.2
offset = NUM_HEADER_BYTES + RECORD_SIZE * (k-1) + 12;
else
offset = NUM_HEADER_BYTES + RECORD_SIZE * (k-1) + 10;
end
status = fseek(fid,offset,'bof');
%TODO below should be a local function except break
% switch to searching for record markers
last_ten_bytes = zeros(size(RECORD_MARKER));
for bytenum = 1:RECORD_SIZE*5
byte = fread(fid, 1, 'uint8');
last_ten_bytes = circshift(last_ten_bytes,-1);
last_ten_bytes(10) = double(byte);
if last_ten_bytes(10) == RECORD_MARKER(end)
sq_err = sum((last_ten_bytes - RECORD_MARKER).^2);
if (sq_err == 0)
disp([' Found a record marker after ' int2str(bytenum) ' bytes!']);
go_back_to_start_of_loop = 1;
break; % from 'for' loop
end
end
end
% if we made it through the approximate length of 5 records without
% finding a marker, abandon ship.
if bytenum == RECORD_SIZE*5
disp(['Loading failed at block number ' int2str(index) '. Found ' ...
int2str(nsamples) ' samples.'])
% break; % from 'while' loop
end
end
end
% crop data to the correct size
data = data(1:current_sample);
info.ts = info.ts(1:index);
info.nsamples = info.nsamples(1:index);
if version >= 0.2
info.recNum = info.recNum(1:index);
end
% convert to microvolts
data = data.*info.header.bitVolts;
if isempty(range_pts)
timestamps = nan(size(data));
current_sample = 0;
if version >= 0.1
for record = 1:length(info.ts)
ts_interp = info.ts(record):info.ts(record)+info.nsamples(record);
timestamps(current_sample+1:current_sample+info.nsamples(record)) = ts_interp(1:end-1);
current_sample = current_sample + info.nsamples(record);
end
else % v0.0; NOTE: the timestamps for the last record will not be interpolated
for record = 1:length(info.ts)-1
ts_interp = linspace(info.ts(record), info.ts(record+1), info.nsamples(record)+1);
timestamps(current_sample+1:current_sample+info.nsamples(record)) = ts_interp(1:end-1);
current_sample = current_sample + info.nsamples(record);
end
end
end
%-----------------------------------------------------------------------
%--------------------------- SPIKE DATA --------------------------------
%-----------------------------------------------------------------------
elseif strcmp(filetype, 'spikes')
if ~isempty(range_pts)
error('spike data is not supported for memory mapping yet')
end
disp(['Loading spikes file...']);
index = 0;
hdr = fread(fid, NUM_HEADER_BYTES, 'char*1');
eval(char(hdr'));
info.header = header;
if (isfield(info.header, 'version'))
version = info.header.version;
else
version = 0.0;
end
num_channels = info.header.num_channels;
num_samples = 40; % **NOT CURRENTLY WRITTEN TO HEADER**
% pre-allocate space for spike data
data = zeros(MAX_NUMBER_OF_SPIKES, num_samples, num_channels);
timestamps = zeros(MAX_NUMBER_OF_SPIKES, 1);
info.source = zeros(MAX_NUMBER_OF_SPIKES, 1);
info.gain = zeros(MAX_NUMBER_OF_SPIKES, num_channels);
info.thresh = zeros(MAX_NUMBER_OF_SPIKES, num_channels);
if (version >= 0.4)
info.sortedId = zeros(MAX_NUMBER_OF_SPIKES, num_channels);
end
if (version >= 0.2)
info.recNum = zeros(MAX_NUMBER_OF_SPIKES, 1);
end
current_spike = 0;
last_percent=0;
while ftell(fid) + 512 < filesize % at least one record remains
current_spike = current_spike + 1;
current_percent= round(100* ((ftell(fid) + 512) / filesize));
if current_percent >= last_percent+10
last_percent=current_percent;
fprintf(' %d%%',current_percent);
end
idx = 0;
% read in event type (1 byte)
event_type = fread(fid, 1, 'uint8'); % always equal to 4; ignore
idx = idx + 1;
if (version == 0.3)
event_size = fread(fid, 1, 'uint32', 0, 'l');
idx = idx + 4;
ts = fread(fid, 1, 'int64', 0, 'l');
idx = idx + 8;
elseif (version >= 0.4)
timestamps(current_spike) = fread(fid, 1, 'int64', 0, 'l');
idx = idx + 8;
ts_software = fread(fid, 1, 'int64', 0, 'l');
idx = idx + 8;
end
if (version < 0.4)
if (version >= 0.1)
timestamps(current_spike) = fread(fid, 1, 'int64', 0, 'l');
else
timestamps(current_spike) = fread(fid, 1, 'uint64', 0, 'l');
end
idx = idx + 8;
end
info.source(current_spike) = fread(fid, 1, 'uint16', 0, 'l');
idx = idx + 2;
num_channels = fread(fid, 1, 'uint16', 0, 'l');
num_samples = fread(fid, 1, 'uint16', 0, 'l');
idx = idx + 4;
if num_samples < 1 || num_samples > 10000
disp(['Loading failed at block number ' int2str(current_spike) '. Found ' ...
int2str(num_samples) ' samples.'])
break;
end
if (version >= 0.4)
info.sortedId(current_spike) = fread(fid, 1, 'uint16', 0, 'l');
electrodeId = fread(fid, 1, 'uint16', 0, 'l');
channel = fread(fid, 1, 'uint16', 0, 'l');
color = fread(fid, 3, 'uint8', 0, 'l');
pcProj = fread(fid, 2, 'single');
sampleFreq = fread(fid, 1, 'uint16', 0, 'l');
idx = idx + 19;
end
waveforms = fread(fid, num_channels*num_samples, 'uint16', 0, 'l');
idx = idx + num_channels*num_samples*2;
wv = reshape(waveforms, num_samples, num_channels);
if (version < 0.4)
channel_gains = fread(fid, num_channels, 'uint16', 0, 'l');
idx = idx + num_channels * 2;
else
channel_gains = fread(fid, num_channels, 'single');
idx = idx + num_channels * 4;
end
info.gain(current_spike,:) = channel_gains;
channel_thresholds = fread(fid, num_channels, 'uint16', 0, 'l');
idx = idx + num_channels * 2;
info.thresh(current_spike,:) = channel_thresholds;
if version >= 0.2
info.recNum(current_spike) = fread(fid, 1, 'uint16', 0, 'l');
idx = idx + 2;
end
data(current_spike, :, :) = wv;
end
fprintf('\n')
for ch = 1:num_channels % scale the waveforms
data(:, :, ch) = double(data(:, :, ch)-32768)./(channel_gains(ch)/1000);
end
data = data(1:current_spike,:,:);
timestamps = timestamps(1:current_spike);
info.source = info.source(1:current_spike);
info.gain = info.gain(1:current_spike);
info.thresh = info.thresh(1:current_spike);
if version >= 0.2
info.recNum = info.recNum(1:current_spike);
end
if version >= 0.4
info.sortedId = info.sortedId(1:current_spike);
end
else
error('File extension not recognized. Please use a ''.continuous'', ''.spikes'', or ''.events'' file.');
end
fclose(fid); % close the file
if (isfield(info.header,'sampleRate'))
if ~ischar(info.header.sampleRate)
timestamps = timestamps./info.header.sampleRate; % convert to seconds
end
end
end
function filesize = getfilesize(fid)
fseek(fid,0,'eof');
filesize = ftell(fid);
fseek(fid,0,'bof');
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
stats_between_trials10.m
|
.m
|
CorticoHippocampal-master/Stats/stats_between_trials10.m
| 1,247 |
utf_8
|
5aa44f08f7f316efa8190a22d87ab7db
|
%%
function [stats]=stats_between_trials10(freq1,freq2,label1,w)
cfg = [];
cfg.latency = [-10 10]; % time of interest (exclude baseline: it doesn't make sense to compute statistics on a region we expect to be zero)
cfg.method = 'montecarlo';
cfg.statistic = 'ft_statfun_indepsamplesT';
cfg.correctm = 'cluster';
%cfg.channel = 'chan0'; % only one channel at the time, you should correct the p-value for the number of channels
cfg.channel = label1{2*w-1}; % only one channel at the time, you should correct the p-value for the number of channels
cfg.alpha = 0.05 / length(freq1.label);
cfg.correcttail = 'prob';
cfg.numrandomization = 500; % this value won't change the statistics. Use a higher value to have a more accurate p-value
% design = zeros(2, n_trl * 2);
% design(1, 1:n_trl) = 1;
% design(1, n_trl+1:end) = 2;
% design(2, :) = [1:n_trl 1:n_trl];
design = zeros(1,size(freq1.powspctrm,1) + size(freq2.powspctrm,1));
design(1,1:size(freq1.powspctrm,1)) = 1;
design(1,(size(freq1.powspctrm,1)+1):(size(freq1.powspctrm,1)+...
size(freq1.powspctrm,1))) = 2;
cfg.design = design;
cfg.ivar = 1;
% cfg.uvar = 2;
stats = ft_freqstatistics(cfg, freq2, freq1);
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
stats_high2.m
|
.m
|
CorticoHippocampal-master/Stats/stats_high2.m
| 3,642 |
utf_8
|
d2be4e040001bca14c70324f87fbe664
|
%%
function [zmap]=stats_high2(freq3,freq4)
%ntrials=size(freq3.powspctrm,1);
ntrials=1;
%Requires turning NaN into zeros.
% no1=freq3.powspctrm;
% no2=freq4.powspctrm;
no1=freq3;
no2=freq4;
no1(isnan(no1))=0;
no2(isnan(no2))=0;
%%
% freq3.powspctrm=no1;
% freq4.powspctrm=no2;
freq3=no1;
freq4=no2;
%% statistics via permutation testing
% p-value
pval = 0.05;
% convert p-value to Z value
zval = abs(norminv(pval));
% number of permutations
n_permutes = 2500; %Seems to need a lot more than 500.
% initialize null hypothesis maps
% permmaps = zeros(n_permutes,length(freq3.freq),length(freq3.time));
permmaps = zeros(n_permutes,size(freq3,1),size(freq3,2));
% for convenience, tf power maps are concatenated
% in this matrix, trials 1:ntrials are from channel "1"
% and trials ntrials+1:end are from channel "2"
%tf3d = cat(3,squeeze(tf(1,:,:,:)),squeeze(tf(2,:,:,:)));
%tf3d = cat(3,squeeze(freq3.powspctrm(:,w,:,:)),squeeze(freq3.powspctrm(:,w,:,:)));
tf3d = cat(3,freq3,freq4);
%concatenated in time.
% freq, time, trials
%59 241 2000
% generate maps under the null hypothesis
for permi = 1:n_permutes
permi
% randomize trials, which also randomly assigns trials to channels
randorder = randperm(size(tf3d,3));
temp_tf3d = tf3d(:,:,randorder);
% compute the "difference" map
% what is the difference under the null hypothesis?
permmaps(permi,:,:) = squeeze( mean(temp_tf3d(:,:,1:ntrials),3) - mean(temp_tf3d(:,:,ntrials+1:end),3) );
end
%% show non-corrected thresholded maps
%diffmap = squeeze(mean(freq4.powspctrm(:,w,:,:),1 )) - squeeze(mean(freq3.powspctrm(:,w,:,:),1 ));
diffmap = freq4 - freq3;
% compute mean and standard deviation maps
mean_h0 = squeeze(mean(permmaps));
std_h0 = squeeze(std(permmaps));
% now threshold real data...
% first Z-score
zmap = (diffmap-mean_h0) ./ std_h0;
% threshold image at p-value, by setting subthreshold values to 0
zmap(abs(zmap)<zval) = 0;
%%
% initialize matrices for cluster-based correction
max_cluster_sizes = zeros(1,n_permutes);
% ... and for maximum-pixel based correction
max_val = zeros(n_permutes,2); % "2" for min/max
% loop through permutations
for permi = 1:n_permutes
% take each permutation map, and transform to Z
threshimg = squeeze(permmaps(permi,:,:));
threshimg = (threshimg-mean_h0)./std_h0;
% threshold image at p-value
threshimg(abs(threshimg)<zval) = 0;
% find clusters (need image processing toolbox for this!)
islands = bwconncomp(threshimg);
if numel(islands.PixelIdxList)>0
% count sizes of clusters
tempclustsizes = cellfun(@length,islands.PixelIdxList);
% store size of biggest cluster
max_cluster_sizes(permi) = max(tempclustsizes);
end
% get extreme values (smallest and largest)
temp = sort( reshape(permmaps(permi,:,:),1,[] ));
max_val(permi,:) = [ min(temp) max(temp) ];
end
%%
cluster_thresh = prctile(max_cluster_sizes,100-(100*pval));
% now find clusters in the real thresholded zmap
% if they are "too small" set them to zero
islands = bwconncomp(zmap);
for i=1:islands.NumObjects
% if real clusters are too small, remove them by setting to zero!
if numel(islands.PixelIdxList{i}==i)<cluster_thresh
zmap(islands.PixelIdxList{i})=0;
end
end
%% now with max-pixel-based thresholding
% find the threshold for lower and upper values
thresh_lo = prctile(max_val(:,1),100-100*pval); % what is the
thresh_hi = prctile(max_val(:,2),100-100*pval); % true p-value?
% threshold real data
zmap = diffmap;
zmap(zmap>thresh_lo & zmap<thresh_hi) = 0;
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
stats_between_trials.m
|
.m
|
CorticoHippocampal-master/Stats/stats_between_trials.m
| 1,243 |
utf_8
|
003a2db080bbf2d57506abac11b32600
|
%%
function [stats]=stats_between_trials(freq1,freq2,label1,w)
cfg = [];
cfg.latency = [-1 1]; % time of interest (exclude baseline: it doesn't make sense to compute statistics on a region we expect to be zero)
cfg.method = 'montecarlo';
cfg.statistic = 'ft_statfun_indepsamplesT';
cfg.correctm = 'cluster';
%cfg.channel = 'chan0'; % only one channel at the time, you should correct the p-value for the number of channels
cfg.channel = label1{2*w-1}; % only one channel at the time, you should correct the p-value for the number of channels
cfg.alpha = 0.05 / length(freq1.label);
cfg.correcttail = 'prob';
cfg.numrandomization = 500; % this value won't change the statistics. Use a higher value to have a more accurate p-value
% design = zeros(2, n_trl * 2);
% design(1, 1:n_trl) = 1;
% design(1, n_trl+1:end) = 2;
% design(2, :) = [1:n_trl 1:n_trl];
design = zeros(1,size(freq1.powspctrm,1) + size(freq2.powspctrm,1));
design(1,1:size(freq1.powspctrm,1)) = 1;
design(1,(size(freq1.powspctrm,1)+1):(size(freq1.powspctrm,1)+...
size(freq1.powspctrm,1))) = 2;
cfg.design = design;
cfg.ivar = 1;
% cfg.uvar = 2;
stats = ft_freqstatistics(cfg, freq2, freq1);
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
permutationTest.m
|
.m
|
CorticoHippocampal-master/Stats/permutationTest.m
| 6,594 |
utf_8
|
6226faa947aba893c5b470c128f9fc48
|
% [p, observeddifference, effectsize] = permutationTest(sample1, sample2, permutations [, varargin])
%
% In:
% sample1 - vector of measurements representing one condition
% sample2 - vector of measurements representing a second condition
% permutations - the number of permutations
%
% Optional (name-value pairs):
% sidedness - whether to test one- or two-sided:
% 'both' - test two-sided (default)
% 'smaller' - test one-sided, alternative hypothesis is that
% the mean of sample1 is smaller than the mean of
% sample2
% 'larger' - test one-sided, alternative hypothesis is that
% the mean of sample1 is larger than the mean of
% sample2
% exact - whether or not to run an exact test, in which all possible
% combinations are considered. this is only feasible for
% relatively small sample sizes. the 'permutations' argument
% will be ignored for an exact test. (1|0, default 0)
% plotresult - whether or not to plot the distribution of randomised
% differences, along with the observed difference (1|0,
% default: 0)
% showprogress - whether or not to show a progress bar. if 0, no bar
% is displayed; if showprogress > 0, the bar updates
% every showprogress-th iteration.
%
% Out:
% p - the resulting p-value
% observeddifference - the observed difference between the two
% samples, i.e. mean(sample1) - mean(sample2)
% effectsize - the effect size
%
% Usage example:
% >> permutationTest(rand(1,100), rand(1,100)-.25, 10000, ...
% 'plotresult', 1, 'showprogress', 250)
%
% Copyright 2015-2018 Laurens R Krol
% Team PhyPA, Biological Psychology and Neuroergonomics,
% Berlin Institute of Technology
% 2018-03-15 lrk
% - Suppressed initial MATLAB:nchoosek:LargeCoefficient warning
% 2018-03-14 lrk
% - Added exact test
% 2018-01-31 lrk
% - Replaced calls to mean() with nanmean()
% 2017-06-15 lrk
% - Updated waitbar message in first iteration
% 2017-04-04 lrk
% - Added progress bar
% 2017-01-13 lrk
% - Switched to inputParser to parse arguments
% 2016-09-13 lrk
% - Caught potential issue when column vectors were used
% - Improved plot
% 2016-02-17 toz
% - Added plot functionality
% 2015-11-26 First version
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
function [p, observeddifference, effectsize] = permutationTest(sample1, sample2, permutations, varargin)
% parsing input
p = inputParser;
addRequired(p, 'sample1', @isnumeric);
addRequired(p, 'sample2', @isnumeric);
addRequired(p, 'permutations', @isnumeric);
addParamValue(p, 'sidedness', 'both', @(x) any(validatestring(x,{'both', 'smaller', 'larger'})));
addParamValue(p, 'exact' , 0, @isnumeric);
addParamValue(p, 'plotresult', 0, @isnumeric);
addParamValue(p, 'showprogress', 0, @isnumeric);
parse(p, sample1, sample2, permutations, varargin{:})
sample1 = p.Results.sample1;
sample2 = p.Results.sample2;
permutations = p.Results.permutations;
sidedness = p.Results.sidedness;
exact = p.Results.exact;
plotresult = p.Results.plotresult;
showprogress = p.Results.showprogress;
% enforcing row vectors
if iscolumn(sample1), sample1 = sample1'; end
if iscolumn(sample2), sample2 = sample2'; end
allobservations = [sample1, sample2];
observeddifference = nanmean(sample1) - nanmean(sample2);
effectsize = observeddifference / nanmean([std(sample1), std(sample2)]);
w = warning('off', 'MATLAB:nchoosek:LargeCoefficient');
if ~exact && permutations > nchoosek(numel(allobservations), numel(sample1))
warning(['the number of permutations (%d) is higher than the number of possible combinations (%d);\n' ...
'consider running an exact test using the ''exact'' argument'], ...
permutations, nchoosek(numel(allobservations), numel(sample1)));
end
warning(w);
if showprogress, w = waitbar(0, 'Preparing test...', 'Name', 'permutationTest'); end
if exact
% getting all possible combinations
allcombinations = nchoosek(1:numel(allobservations), numel(sample1));
permutations = size(allcombinations, 1);
end
% running test
randomdifferences = zeros(1, permutations);
if showprogress, waitbar(0, w, sprintf('Permutation 1 of %d', permutations), 'Name', 'permutationTest'); end
for n = 1:permutations
if showprogress && mod(n,showprogress) == 0, waitbar(n/permutations, w, sprintf('Permutation %d of %d', n, permutations)); end
% selecting either next combination, or random permutation
if exact, permutation = [allcombinations(n,:), setdiff(1:numel(allobservations), allcombinations(n,:))];
else, permutation = randperm(length(allobservations)); end
% diving into two samples
randomSample1 = allobservations(permutation(1:length(sample1)));
randomSample2 = allobservations(permutation(length(sample1)+1:length(permutation)));
% saving differences between the two samples
randomdifferences(n) = nanmean(randomSample1) - nanmean(randomSample2);
end
if showprogress, delete(w); end
% getting probability of finding observed difference from random permutations
if strcmp(sidedness, 'both')
p = (length(find(abs(randomdifferences) > abs(observeddifference)))+1) / (permutations+1);
elseif strcmp(sidedness, 'smaller')
p = (length(find(randomdifferences < observeddifference))+1) / (permutations+1);
elseif strcmp(sidedness, 'larger')
p = (length(find(randomdifferences > observeddifference))+1) / (permutations+1);
end
% plotting result
if plotresult
figure;
hist(randomdifferences);
hold on;
xlabel('Random differences');
ylabel('Count')
od = plot(observeddifference, 0, '*r', 'DisplayName', sprintf('Observed difference.\nEffect size: %.2f,\np = %f', effectsize, p));
legend(od);
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
stats_gc.m
|
.m
|
CorticoHippocampal-master/Stats/stats_gc.m
| 3,553 |
utf_8
|
7076361fc3aa8a22c55d34a5ad9714ac
|
%% Seems useless. Check carefully.
function [zmap]=stats_gc(gr1,gr2)
ntrials=373;
%Requires turning NaN into zeros.
no1=gr1(:,1:ntrials);
no2=gr2(:,1:ntrials);
no1(isnan(no1))=0;
no2(isnan(no2))=0;
%%
gr1=no1;
gr2=no2;
%% statistics via permutation testing
% p-value
pval = 0.05;
% convert p-value to Z value
zval = abs(norminv(pval));
% number of permutations
n_permutes = 500;
% initialize null hypothesis maps
permmaps = zeros(n_permutes,size(no1,1),1);
% for convenience, tf power maps are concatenated
% in this matrix, trials 1:ntrials are from channel "1"
% and trials ntrials+1:end are from channel "2"
%tf3d = cat(3,squeeze(tf(1,:,:,:)),squeeze(tf(2,:,:,:)));
%tf3d = cat(3,squeeze(freq3.powspctrm(:,w,:,:)),squeeze(freq3.powspctrm(:,w,:,:)));
% tf3d = cat(3,reshape(squeeze(freq3.powspctrm(:,w,:,:)),[length(freq3.freq) length(freq3.time)...
% ntrials ]),reshape(squeeze(freq4.powspctrm(:,w,:,:)),[length(freq3.freq) length(freq3.time)...
% ntrials ]));
tf3d=cat(2,no1,no2);
%concatenated in time.
% freq, time, trials
%59 241 2000
% generate maps under the null hypothesis
for permi = 1:n_permutes
permi
% randomize trials, which also randomly assigns trials to channels
randorder = randperm(size(tf3d,2));
temp_tf3d = tf3d(:,randorder);
% compute the "difference" map
% what is the difference under the null hypothesis?
permmaps(permi,:) = squeeze( mean(temp_tf3d(:,1:ntrials),2) - mean(temp_tf3d(:,ntrials+1:end),2) );
end
%% show non-corrected thresholded maps
diffmap = squeeze(no2-no1);
% compute mean and standard deviation maps
mean_h0 = squeeze(mean(permmaps));
std_h0 = squeeze(std(permmaps));
% now threshold real data...
% first Z-score
zmap = (diffmap-mean_h0.') ./ std_h0.';
% threshold image at p-value, by setting subthreshold values to 0
zmap(abs(zmap)<zval) = 0;
%%
% initialize matrices for cluster-based correction
max_cluster_sizes = zeros(1,n_permutes);
% ... and for maximum-pixel based correction
max_val = zeros(n_permutes,2); % "2" for min/max
% loop through permutations
for permi = 1:n_permutes
% take each permutation map, and transform to Z
threshimg = squeeze(permmaps(permi,:,:));
threshimg = (threshimg-mean_h0)./std_h0;
% threshold image at p-value
threshimg(abs(threshimg)<zval) = 0;
% find clusters (need image processing toolbox for this!)
islands = bwconncomp(threshimg);
if numel(islands.PixelIdxList)>0
% count sizes of clusters
tempclustsizes = cellfun(@length,islands.PixelIdxList);
% store size of biggest cluster
max_cluster_sizes(permi) = max(tempclustsizes);
end
% get extreme values (smallest and largest)
temp = sort( reshape(permmaps(permi,:,:),1,[] ));
max_val(permi,:) = [ min(temp) max(temp) ];
end
%%
cluster_thresh = prctile(max_cluster_sizes,100-(100*pval));
% now find clusters in the real thresholded zmap
% if they are "too small" set them to zero
islands = bwconncomp(zmap);
for i=1:islands.NumObjects
% if real clusters are too small, remove them by setting to zero!
if numel(islands.PixelIdxList{i}==i)<cluster_thresh
zmap(islands.PixelIdxList{i})=0;
end
end
%% now with max-pixel-based thresholding
% find the threshold for lower and upper values
thresh_lo = prctile(max_val(:,1),100-100*pval); % what is the
thresh_hi = prctile(max_val(:,2),100-100*pval); % true p-value?
% threshold real data
zmap = diffmap;
zmap(zmap>thresh_lo & zmap<thresh_hi) = 0;
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_conditions_27.m
|
.m
|
CorticoHippocampal-master/Pre_midterm/plot_inter_conditions_27.m
| 14,748 |
utf_8
|
8702a487891868e6a1975f49958835e0
|
%This one requires running data from Non Learning condition
function plot_inter_conditions_27(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,selectripples,acer,timecell_nl,P1_nl,P2_nl,p_nl,q_nl)
%function plot_inter_conditions_27(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,selectripples)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
%ran=randi(length(p),100,1);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
% % % % % % % % % % % % % % [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % % % % % % % % % % % % % % % ran_nl=ran;
% % % % % % % % % % % % % % if selectripples==1
% % % % % % % % % % % % % %
% % % % % % % % % % % % % % [ran_nl]=rip_select(p);
% % % % % % % % % % % % % % % av=cat(1,p_nl{1:end});
% % % % % % % % % % % % % % % %av=cat(1,q_nl{1:end});
% % % % % % % % % % % % % % % av=av(1:3:end,:); %Only Hippocampus
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % %AV=max(av.');
% % % % % % % % % % % % % % % %[B I]= maxk(AV,1000);
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % %AV=max(av.');
% % % % % % % % % % % % % % % %[B I]= maxk(max(av.'),1000);
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % [ach]=max(av.');
% % % % % % % % % % % % % % % achinga=sort(ach,'descend');
% % % % % % % % % % % % % % % achinga=achinga(1:1000);
% % % % % % % % % % % % % % % B=achinga;
% % % % % % % % % % % % % % % I=nan(1,length(B));
% % % % % % % % % % % % % % % for hh=1:length(achinga)
% % % % % % % % % % % % % % % % I(hh)= min(find(ach==achinga(hh)));
% % % % % % % % % % % % % % % I(hh)= find(ach==achinga(hh),1,'first');
% % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % [ajal ind]=unique(B);
% % % % % % % % % % % % % % % if length(ajal)>500
% % % % % % % % % % % % % % % ajal=ajal(end-499:end);
% % % % % % % % % % % % % % % ind=ind(end-499:end);
% % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % % dex=I(ind);
% % % % % % % % % % % % % % % ran_nl=dex.';
% % % % % % % % % % % % % %
% % % % % % % % % % % % % % p_nl=p_nl([ran_nl]);
% % % % % % % % % % % % % % q_nl=q_nl([ran_nl]);
% % % % % % % % % % % % % % timecell_nl=timecell_nl([ran_nl]);
% % % % % % % % % % % % % %
% % % % % % % % % % % % % %
% % % % % % % % % % % % % % end
%Need: P1, P2 ,p, q.
% % % % % % % % % % % % % P1_nl=avg_samples(q_nl,timecell_nl);
% % % % % % % % % % % % % P2_nl=avg_samples(p_nl,timecell_nl);
% % % if acer==0
% % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % %
% % % else
% % % cd(strcat('D:\internship\',num2str(Rat)))
% % % end
% % % cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
H1=subplot(3,4,1);
plot(timecell_nl{1},P2_nl(w,:))
xlim([-1,1])
%xlim([-0.8,0.8])
grid minor
Hc1=narrow_colorbar();
title('Wide Band NO Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
%%
H3=subplot(3,4,3)
plot(timecell_nl{1},P1_nl(w,:))
xlim([-1,1])
%xlim([-0.8,0.8])
grid minor
Hc3=narrow_colorbar()
title('High Gamma NO Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
%%
H2=subplot(3,4,2)
plot(timecell{1},P2(w,:))
xlim([-1,1])
%xlim([-0.8,0.8])
grid minor
Hc2=narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii-3}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
%%
H4=subplot(3,4,4)
plot(timecell{1},P1(w,:))
xlim([-1,1])
%xlim([-0.8,0.8])
grid minor
Hc4=narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii-3}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
%% Time Frequency plots
% Calculate Freq1 and Freq2
toy = [-1.2:.01:1.2];
if selectripples==1
if length(p)>length(p_nl)
p=p(1:length(p_nl));
timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
timecell_nl=timecell_nl(1:length(p));
end
end
freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10,toy);
freq2=justtesting(p,timecell,[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%% Baseline normalization
cfg=[];
cfg.baseline=[-1 -0.5];
%cfg.baseline='yes';
cfg.baselinetype ='db';
freq10=ft_freqbaseline(cfg,freq1);
freq20=ft_freqbaseline(cfg,freq2);
[achis]=baseline_norm(freq1,w);
[achis2]=baseline_norm(freq2,w);
climdb=[-3 3];
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
% % % % % cfg = [];
% % % % % cfg.channel = freq1.label{w};
% % % % % [ zmin1, zmax1] = ft_getminmax(cfg, freq10);
% % % % % [zmin2, zmax2] = ft_getminmax(cfg, freq20);
% % % % %
% % % % % zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% % % % %
% % % % % zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
% % % % % % % % % % % % % % % % % % % cfg = [];
% % % % % % % % % % % % % % % % % % % cfg.zlim=zlim;% Uncomment this!
% % % % % % % % % % % % % % % % % % % cfg.channel = freq1.label{w};
% % % % % % % % % % % % % % % % % % % cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
ax1 =subplot(3,4,5);
contourf(toy,freq1.freq,achis,40,'linecolor','none');
colormap(jet(256));%narrow_colorbar();
set(gca,'clim',climdb,'ydir','normal','xlim',[-1 1])
c1=colorbar();
h1 = get(H1, 'position'); % get axes position
hn1= get(Hc1, 'Position'); % Colorbar Width for c1
x1 = get(ax1, 'position'); % get axes position
cw1= get(c1, 'Position'); % Colorbar Width for c1
cw1(3)=hn1(3);
cw1(1)=hn1(1);
set(c1,'Position',cw1)
x1(3)=h1(3);
set(ax1,'Position',x1)
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
title('Wide Band NO Learning')
%xlim([-1 1])
%%
% subplot(3,4,6)
%%ft_singleplotTFR(cfg, freq20);
ax2 =subplot(3,4,6);
contourf(toy,freq2.freq,achis2,40,'linecolor','none');
colormap(jet(256));%narrow_colorbar();
set(gca,'clim',climdb,'ydir','normal','xlim',[-1 1])
c2=colorbar();
h2 = get(H2, 'position'); % get axes position
hn2= get(Hc2, 'Position'); % Colorbar Width for c1
x2 = get(ax2, 'position'); % get axes position
cw2= get(c2, 'Position'); % Colorbar Width for c1
cw2(3)=hn2(3);
cw2(1)=hn2(1);
set(c2,'Position',cw2)
x2(3)=h2(3);
set(ax2,'Position',x2)
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
title(strcat('Wide Band',{' '},labelconditions{iii-3}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
xlim([-1 1])
%%
%
[stats]=stats_between_trials(freq1,freq2,label1,w);
%
subplot(3,4,10)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
title(strcat(labelconditions{iii-3},' vs No Learning'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
%Calculate Freq3 and Freq4
toy=[-1:.01:1];
if selectripples==1
if length(q)>length(q_nl)
q=q(1:length(q_nl));
timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
timecell_nl=timecell_nl(1:length(q));
end
end
freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w,toy);
freq4=barplot2_ft(q,timecell,[100:1:300],w,toy);
%%
cfg=[];
cfg.baseline=[-1 -0.5];
%cfg.baseline='yes';
cfg.baselinetype='db';
freq30=ft_freqbaseline(cfg,freq3);
freq40=ft_freqbaseline(cfg,freq4);
[achis3]=baseline_norm(freq3,w);
[achis4]=baseline_norm(freq4,w);
climdb=[-3 3];
%%
% Calculate zlim
% % % % cfg = [];
% % % % cfg.channel = freq3.label{w};
% % % % [ zmin1, zmax1] = ft_getminmax(cfg, freq30);
% % % % [zmin2, zmax2] = ft_getminmax(cfg, freq40);
% % % %
% % % % zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% % % %
% % % % zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
% % % % cfg = [];
% % % % cfg.zlim=zlim;
% % % % cfg.channel = freq3.label{w};
% % % % cfg.colormap=colormap(jet(256));
%%
%subplot(3,4,7)
%ft_singleplotTFR(cfg, freq30);
ax3 =subplot(3,4,7);
contourf(toy,freq3.freq,achis3,40,'linecolor','none');
colormap(jet(256));%narrow_colorbar();
set(gca,'clim',climdb,'ydir','normal','xlim',[-1 1])
c3=colorbar();
h3 = get(H3, 'position'); % get axes position
hn3= get(Hc3, 'Position'); % Colorbar Width for c1
x3 = get(ax3, 'position'); % get axes position
cw3= get(c3, 'Position'); % Colorbar Width for c1
cw3(3)=hn3(3);
cw3(1)=hn3(1);
set(c3,'Position',cw3)
x3(3)=h3(3);
set(ax3,'Position',x3)
% freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
title('High Gamma NO Learning')
%%
ax4 =subplot(3,4,8);
contourf(toy,freq4.freq,achis4,40,'linecolor','none');
colormap(jet(256));%narrow_colorbar();
set(gca,'clim',climdb,'ydir','normal','xlim',[-1 1])
c4=colorbar();
h4 = get(H4, 'position'); % get axes position
hn4= get(Hc4, 'Position'); % Colorbar Width for c1
x4 = get(ax4, 'position'); % get axes position
cw4= get(c4, 'Position'); % Colorbar Width for c1
cw4(3)=hn4(3);
cw4(1)=hn4(1);
set(c4,'Position',cw4)
x4(3)=h4(3);
set(ax4,'Position',x4)
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
%%%%%%%%%%%%%%ft_singleplotTFR(cfg, freq40);
title(strcat('High Gamma',{' '},labelconditions{iii-3}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
%%
[stats1]=stats_between_trials(freq3,freq4,label1,w);
% %
subplot(3,4,12)
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
grid minor
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
title(strcat(labelconditions{iii-3},' vs No Learning'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%% EXTRA STATISTICS
[stats1]=stats_between_trials(freq30,freq40,label1,w);
% %
subplot(3,4,11)
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
grid minor
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% % %title(strcat(labelconditions{iii},' vs No Learning'))
% % %%
[stats1]=stats_between_trials(freq10,freq20,label1,w);
% %
subplot(3,4,9)
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
grid minor
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
generate500.m
|
.m
|
CorticoHippocampal-master/Old_files/generate500.m
| 585 |
utf_8
|
ce8f06e9aba63819e4ed9e55b86cb622
|
function [p3,p5,cellx,cellr,cfs,f]=generate500(carajo,veamos, Bip17,S17,label1,label2)
fn=1000;
figure('units','normalized','outerposition',[0 0 1 1])
[TI,TN, cellx,cellr,to,tu]=win500(carajo,veamos,Bip17,S17);
[cellx,cellr]=clean(cellx,cellr);
% cellx{37}=cellx{36};
% cellr{37}=cellr{36};
[p3 p4]=eta500(cellx,cellr);
mtit(strcat(label1,' (',label2,')'),'fontsize',14,'color',[1 0 0],'position',[.5 1 ])
p5=p4;
% Wn2=[30/(fn/2)]; % Cutoff=500 Hz
% [b2,a2] = butter(3,Wn2); %Filter coefficients for LPF
% p4=filtfilt(b2,a2,p4);
barplot2_500(p4,p3)
[cfs,f]=barplot3_500(p4,p3)
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
getenvel.m
|
.m
|
CorticoHippocampal-master/Old_files/getenvel.m
| 598 |
utf_8
|
b9a3fe3fd94de4e13ad949491967bede
|
%% Envelope of q.
function [ww]=getenvel(q)
ww=cell(1,length(q));
for i=1:length(q)
w=q{i};
for j=1:4
envel=w(j,:);
ev(j,:)=envelope1(envel);
end
ww{i}=ev;
end
end
% %
% % %%
% % t=linspace(-2,2,length(checa));
% % plot(t,envelope1(checa,1000)); hold on;
% % plot(t,checa)
% % title('Envelope of ripple')
% % grid minor
% % xlabel('time')
% % %%
% % wacha=envelope2(linspace(-2,2,length(checa)),checa,1000);
% % %%
% % plot(); hold on;
% % plot(checa)
% % %%
% % aver=envelope1(w);
% % %%
% % veam=ww{1};
% % vea=q{1};
% % %%
% % plot(veam(4,:))
% % hold on
%% plot(vea(4,:))
|
github
|
Aleman-Z/CorticoHippocampal-master
|
getenvelbipolar.m
|
.m
|
CorticoHippocampal-master/Old_files/getenvelbipolar.m
| 192 |
utf_8
|
6cc37bcbdc2bbe39e6748c464ed65241
|
%% Envelope of q.
function [ww]=getenvelbipolar(q)
ww=cell(1,length(q));
for i=1:length(q)
w=q{i};
for j=1:3
envel=w(j,:);
ev(j,:)=envelope1(envel);
end
ww{i}=ev;
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
generate1000.m
|
.m
|
CorticoHippocampal-master/Old_files/generate1000.m
| 575 |
utf_8
|
4af37776c0e735ffed7cb1d5a881afdc
|
function [p3, p5,cellx,cellr]=generate1000(carajo,veamos, Bip17,S17,label1,label2)
fn=1000;
figure('units','normalized','outerposition',[0 0 1 1])
[TI,TN, cellx,cellr,to,tu]=win1000(carajo,veamos,Bip17,S17);
[cellx,cellr]=clean(cellx,cellr);
% cellx{37}=cellx{36};
% cellr{37}=cellr{36};
[p3 p4]=eta1000(cellx,cellr);
mtit(strcat(label1,' (',label2,')'),'fontsize',14,'color',[1 0 0],'position',[.5 1 ])
p5=p4;
% Wn2=[30/(fn/2)]; % Cutoff=500 Hz
% [b2,a2] = butter(3,Wn2); %Filter coefficients for LPF
% p4=filtfilt(b2,a2,p4);
barplot2_1000(p4,p3)
barplot3_1000(p4,p3)
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_prueba.m
|
.m
|
CorticoHippocampal-master/Figures/plot_inter_prueba.m
| 18,485 |
utf_8
|
b3f5ad90e17b03fa05b58b616251da68
|
%This one requires running data from Non Learning condition
function [h]=plot_inter_prueba(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,acer,block_time,NFF,mergebaseline,FiveHun,meth,rat26session3,rat27session3,notch,sanity,quinientos,outlie,varargin)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% ripple3=ripple_nl;
%ran=randi(length(p),100,1);
randrip=varargin;
randrip=cell2mat(randrip);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
%This one:
% % % [p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% if meth==3
% [p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),chtm);
% else
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro);
% end
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
%Ripple selection
% % if outlie==1
% % ache=max_outlier(p_nl);
% % p_nl=p_nl(ache);
% % q_nl=q_nl(ache);
% % end
% %
% % if quinientos==0
% % [ran_nl]=select_rip(p_nl,FiveHun);
% % p_nl=p_nl([ran_nl]);
% % q_nl=q_nl([ran_nl]);
% %
% % else
% % if iii~=2
% % [ran_nl]=select_quinientos(p_nl,length(randrip));
% % p_nl=p_nl([ran_nl]);
% % q_nl=q_nl([ran_nl]);
% % % ran=1:length(randrip);
% % end
% % end
%No outliers
ache=max_outlier(p_nl);
p_nl=p_nl(ache);
q_nl=q_nl(ache);
%Find strongests rip_nlp_nlles.
[p_nl,q_nl]=sort_rip(p_nl,q_nl);
%Select n strongest
switch Rat
case 24
n=550;
case 26
n=180;
case 27
n=326;
end
p_nl=p_nl(1:n);
q_nl=q_nl(1:n);
%timecell_nl=timecell_nl([ran_nl]);
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
if mergebaseline==1
%%
'MERGING BASELINES'
L1=length(p_nl);
NU{1}=p_nl;
QNU{1}=q_nl;
%% Other Baseline
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1}) %Baseline
% [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
if meth==1
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
end
if meth==2
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=median_std;
end
if meth==3
chtm=load('vq_loop2.mat');
chtm=chtm.vq;
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
if meth==4
[timeasleep]=find_thr_base;
ror=2000/timeasleep;
if acer==0
cd(strcat('/home/raleman/Dropbox/Figures/Figure2/',num2str(Rat)))
else
%cd(strcat('C:\Users\Welt Meister\Dropbox\Figures\Figure2\',num2str(Rat)))
cd(strcat('C:\Users\addri\Dropbox\Figures\Figure2\',num2str(Rat)))
end
if Rat==26
Base=[{'Baseline1'} {'Baseline2'}];
end
if Rat==26 && rat26session3==1
Base=[{'Baseline3'} {'Baseline2'}];
end
if Rat==27
Base=[{'Baseline2'} {'Baseline1'}];% We run Baseline 2 first, cause it is the one we prefer.
end
if Rat==27 && rat27session3==1
Base=[{'Baseline2'} {'Baseline3'}];% We run Baseline 2 first, cause it is the one we prefer.
end
base=2; %VERY IMPORTANT!
%openfig('Ripples_per_condition_best.fig')
openfig(strcat('Ripples_per_condition_',Base{base},'.fig'))
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes
ydata=dataObjs{2}(8).YData;
xdata=dataObjs{2}(8).XData;
% figure()
% plot(xdata,ydata)
chtm = interp1(ydata,xdata,ror);
close
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1})
%xo
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
%This seems incomplete:
% if meth==4
% [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
% CHTM2=[chtm chtm];
% end
if block_time==1
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,30,0);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
if block_time==2
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,60,30);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
%%
clear sig1_nl sig2_nl
if quinientos==0
[ran_nl]=select_rip(p_nl,FiveHun);
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
else
if iii~=2
[ran_nl]=select_quinientos(p_nl,length(randrip));
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
% ran=1:length(randrip);
end
end
%timecell_nl=timecell_nl([ran_nl]);
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
%%
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
NU{2}=p_nl;
QNU{2}=q_nl;
L2=length(p_nl);
amount=min([L1 L2]);
% p_nl(1:amount)=NU{1}(1:amount);
% p_nl(amount+1:2*amount)=NU{2}(1:amount);
p_nl(1:2*amount)=[NU{1}(1:amount) NU{1}(1:amount)];
p_nl(2:2:end)=[NU{2}(1:length(p_nl(2:2:end)))];
% q_nl(1:amount)=QNU{1}(1:amount);
% q_nl(amount+1:2*amount)=QNU{2}(1:amount);
q_nl(1:2*amount)=[QNU{1}(1:amount) QNU{1}(1:amount)];
q_nl(2:2:end)=[QNU{2}(1:length(q_nl(2:2:end)))];
end
clear sig1_nl sig2_nl
if length(p)>length(p_nl)
p=p(1:length(p_nl));
q=q(1:length(q_nl));
%timecell=timecell(1:length(p_nl));
end
% if length(p)<length(p_nl)
% p_nl=p_nl(1:length(p));
% q_nl=q_nl(1:length(q));
% %timecell_nl=timecell_nl(1:length(p));
% end
%Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,create_timecell(ro,length(p_nl)));
P2_nl=avg_samples(p_nl,create_timecell(ro,length(p_nl)));
P1=avg_samples(q,create_timecell(ro,length(p)));
P2=avg_samples(p,create_timecell(ro,length(p)));
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
%cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
%%
h(1)=subplot(3,4,1)
%plot(timecell_nl{1},P2_nl(w,:))
plot(cell2mat(create_timecell(ro,1)),P2_nl(w,:))
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('Wide Band No Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(3)=subplot(3,4,3)
plot(cell2mat(create_timecell(ro,1)),P1_nl(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('High Gamma No Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%%
h(2)=subplot(3,4,2)
plot(cell2mat(create_timecell(ro,1)),P2(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(4)=subplot(3,4,4)
plot(cell2mat(create_timecell(ro,1)),P1(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
clear P1 P2
%% Time Frequency plots
% Calculate Freq1 and Freq2
if ro==1200
toy = [-1.2:.01:1.2];
else
%toy = [-10.2:.1:10.2];
toy = [-10.2:.01:10.2];
end
%toy = [-1.2:.01:1.2];
% if length(p)>length(p_nl)
% p=p(1:length(p_nl));
% %timecell=timecell(1:length(p_nl));
% end
%
% if length(p)<length(p_nl)
% p_nl=p_nl(1:length(p));
% %timecell_nl=timecell_nl(1:length(p));
% end
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
h(5)=subplot(3,4,5)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band No Learning');
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
h(6)=subplot(3,4,6)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
ylim([0.5 30])
%%
if ro==1200
[stats]=stats_between_trials(freq1,freq2,label1,w);
else
[stats]=stats_between_trials10(freq1,freq2,label1,w);
end
%%
h(9)=subplot(3,4,10)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
g=title(strcat(labelconditions{iii},' vs No Learning'))
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%%
clear freq1 freq2 p_nl p
%Calculate Freq3 and Freq4
%toy=[-1:.01:1];
if ro==1200
toy=[-1:.01:1];
else
%toy=[-10:.1:10];
toy = [-10:.01:10];
end
if length(q)>length(q_nl)
q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
% timecell_nl=timecell_nl(1:length(q));
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
%U might want to uncomment this if you use a smaller step: (Memory purposes)
cfg = [];
cfg.channel = freq3.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq3);
[zmin2, zmax2] = ft_getminmax(cfg, freq4);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim; %U might want to uncomment this if you use a smaller step: (Memory purposes)
cfg.channel = freq3.label{w};
cfg.colormap=colormap(jet(256));
%%
h(7)=subplot(3,4,7)
ft_singleplotTFR(cfg, freq3);
% freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
g=title('High Gamma No Learning');
g.FontSize=12;
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%clear freq3
%%
%
h(8)=subplot(3,4,8);
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
ft_singleplotTFR(cfg, freq4);
g=title(strcat('High Gamma',{' '},labelconditions{iii}));
g.FontSize=12;
%title(strcat('High Gamma',{' '},labelconditions{iii}))
%xo
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%clear freq4
%%
% % % % % %
% % % % % % if ro==1200
% % % % % % [stats1]=stats_between_trials(freq3,freq4,label1,w);
% % % % % % else
% % % % % % [stats1]=stats_between_trials10(freq3,freq4,label1,w);
% % % % % % end
% % % % % %
% % % % % %
% % % % % % %% %
% % % % % %
% % % % % % h(10)=subplot(3,4,12);
% % % % % %
% % % % % % cfg = [];
% % % % % % cfg.channel = label1{2*w-1};
% % % % % % cfg.parameter = 'stat';
% % % % % % cfg.maskparameter = 'mask';
% % % % % % cfg.zlim = 'maxabs';
% % % % % % cfg.colorbar = 'yes';
% % % % % % cfg.colormap=colormap(jet(256));
% % % % % % %grid minor
% % % % % % % ft_singleplotTFR(cfg, stats1);
% % % % % % ft_singleplotTFR(cfg, stats1);
% % % % % %
% % % % % % %title('Ripple vs No Ripple')
% % % % % % g=title(strcat(labelconditions{iii},' vs No Learning'));
% % % % % % g.FontSize=12;
% % % % % % %title(strcat(labelconditions{iii},' vs No Learning'))
% % % % % % xlabel('Time (s)')
% % % % % % %ylabel('uV')
% % % % % % ylabel('Frequency (Hz)')
%% Pixel-based stats
zmap=stats_high(freq3,freq4,w);
h(10)=subplot(3,4,12);
colormap(jet(256))
zmap(zmap == 0) = NaN;
J=imagesc(freq3.time,freq3.freq,zmap)
xlabel('Time (s)'), ylabel('Frequency (Hz)')
%title('tf power map, thresholded')
set(gca,'xlim',xlim,'ydir','no')
% c=narrow_colorbar()
set(J,'AlphaData',~isnan(zmap))
c=narrow_colorbar()
c.YLim=[-max(abs(c.YLim)) max(abs(c.YLim))];
caxis([-max(abs(c.YLim)) max(abs(c.YLim))])
c=narrow_colorbar()
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%% EXTRA STATISTICS
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_conditions_33_cluster.m
|
.m
|
CorticoHippocampal-master/Figures/plot_inter_conditions_33_cluster.m
| 20,613 |
utf_8
|
53b3206829f4144aa17fb17cd8c682e1
|
%This one requires running data from Non Learning condition
function [h]=plot_inter_conditions_33_cluster(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,acer,block_time,NFF,mergebaseline,FiveHun,meth,rat26session3,rat27session3,notch,sanity,quinientos,outlie,varargin)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% ripple3=ripple_nl;
%ran=randi(length(p),100,1);
randrip=varargin;
randrip=cell2mat(randrip);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
%This one:
% % % [p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% if meth==3
% [p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),chtm);
% else
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro);
%,ripple_nl(level),CHTM2(level+1)
% end
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
%Ripple selection
% % if outlie==1
% % ache=max_outlier(p_nl);
% % p_nl=p_nl(ache);
% % q_nl=q_nl(ache);
% % end
% %
% % if quinientos==0
% % [ran_nl]=select_rip(p_nl,FiveHun);
% % p_nl=p_nl([ran_nl]);
% % q_nl=q_nl([ran_nl]);
% %
% % else
% % if iii~=2
% % [ran_nl]=select_quinientos(p_nl,length(randrip));
% % p_nl=p_nl([ran_nl]);
% % q_nl=q_nl([ran_nl]);
% % % ran=1:length(randrip);
% % end
% % end
%No outliers
ache=max_outlier(p_nl);
p_nl=p_nl(ache);
q_nl=q_nl(ache);
%Find strongests rip_nlp_nlles.
[p_nl,q_nl]=sort_rip(p_nl,q_nl);
%Select n strongest
% switch Rat
% case 24
% n=550;
% case 26
% n=180;
% case 27
% n=326;
% end
%
% p_nl=p_nl(1:n);
% q_nl=q_nl(1:n);
% switch Rat
% case 24
% % n=550;
% n=552;
% case 26
% % n=180;
% n=385;
% case 27
% % n=326;
% n=339;
% end
%
% p=p(1:n);
% q=q(1:n);
%timecell_nl=timecell_nl([ran_nl]);
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
if mergebaseline==1
%%
'MERGING BASELINES'
L1=length(p_nl);
NU{1}=p_nl;
QNU{1}=q_nl;
%% Other Baseline
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1}) %Baseline
% [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
if meth==1
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
end
if meth==2
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=median_std;
end
if meth==3
chtm=load('vq_loop2.mat');
chtm=chtm.vq;
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
if meth==4
[timeasleep]=find_thr_base;
ror=2000/timeasleep;
if acer==0
cd(strcat('/home/raleman/Dropbox/Figures/Figure2/',num2str(Rat)))
else
%cd(strcat('C:\Users\Welt Meister\Dropbox\Figures\Figure2\',num2str(Rat)))
cd(strcat('C:\Users\addri\Dropbox\Figures\Figure2\',num2str(Rat)))
end
if Rat==26
Base=[{'Baseline1'} {'Baseline2'}];
end
if Rat==26 && rat26session3==1
Base=[{'Baseline3'} {'Baseline2'}];
end
if Rat==27
Base=[{'Baseline2'} {'Baseline1'}];% We run Baseline 2 first, cause it is the one we prefer.
end
if Rat==27 && rat27session3==1
Base=[{'Baseline2'} {'Baseline3'}];% We run Baseline 2 first, cause it is the one we prefer.
end
base=2; %VERY IMPORTANT!
%openfig('Ripples_per_condition_best.fig')
openfig(strcat('Ripples_per_condition_',Base{base},'.fig'))
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes
ydata=dataObjs{2}(8).YData;
xdata=dataObjs{2}(8).XData;
% figure()
% plot(xdata,ydata)
chtm = interp1(ydata,xdata,ror);
close
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1})
%xo
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
%This seems incomplete:
% if meth==4
% [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
% CHTM2=[chtm chtm];
% end
if block_time==1
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,30,0);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
if block_time==2
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,60,30);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
%%
clear sig1_nl sig2_nl
if quinientos==0
[ran_nl]=select_rip(p_nl,FiveHun);
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
else
if iii~=2
[ran_nl]=select_quinientos(p_nl,length(randrip));
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
% ran=1:length(randrip);
end
end
%timecell_nl=timecell_nl([ran_nl]);
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
%%
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
NU{2}=p_nl;
QNU{2}=q_nl;
L2=length(p_nl);
amount=min([L1 L2]);
% p_nl(1:amount)=NU{1}(1:amount);
% p_nl(amount+1:2*amount)=NU{2}(1:amount);
p_nl(1:2*amount)=[NU{1}(1:amount) NU{1}(1:amount)];
p_nl(2:2:end)=[NU{2}(1:length(p_nl(2:2:end)))];
% q_nl(1:amount)=QNU{1}(1:amount);
% q_nl(amount+1:2*amount)=QNU{2}(1:amount);
q_nl(1:2*amount)=[QNU{1}(1:amount) QNU{1}(1:amount)];
q_nl(2:2:end)=[QNU{2}(1:length(q_nl(2:2:end)))];
end
clear sig1_nl sig2_nl
% % % %Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,create_timecell(ro,length(p_nl)));
P2_nl=avg_samples(p_nl,create_timecell(ro,length(p_nl)));
% % %
% % % P1=avg_samples(q,create_timecell(ro,length(p)));
% % % P2=avg_samples(p,create_timecell(ro,length(p)));
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
%cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
%%
h(1)=subplot(3,4,1)
%plot(timecell_nl{1},P2_nl(w,:))
plot(cell2mat(create_timecell(ro,1)),P2_nl(w,:))
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('Wide Band No Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(3)=subplot(3,4,3)
plot(cell2mat(create_timecell(ro,1)),P1_nl(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('High Gamma No Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%%
h(2)=subplot(3,4,2)
plot(cell2mat(create_timecell(ro,1)),P2(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(4)=subplot(3,4,4)
plot(cell2mat(create_timecell(ro,1)),P1(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
clear P1 P2
%% Time Frequency plots
% Calculate Freq1 and Freq2
if ro==1200
toy = [-1.2:.01:1.2];
else
%toy = [-10.2:.1:10.2];
toy = [-10.2:.01:10.2];
end
%toy = [-1.2:.01:1.2];
% if length(p)>length(p_nl)
% p=p(1:length(p_nl));
% %timecell=timecell(1:length(p_nl));
% end
%
% if length(p)<length(p_nl)
% p_nl=p_nl(1:length(p));
% %timecell_nl=timecell_nl(1:length(p));
% end
if length(p)>1000
p=p(1:1000);
end
if length(p_nl)>1000
p_nl=p_nl(1:1000);
end
%By not equalizing the sizes of p and p_nl we assure that the spectrogram
%for NL wont change throughout the sessions. There might be an issue with
%memory here. Would need to be solved using a max of i.e. 1000 ripples.
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
h(5)=subplot(3,4,5)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band No Learning');
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
h(6)=subplot(3,4,6)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
ylim([0.5 30])
%% Equalize number of ripples and recalculate freq1 and freq2
%Only when number of ripples between conditions are different.
if length(p)~=length(p_nl)
clear freq1 freq2
if length(p)>length(p_nl)
p=p(1:length(p_nl));
%q=q(1:length(q_nl));
%timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
%q_nl=q_nl(1:length(q));
%timecell_nl=timecell_nl(1:length(p));
end
%Due to memory reasons use top 1000
if length(p)>1000
p=p(1:1000);
p_nl=q_nl(1:1000);
end
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
end
%%
if ro==1200
[stats]=stats_between_trials(freq1,freq2,label1,w);
else
[stats]=stats_between_trials10(freq1,freq2,label1,w);
end
%%
h(9)=subplot(3,4,10)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
g=title(strcat(labelconditions{iii},' vs No Learning'))
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%%
clear freq1 freq2 p_nl p
%Calculate Freq3 and Freq4
%First they need to be calculated using all q and q_nl.
%toy=[-1:.01:1];
if ro==1200
toy=[-1:.01:1];
else
%toy=[-10:.1:10];
toy = [-10:.01:10];
end
% if length(q)>length(q_nl)
% q=q(1:length(q_nl));
% % timecell=timecell(1:length(q_nl));
% end
%
% if length(q)<length(q_nl)
% q_nl=q_nl(1:length(q));
% % timecell_nl=timecell_nl(1:length(q));
% end
if length(q)>1000
q=q(1:1000);
end
if length(q_nl)>1000
q_nl=q_nl(1:1000);
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
%U might want to uncomment this if you use a smaller step: (Memory purposes)
cfg = [];
cfg.channel = freq3.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq3);
[zmin2, zmax2] = ft_getminmax(cfg, freq4);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim; %U might want to uncomment this if you use a smaller step: (Memory purposes)
cfg.channel = freq3.label{w};
cfg.colormap=colormap(jet(256));
%%
h(7)=subplot(3,4,7)
ft_singleplotTFR(cfg, freq3);
% freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
g=title('High Gamma No Learning');
g.FontSize=12;
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%clear freq3
%%
%
h(8)=subplot(3,4,8);
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
ft_singleplotTFR(cfg, freq4);
g=title(strcat('High Gamma',{' '},labelconditions{iii}));
g.FontSize=12;
%title(strcat('High Gamma',{' '},labelconditions{iii}))
%xo
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%clear freq4
%%
% % % % % %
% % % % % % if ro==1200
% % % % % % [stats1]=stats_between_trials(freq3,freq4,label1,w);
% % % % % % else
% % % % % % [stats1]=stats_between_trials10(freq3,freq4,label1,w);
% % % % % % end
% % % % % %
% % % % % %
% % % % % % %% %
% % % % % %
% % % % % % h(10)=subplot(3,4,12);
% % % % % %
% % % % % % cfg = [];
% % % % % % cfg.channel = label1{2*w-1};
% % % % % % cfg.parameter = 'stat';
% % % % % % cfg.maskparameter = 'mask';
% % % % % % cfg.zlim = 'maxabs';
% % % % % % cfg.colorbar = 'yes';
% % % % % % cfg.colormap=colormap(jet(256));
% % % % % % %grid minor
% % % % % % % ft_singleplotTFR(cfg, stats1);
% % % % % % ft_singleplotTFR(cfg, stats1);
% % % % % %
% % % % % % %title('Ripple vs No Ripple')
% % % % % % g=title(strcat(labelconditions{iii},' vs No Learning'));
% % % % % % g.FontSize=12;
% % % % % % %title(strcat(labelconditions{iii},' vs No Learning'))
% % % % % % xlabel('Time (s)')
% % % % % % %ylabel('uV')
% % % % % % ylabel('Frequency (Hz)')
%% Equalize number of ripples between q and q_nl and recalculate freq3 and freq4
if length(q)~= length(q_nl)
clear freq3 freq4
if length(q)>length(q_nl)
q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
% timecell_nl=timecell_nl(1:length(q));
end
%Due to memory reasons use top 1000
if length(q)>1000
q=q(1:1000);
q_nl=q_nl(1:1000);
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
end
%% Pixel-based stats
% zmap=stats_high(freq3,freq4,w);
% h(10)=subplot(3,4,12);
%
% colormap(jet(256))
% zmap(zmap == 0) = NaN;
% J=imagesc(freq3.time,freq3.freq,zmap)
% xlabel('Time (s)'), ylabel('Frequency (Hz)')
% %title('tf power map, thresholded')
% set(gca,'xlim',xlim,'ydir','no')
% % c=narrow_colorbar()
% set(J,'AlphaData',~isnan(zmap))
% c=narrow_colorbar()
% c.YLim=[-max(abs(c.YLim)) max(abs(c.YLim))];
% caxis([-max(abs(c.YLim)) max(abs(c.YLim))])
% c=narrow_colorbar()
%
% g=title(strcat(labelconditions{iii},' vs No Learning'));
% g.FontSize=12;
%% EXTRA STATISTICS
[stats1]=stats_between_trials(freq3,freq4,label1,w);
% %
% subplot(3,4,11)
h(10)=subplot(3,4,12);
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
% grid minor
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
%title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_traces.m
|
.m
|
CorticoHippocampal-master/Figures/Figure2/plot_traces.m
| 2,071 |
utf_8
|
3564511915722ae505d5f2c0bb199583
|
% sig2 %63x1 Raw signal
% ti % 63x1 times
%
% veamos %Epochs where ripples were detected wrt sig2. 58x1
% cara %58x3; sample where they occur
% cara_times %58x3; times where they occur
%%
function plot_traces(sig2,veamos,cara,ti,amp_vec,iii,labelconditions,chtm,include_hpc,cara_hpc,veamos_hpc,chtm_hpc)
% amp_vec=[5 5];
%HPC
hpc_bout=sig2{1};
%PAR
par_bout=sig2{3};
if include_hpc==1
[C,ia,ib]=intersect(veamos{1},veamos_hpc{1});
%ia wrt veamos{1}
%ib wrt veamos_hpc{1}
hpc_bout=hpc_bout(C);
par_bout=par_bout(C);
hpc_ti=ti(C);
cara={cara{1}(ia,:)};
cara_hpc={cara_hpc{1}(ib,:)};
else %Only use epochs where ripples were detected.
hpc_bout=hpc_bout(veamos{1});
par_bout=par_bout(veamos{1});
hpc_ti=ti(veamos{1});
%
% cara{1}(n,:)
end
nrem_length=cellfun(@length,hpc_bout);
n=find((nrem_length==max(nrem_length))==1)%Index wrt veamos.
%% Plot traces
%HPC
%plot(hpc_ti{n}/60,amp_vec(1).*(zscore(hpc_bout{n}))+100)
plot(hpc_ti{n},amp_vec(1).*(zscore(hpc_bout{n}))+100)
hold on
%PAR
% plot(hpc_ti{n}/60,amp_vec(2).*(zscore(par_bout{n}))+200)
plot(hpc_ti{n},amp_vec(2).*(zscore(par_bout{n}))+200)
%xlabel('Time (Minutes)')
xlabel('Time (Seconds)')
title(['Largest NREM bout: ' labelconditions{iii} '. Thr:' num2str(chtm) ' uV'])
%%
times_rip=cara{1}(n,:);%Works.
times_rip=times_rip(1,3);%Ripple center.
times_rip=times_rip{1};
%%
if include_hpc==1
times_rip_hpc=cara_hpc{1}(n,:);
times_rip_hpc=times_rip_hpc(1,3);%Ripple center.
times_rip_hpc=times_rip_hpc{1};
end
% times_rip=times_rip/60;
%%
% y = ylim; % current y-axis limits
% plot([times_rip times_rip],[y(1) y(2)])
stem(times_rip,240.*ones(1,length(times_rip)))
hold on
stem(times_rip_hpc,240.*ones(1,length(times_rip_hpc)),'Color','blue')
yticks([100 200])
yticklabels({'HPC','PAR'})
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
merge_blocks.m
|
.m
|
CorticoHippocampal-master/Figures/Figure2/merge_blocks.m
| 2,442 |
utf_8
|
0380e2b910b01756e7b8b97721a9b2d3
|
function merge_blocks(rat,fq_range)
%Inputs:
%rat number
%frequency range
if fq_range==30
% Load saved figures
a=hgload('30Hz_block1_Hippocampus.fig');
b=hgload('30Hz_block2_Hippocampus.fig');
c=hgload('30Hz_block3_Hippocampus.fig');
end
if fq_range==300
% Load saved figures
a=hgload('300Hz_block1_Hippocampus.fig');
b=hgload('300Hz_block2_Hippocampus.fig');
c=hgload('300Hz_block3_Hippocampus.fig');
end
%
% Prepare subplots
allscreen()
h(1)=subplot(1,3,1);
if fq_range==30
xlim([0 30])
else
xlim([0 300])
end
grid on
set(gca, 'YScale', 'log')
title('Block 1', 'FontSize', 15)
xlabel('Frequency (Hz)', 'FontSize', 15)
ylabel('Power', 'FontSize', 15)
h(2)=subplot(1,3,2);
if fq_range==30
xlim([0 30])
else
xlim([0 300])
end
grid on
set(gca, 'YScale', 'log')
title('Block 2', 'FontSize', 15)
xlabel('Frequency (Hz)', 'FontSize', 15)
% ylabel('Power')
h(3)=subplot(1,3,3);
if fq_range==30
xlim([0 30])
else
xlim([0 300])
end
grid on
set(gca, 'YScale', 'log')
title('Block 3', 'FontSize', 15)
xlabel('Frequency (Hz)', 'FontSize', 15)
% ylabel('Power')
% Paste figures on the subplots
copyobj(allchild(get(a,'CurrentAxes')),h(1));
copyobj(allchild(get(b,'CurrentAxes')),h(2));
copyobj(allchild(get(c,'CurrentAxes')),h(3));
close (a)
close (b)
close (c)
% Add legends
if rat==24
l(1)=legend(h(1),'Baseline1','Baseline2','Baseline3','Baseline4','Plusmaze1','Plusmaze2')
l(2)=legend(h(2),'Baseline1','Baseline2','Baseline3','Baseline4','Plusmaze1','Plusmaze2')
l(3)=legend(h(3),'Baseline1','Baseline2','Baseline3','Baseline4','Plusmaze1','Plusmaze2')
else
l(1)=legend(h(1),'Baseline','Plusmaze','Novelty','Foraging')
l(2)=legend(h(2),'Baseline','Plusmaze','Novelty','Foraging')
l(3)=legend(h(3),'Baseline','Plusmaze','Novelty','Foraging')
end
if fq_range==300
string=strcat('300Hz_','time_blocks','_','Hippocampus','.eps');
saveas(gcf,string)
string=strcat('300Hz_','time_blocks','_','Hippocampus','.fig');
saveas(gcf,string)
end
if fq_range==30
string=strcat('30Hz_','time_blocks','_','Hippocampus','.eps');
saveas(gcf,string)
string=strcat('30Hz_','time_blocks','_','Hippocampus','.fig');
saveas(gcf,string)
end
close all
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
stats_vs_nl.m
|
.m
|
CorticoHippocampal-master/Figures/Figure3/stats_vs_nl.m
| 19,438 |
utf_8
|
1c93b28f7726688a3a45a36aa422441e
|
%This one requires running data from Non Learning condition
function [h]=stats_vs_nl(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,cara_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,acer,block_time,NFF,mergebaseline,FiveHun,meth,rat26session3,rat27session3,notch,sanity,quinientos,outlie,rat24base,datapath,varargin)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,cara_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,cara_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% ripple3=ripple_nl;
%ran=randi(length(p),100,1);
randrip=varargin;
randrip=cell2mat(randrip);
if meth==4
if Rat==24
%Remove artifact from Rat 24.
% run('rat24_december.m')
if w==2
p=p(1,end-60:end);
q=q(1,end-60:end);
else
if iii~=3
p=p(1,end-50:end);
q=q(1,end-50:end);
else
p=p(1,end-100:end-50);
q=q(1,end-100:end-50);
end
end
%PLUSMAZE PFC CORRECTION
if iii==2
for cn=1:length(p)
% p{cn}(3,:)= p{cn}(3,:).*0.195;
q{cn}(w,:)= q{cn}(w,:).*0.195;
end
if w==3
for cn=1:length(p)
q{cn}(w,:)= q{cn}(w,:).*0.195;
end
% else
% for cn=1:length(p)
% p{cn}(w,:)= p{cn}(w,:).*(1/0.195);
% end
end
end
% p=p(1,end-120:end-60);
% q=q(1,end-120:end-60);
end
end
if meth==5
if Rat==24
if iii==2
for cn=1:length(p)
q{cn}(w,:)= q{cn}(w,:)./0.195;
end
end
end
end
P1=avg_samples(q,create_timecell(ro,length(p)));
P2=avg_samples(p,create_timecell(ro,length(p)));
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(cara_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
%This one:
% % % [p_nl,q_nl,~,~,~,~]=getwin2(cara_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% if meth==3
% [p_nl,q_nl,~,~,~,~]=getwin2(cara_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),chtm);
% else
%[p_nl,q_nl,~,sos_nl]=getwin2(cara_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,ro);
[p_nl,q_nl,~,sos_nl]=getwin2(cara_nl{1},veamos_nl{1},sig1_nl,sig2_nl,ro);
%,ripple_nl(level),CHTM2(level+1)
% end
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
%Ripple selection
if Rat~=24 || meth~=4
[p_nl,q_nl,sos_nl]=ripple_selection(p_nl,q_nl,sos_nl,Rat,meth);
end
% [length(p_nl) length(p_nl2)]
% disp(sos_nl)
%xo
% if iii~=3
% p_nl=p_nl(1,end-60:end);
% q_nl=q_nl(1,end-60:end);
% else
% p_nl=p_nl(1,end-120:end-60);
% q_nl=q_nl(1,end-120:end-60);
% end
if Rat==24 && meth==4
p_nl=p_nl(1,end-120:end-60);
q_nl=q_nl(1,end-120:end-60);
end
% % if outlie==1
% % ache=max_outlier(p_nl);
% % p_nl=p_nl(ache);
% % q_nl=q_nl(ache);
% % end
% %
% % if quinientos==0
% % [ran_nl]=select_rip(p_nl,FiveHun);
% % p_nl=p_nl([ran_nl]);
% % q_nl=q_nl([ran_nl]);
% %
% % else
% % if iii~=2
% % [ran_nl]=select_quinientos(p_nl,length(randrip));
% % p_nl=p_nl([ran_nl]);
% % q_nl=q_nl([ran_nl]);
% % % ran=1:length(randrip);
% % end
% % end
% % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % %No outliers
% % % % % % % % % % % % % % % % % % % % % % % % ache=max_outlier(p_nl);
% % % % % % % % % % % % % % % % % % % % % % % % p_nl=p_nl(ache);
% % % % % % % % % % % % % % % % % % % % % % % % q_nl=q_nl(ache);
% % % % % % % % % % % % % % % % % % % % % % % % %Find strongests rip_nlp_nlles.
% % % % % % % % % % % % % % % % % % % % % % % % [p_nl,q_nl]=sort_rip(p_nl,q_nl);
%if Rat~=24 && rat24base~=2
if meth==4
if Rat~=24
%Select n strongest
switch Rat
case 24
n=550;
case 26
n=180;
case 27
n=326;
otherwise
error('Error found')
end
p_nl=p_nl(1:n);
q_nl=q_nl(1:n);
% % % % % % % % % % % % % % % %Need to add sos_nl
end
end
if meth==5
% if Rat~=24
%Select n strongest
switch Rat
case 24
n=426;
case 26
n=476;
case 27
n=850;
otherwise
error('Error found')
end
p_nl=p_nl(1:n);
q_nl=q_nl(1:n);
% % % % % % % % % % % % % % % %Need to add sos_nl
% end
end
%end
% switch Rat
% case 24
% % n=550;
% n=552;
% case 26
% % n=180;
% n=385;
% case 27
% % n=326;
% n=339;
% end
%
% p=p(1:n);
% q=q(1:n);
%timecell_nl=timecell_nl([ran_nl]);
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
if mergebaseline==1
merge_baselines
end
clear sig1_nl sig2_nl
% run('rat24_december_nl.m')
% % % %Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,create_timecell(ro,length(p_nl)));
P2_nl=avg_samples(p_nl,create_timecell(ro,length(p_nl)));
% % %
% % % P1=avg_samples(q,create_timecell(ro,length(p)));
% % % P2=avg_samples(p,create_timecell(ro,length(p)));
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
if acer==0
cd(strcat('/home/adrian/Documents/downsampled_NREM_data/',num2str(Rat)))
else
cd(strcat(datapath,'/',num2str(Rat)))
end
%cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
%%
h(1)=subplot(3,4,1)
plot(cell2mat(create_timecell(ro,1)),P2_nl(w,:))
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('Wide Band No Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(3)=subplot(3,4,3)
plot(cell2mat(create_timecell(ro,1)),P1_nl(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('High Gamma No Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%%
h(2)=subplot(3,4,2)
plot(cell2mat(create_timecell(ro,1)),P2(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(4)=subplot(3,4,4)
plot(cell2mat(create_timecell(ro,1)),P1(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
clear P1 P2
%% Time Frequency plots
% Calculate Freq1 and Freq2
if ro==1200
toy = [-1.2:.01:1.2];
else
%toy = [-10.2:.1:10.2];
toy = [-10.2:.01:10.2];
end
%toy = [-1.2:.01:1.2];
% if length(p)>length(p_nl)
% p=p(1:length(p_nl));
% %timecell=timecell(1:length(p_nl));
% end
%
% if length(p)<length(p_nl)
% p_nl=p_nl(1:length(p));
% %timecell_nl=timecell_nl(1:length(p));
% end
if length(p)>1000
p=p(1:1000);
end
if length(p_nl)>1000
p_nl=p_nl(1:1000);
end
%By not equalizing the sizes of p and p_nl we assure that the spectrogram
%for NL wont change throughout the sessions. There might be an issue with
%memory here. Would need to be solved using a max of i.e. 1000 ripples.
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
h(5)=subplot(3,4,5)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band No Learning');
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
h(6)=subplot(3,4,6)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
ylim([0.5 30])
%% Equalize number of ripples and recalculate freq1 and freq2
%Only when number of ripples between conditions are different.
if length(p)~=length(p_nl)
clear freq1 freq2
if length(p)>length(p_nl)
p=p(1:length(p_nl));
%q=q(1:length(q_nl));
%timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
%q_nl=q_nl(1:length(q));
%timecell_nl=timecell_nl(1:length(p));
end
%Due to memory reasons use top 1000
if length(p)>1000
p=p(1:1000);
p_nl=q_nl(1:1000);
end
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
end
%%
if ro==1200
[stats]=stats_between_trials(freq1,freq2,label1,w);
else
[stats]=stats_between_trials10(freq1,freq2,label1,w);
end
%%
h(9)=subplot(3,4,10)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
g=title(strcat(labelconditions{iii},' vs No Learning'))
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%%
clear freq1 freq2 p_nl p
%Calculate Freq3 and Freq4
%First they need to be calculated using all q and q_nl.
%toy=[-1:.01:1];
if ro==1200
toy=[-1:.01:1];
else
%toy=[-10:.1:10];
toy = [-10:.01:10];
end
% if length(q)>length(q_nl)
% q=q(1:length(q_nl));
% % timecell=timecell(1:length(q_nl));
% end
%
% if length(q)<length(q_nl)
% q_nl=q_nl(1:length(q));
% % timecell_nl=timecell_nl(1:length(q));
% end
if length(q)>1000
q=q(1:1000);
end
if length(q_nl)>1000
q_nl=q_nl(1:1000);
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
%U might want to uncomment this if you use a smaller step: (Memory purposes)
cfg = [];
cfg.channel = freq3.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq3);
[zmin2, zmax2] = ft_getminmax(cfg, freq4);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim; %U might want to uncomment this if you use a smaller step: (Memory purposes)
cfg.channel = freq3.label{w};
cfg.colormap=colormap(jet(256));
%%
h(7)=subplot(3,4,7)
ft_singleplotTFR(cfg, freq3);
% freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
g=title('High Gamma No Learning');
g.FontSize=12;
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%clear freq3
%%
%
h(8)=subplot(3,4,8);
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
ft_singleplotTFR(cfg, freq4);
g=title(strcat('High Gamma',{' '},labelconditions{iii}));
g.FontSize=12;
%title(strcat('High Gamma',{' '},labelconditions{iii}))
%xo
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%clear freq4
%%
% % % % % %
% % % % % % if ro==1200
% % % % % % [stats1]=stats_between_trials(freq3,freq4,label1,w);
% % % % % % else
% % % % % % [stats1]=stats_between_trials10(freq3,freq4,label1,w);
% % % % % % end
% % % % % %
% % % % % %
% % % % % % %% %
% % % % % %
% % % % % % h(10)=subplot(3,4,12);
% % % % % %
% % % % % % cfg = [];
% % % % % % cfg.channel = label1{2*w-1};
% % % % % % cfg.parameter = 'stat';
% % % % % % cfg.maskparameter = 'mask';
% % % % % % cfg.zlim = 'maxabs';
% % % % % % cfg.colorbar = 'yes';
% % % % % % cfg.colormap=colormap(jet(256));
% % % % % % %grid minor
% % % % % % % ft_singleplotTFR(cfg, stats1);
% % % % % % ft_singleplotTFR(cfg, stats1);
% % % % % %
% % % % % % %title('Ripple vs No Ripple')
% % % % % % g=title(strcat(labelconditions{iii},' vs No Learning'));
% % % % % % g.FontSize=12;
% % % % % % %title(strcat(labelconditions{iii},' vs No Learning'))
% % % % % % xlabel('Time (s)')
% % % % % % %ylabel('uV')
% % % % % % ylabel('Frequency (Hz)')
%% Equalize number of ripples between q and q_nl and recalculate freq3 and freq4
if length(q)~= length(q_nl)
clear freq3 freq4
if length(q)>length(q_nl)
q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
% timecell_nl=timecell_nl(1:length(q));
end
%Due to memory reasons use top 1000
if length(q)>1000
q=q(1:1000);
q_nl=q_nl(1:1000);
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
end
%% Pixel-based stats
zmap=stats_high(freq3,freq4,w);
h(10)=subplot(3,4,12);
colormap(jet(256))
zmap(zmap == 0) = NaN;
J=imagesc(freq3.time,freq3.freq,zmap)
xlabel('Time (s)'), ylabel('Frequency (Hz)')
%title('tf power map, thresholded')
set(gca,'xlim',xlim,'ydir','no')
% c=narrow_colorbar()
set(J,'AlphaData',~isnan(zmap))
c=narrow_colorbar()
c.YLim=[-max(abs(c.YLim)) max(abs(c.YLim))];
caxis([-max(abs(c.YLim)) max(abs(c.YLim))])
c=narrow_colorbar()
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%% EXTRA STATISTICS
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_high_improve.m
|
.m
|
CorticoHippocampal-master/Figures/Figure3/plot_inter_high_improve.m
| 11,372 |
utf_8
|
d9e296cf5061412e1653e566bf092543
|
%This one requires running data from Non Learning condition
function plot_inter_high_improve(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,acer,block_time,NFF,mergebaseline,FiveHun,meth,rat26session3,rat27session3,notch,sanity,quinientos,outlie,varargin)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% ripple3=ripple_nl;
%ran=randi(length(p),100,1);
randrip=varargin;
randrip=cell2mat(randrip);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
%This one:
% % % [p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% if meth==3
% [p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),chtm);
% else
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% end
if quinientos==0
if outlie==1
ache=max_outlier(p_nl);
p_nl=p_nl(ache);
q_nl=q_nl(ache);
end
[ran_nl]=select_rip(p_nl,FiveHun);
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
else
if iii~=2
[ran_nl]=select_quinientos(p_nl,length(randrip));
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
% ran=1:length(randrip);
end
end
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
if mergebaseline==1
%%
'MERGING BASELINES'
L1=length(p_nl);
NU{1}=p_nl;
QNU{1}=q_nl;
%% Other Baseline
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1}) %Baseline
% [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
if meth==1
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
end
if meth==2
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=median_std;
end
if meth==3
chtm=load('vq_loop2.mat');
chtm=chtm.vq;
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
if meth==4
[timeasleep]=find_thr_base;
ror=2000/timeasleep;
if acer==0
cd(strcat('/home/raleman/Dropbox/Figures/Figure2/',num2str(Rat)))
else
%cd(strcat('C:\Users\Welt Meister\Dropbox\Figures\Figure2\',num2str(Rat)))
cd(strcat('C:\Users\addri\Dropbox\Figures\Figure2\',num2str(Rat)))
end
if Rat==26
Base=[{'Baseline1'} {'Baseline2'}];
end
if Rat==26 && rat26session3==1
Base=[{'Baseline3'} {'Baseline2'}];
end
if Rat==27
Base=[{'Baseline2'} {'Baseline1'}];% We run Baseline 2 first, cause it is the one we prefer.
end
if Rat==27 && rat27session3==1
Base=[{'Baseline2'} {'Baseline3'}];% We run Baseline 2 first, cause it is the one we prefer.
end
base=2; %VERY IMPORTANT!
%openfig('Ripples_per_condition_best.fig')
openfig(strcat('Ripples_per_condition_',Base{base},'.fig'))
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes
ydata=dataObjs{2}(8).YData;
xdata=dataObjs{2}(8).XData;
% figure()
% plot(xdata,ydata)
chtm = interp1(ydata,xdata,ror);
close
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1})
%xo
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
%This seems incomplete:
% if meth==4
% [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
% CHTM2=[chtm chtm];
% end
if block_time==1
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,30,0);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
if block_time==2
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,60,30);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% [ran_nl]=select_rip(p_nl,FiveHun);
%
% p_nl=p_nl([ran_nl]);
% q_nl=q_nl([ran_nl]);
if quinientos==0
[ran_nl]=select_rip(p_nl,FiveHun);
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
else
if iii~=2
[ran_nl]=select_quinientos(p_nl,length(randrip));
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
% ran=1:length(randrip);
end
end
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
NU{2}=p_nl;
QNU{2}=q_nl;
L2=length(p_nl);
amount=min([L1 L2]);
% p_nl(1:amount)=NU{1}(1:amount);
% p_nl(amount+1:2*amount)=NU{2}(1:amount);
p_nl(1:2*amount)=[NU{1}(1:amount) NU{1}(1:amount)];
p_nl(2:2:end)=[NU{2}(1:length(p_nl(2:2:end)))];
% q_nl(1:amount)=QNU{1}(1:amount);
% q_nl(amount+1:2*amount)=QNU{2}(1:amount);
q_nl(1:2*amount)=[QNU{1}(1:amount) QNU{1}(1:amount)];
q_nl(2:2:end)=[QNU{2}(1:length(q_nl(2:2:end)))];
end
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
%cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%% Time Frequency plots
%Calculate Freq3 and Freq4
%toy=[-1:.01:1];
if ro==1200
toy=[-1:.01:1];
else
%toy=[-10:.1:10];
toy=[-10:.01:10];
end
if length(q)>length(q_nl)
q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
% timecell_nl=timecell_nl(1:length(q));
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
%%
zmap=stats_high(freq3,freq4,w);
subplot(3,4,12);
colormap(jet(256))
zmap(zmap == 0) = NaN;
J=imagesc(freq3.time,freq3.freq,zmap)
xlabel('Time (s)'), ylabel('Frequency (Hz)')
%title('tf power map, thresholded')
set(gca,'xlim',xlim,'ydir','no')
% c=narrow_colorbar()
set(J,'AlphaData',~isnan(zmap))
c=narrow_colorbar()
c.YLim=[-max(abs(c.YLim)) max(abs(c.YLim))];
caxis([-max(abs(c.YLim)) max(abs(c.YLim))])
c=narrow_colorbar()
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%%
%
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% %grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% g=title(strcat(labelconditions{iii},' vs No Learning'));
% g.FontSize=12;
% %title(strcat(labelconditions{iii},' vs No Learning'))
% xlabel('Time (s)')
% %ylabel('uV')
% ylabel('Frequency (Hz)')
%% EXTRA STATISTICS
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_conditions_33.m
|
.m
|
CorticoHippocampal-master/Figures/Figure3/plot_inter_conditions_33.m
| 22,436 |
utf_8
|
6625779897661565ba7447358c16edfc
|
%This one requires running data from Non Learning condition
function [h]=plot_inter_conditions_33(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,cara_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,acer,block_time,NFF,mergebaseline,FiveHun,meth,rat26session3,rat27session3,notch,sanity,quinientos,outlie,rat24base,datapath,varargin)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,cara_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,cara_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% ripple3=ripple_nl;
%ran=randi(length(p),100,1);
randrip=varargin;
randrip=cell2mat(randrip);
if Rat==24
%Remove artifact from Rat 24.
% run('rat24_december.m')
if w==2
p=p(1,end-60:end);
q=q(1,end-60:end);
else
if iii~=3
p=p(1,end-50:end);
q=q(1,end-50:end);
else
p=p(1,end-100:end-50);
q=q(1,end-100:end-50);
end
end
%PLUSMAZE PFC CORRECTION
if iii==2
for cn=1:length(p)
% p{cn}(3,:)= p{cn}(3,:).*0.195;
q{cn}(w,:)= q{cn}(w,:).*0.195;
end
if w==3
for cn=1:length(p)
q{cn}(w,:)= q{cn}(w,:).*0.195;
end
% else
% for cn=1:length(p)
% p{cn}(w,:)= p{cn}(w,:).*(1/0.195);
% end
end
end
% p=p(1,end-120:end-60);
% q=q(1,end-120:end-60);
end
P1=avg_samples(q,create_timecell(ro,length(p)));
P2=avg_samples(p,create_timecell(ro,length(p)));
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(cara_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
%This one:
% % % [p_nl,q_nl,~,~,~,~]=getwin2(cara_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% if meth==3
% [p_nl,q_nl,~,~,~,~]=getwin2(cara_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),chtm);
% else
%[p_nl,q_nl,~,sos_nl]=getwin2(cara_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,ro);
[p_nl,q_nl,~,sos_nl]=getwin2(cara_nl{1},veamos_nl{1},sig1_nl,sig2_nl,ro);
%,ripple_nl(level),CHTM2(level+1)
% end
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
%Ripple selection
if Rat~=24
[p_nl,q_nl,sos_nl]=ripple_selection(p_nl,q_nl,sos_nl,Rat);
end
% [length(p_nl) length(p_nl2)]
% disp(sos_nl)
%xo
% if iii~=3
% p_nl=p_nl(1,end-60:end);
% q_nl=q_nl(1,end-60:end);
% else
% p_nl=p_nl(1,end-120:end-60);
% q_nl=q_nl(1,end-120:end-60);
% end
if Rat==24
p_nl=p_nl(1,end-120:end-60);
q_nl=q_nl(1,end-120:end-60);
end
% % if outlie==1
% % ache=max_outlier(p_nl);
% % p_nl=p_nl(ache);
% % q_nl=q_nl(ache);
% % end
% %
% % if quinientos==0
% % [ran_nl]=select_rip(p_nl,FiveHun);
% % p_nl=p_nl([ran_nl]);
% % q_nl=q_nl([ran_nl]);
% %
% % else
% % if iii~=2
% % [ran_nl]=select_quinientos(p_nl,length(randrip));
% % p_nl=p_nl([ran_nl]);
% % q_nl=q_nl([ran_nl]);
% % % ran=1:length(randrip);
% % end
% % end
% % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % %No outliers
% % % % % % % % % % % % % % % % % % % % % % % % ache=max_outlier(p_nl);
% % % % % % % % % % % % % % % % % % % % % % % % p_nl=p_nl(ache);
% % % % % % % % % % % % % % % % % % % % % % % % q_nl=q_nl(ache);
% % % % % % % % % % % % % % % % % % % % % % % % %Find strongests rip_nlp_nlles.
% % % % % % % % % % % % % % % % % % % % % % % % [p_nl,q_nl]=sort_rip(p_nl,q_nl);
%if Rat~=24 && rat24base~=2
if Rat~=24
%Select n strongest
switch Rat
case 24
n=550;
case 26
n=180;
case 27
n=326;
otherwise
error('Error found')
end
p_nl=p_nl(1:n);
q_nl=q_nl(1:n);
% % % % % % % % % % % % % % % %Need to add sos_nl
end
%end
% switch Rat
% case 24
% % n=550;
% n=552;
% case 26
% % n=180;
% n=385;
% case 27
% % n=326;
% n=339;
% end
%
% p=p(1:n);
% q=q(1:n);
%timecell_nl=timecell_nl([ran_nl]);
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
if mergebaseline==1
%%
'MERGING BASELINES'
L1=length(p_nl);
NU{1}=p_nl;
QNU{1}=q_nl;
%% Other Baseline
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1}) %Baseline
% [sig1_nl,sig2_nl,ripple_nl,cara_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
if meth==1
[sig1_nl,sig2_nl,ripple_nl,cara_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
end
if meth==2
[sig1_nl,sig2_nl,ripple_nl,cara_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=median_std;
end
if meth==3
chtm=load('vq_loop2.mat');
chtm=chtm.vq;
[sig1_nl,sig2_nl,ripple_nl,cara_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
if meth==4
[timeasleep]=find_thr_base;
ror=2000/timeasleep;
if acer==0
cd(strcat('/home/raleman/Dropbox/Figures/Figure2/',num2str(Rat)))
else
%cd(strcat('C:\Users\Welt Meister\Dropbox\Figures\Figure2\',num2str(Rat)))
cd(strcat('C:\Users\addri\Dropbox\Figures\Figure2\',num2str(Rat)))
end
if Rat==26
Base=[{'Baseline1'} {'Baseline2'}];
end
if Rat==26 && rat26session3==1
Base=[{'Baseline3'} {'Baseline2'}];
end
if Rat==27
Base=[{'Baseline2'} {'Baseline1'}];% We run Baseline 2 first, cause it is the one we prefer.
end
if Rat==27 && rat27session3==1
Base=[{'Baseline2'} {'Baseline3'}];% We run Baseline 2 first, cause it is the one we prefer.
end
base=2; %VERY IMPORTANT!
%openfig('Ripples_per_condition_best.fig')
openfig(strcat('Ripples_per_condition_',Base{base},'.fig'))
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes
ydata=dataObjs{2}(8).YData;
xdata=dataObjs{2}(8).XData;
% figure()
% plot(xdata,ydata)
chtm = interp1(ydata,xdata,ror);
close
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1})
%xo
[sig1_nl,sig2_nl,ripple_nl,cara_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
%This seems incomplete:
% if meth==4
% [sig1_nl,sig2_nl,ripple_nl,cara_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
% CHTM2=[chtm chtm];
% end
if block_time==1
[cara_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,cara_nl,veamos_nl,30,0);
ripple_nl=sum(cellfun('length',cara_nl{1}(:,1)));
end
if block_time==2
[cara_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,cara_nl,veamos_nl,60,30);
ripple_nl=sum(cellfun('length',cara_nl{1}(:,1)));
end
%[p_nl,q_nl,~,~]=getwin2(cara_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
[p_nl,q_nl,~,~]=getwin2(cara_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,ro);
%%
clear sig1_nl sig2_nl
if quinientos==0
[ran_nl]=select_rip(p_nl,FiveHun);
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
else
if iii~=2
[ran_nl]=select_quinientos(p_nl,length(randrip));
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
% ran=1:length(randrip);
end
end
%timecell_nl=timecell_nl([ran_nl]);
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
%%
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
NU{2}=p_nl;
QNU{2}=q_nl;
L2=length(p_nl);
amount=min([L1 L2]);
% p_nl(1:amount)=NU{1}(1:amount);
% p_nl(amount+1:2*amount)=NU{2}(1:amount);
p_nl(1:2*amount)=[NU{1}(1:amount) NU{1}(1:amount)];
p_nl(2:2:end)=[NU{2}(1:length(p_nl(2:2:end)))];
% q_nl(1:amount)=QNU{1}(1:amount);
% q_nl(amount+1:2*amount)=QNU{2}(1:amount);
q_nl(1:2*amount)=[QNU{1}(1:amount) QNU{1}(1:amount)];
q_nl(2:2:end)=[QNU{2}(1:length(q_nl(2:2:end)))];
end
clear sig1_nl sig2_nl
% run('rat24_december_nl.m')
% % % %Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,create_timecell(ro,length(p_nl)));
P2_nl=avg_samples(p_nl,create_timecell(ro,length(p_nl)));
% % %
% % % P1=avg_samples(q,create_timecell(ro,length(p)));
% % % P2=avg_samples(p,create_timecell(ro,length(p)));
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat(datapath,num2str(Rat)))
end
%cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
%%
h(1)=subplot(3,4,1)
plot(cell2mat(create_timecell(ro,1)),P2_nl(w,:))
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('Wide Band No Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(3)=subplot(3,4,3)
plot(cell2mat(create_timecell(ro,1)),P1_nl(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('High Gamma No Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%%
h(2)=subplot(3,4,2)
plot(cell2mat(create_timecell(ro,1)),P2(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(4)=subplot(3,4,4)
plot(cell2mat(create_timecell(ro,1)),P1(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
clear P1 P2
%% Time Frequency plots
% Calculate Freq1 and Freq2
if ro==1200
toy = [-1.2:.01:1.2];
else
%toy = [-10.2:.1:10.2];
toy = [-10.2:.01:10.2];
end
%toy = [-1.2:.01:1.2];
% if length(p)>length(p_nl)
% p=p(1:length(p_nl));
% %timecell=timecell(1:length(p_nl));
% end
%
% if length(p)<length(p_nl)
% p_nl=p_nl(1:length(p));
% %timecell_nl=timecell_nl(1:length(p));
% end
if length(p)>1000
p=p(1:1000);
end
if length(p_nl)>1000
p_nl=p_nl(1:1000);
end
%By not equalizing the sizes of p and p_nl we assure that the spectrogram
%for NL wont change throughout the sessions. There might be an issue with
%memory here. Would need to be solved using a max of i.e. 1000 ripples.
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
h(5)=subplot(3,4,5)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band No Learning');
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
h(6)=subplot(3,4,6)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
ylim([0.5 30])
%% Equalize number of ripples and recalculate freq1 and freq2
%Only when number of ripples between conditions are different.
if length(p)~=length(p_nl)
clear freq1 freq2
if length(p)>length(p_nl)
p=p(1:length(p_nl));
%q=q(1:length(q_nl));
%timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
%q_nl=q_nl(1:length(q));
%timecell_nl=timecell_nl(1:length(p));
end
%Due to memory reasons use top 1000
if length(p)>1000
p=p(1:1000);
p_nl=q_nl(1:1000);
end
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
end
%%
if ro==1200
[stats]=stats_between_trials(freq1,freq2,label1,w);
else
[stats]=stats_between_trials10(freq1,freq2,label1,w);
end
%%
h(9)=subplot(3,4,10)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
g=title(strcat(labelconditions{iii},' vs No Learning'))
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%%
clear freq1 freq2 p_nl p
%Calculate Freq3 and Freq4
%First they need to be calculated using all q and q_nl.
%toy=[-1:.01:1];
if ro==1200
toy=[-1:.01:1];
else
%toy=[-10:.1:10];
toy = [-10:.01:10];
end
% if length(q)>length(q_nl)
% q=q(1:length(q_nl));
% % timecell=timecell(1:length(q_nl));
% end
%
% if length(q)<length(q_nl)
% q_nl=q_nl(1:length(q));
% % timecell_nl=timecell_nl(1:length(q));
% end
if length(q)>1000
q=q(1:1000);
end
if length(q_nl)>1000
q_nl=q_nl(1:1000);
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
%U might want to uncomment this if you use a smaller step: (Memory purposes)
cfg = [];
cfg.channel = freq3.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq3);
[zmin2, zmax2] = ft_getminmax(cfg, freq4);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim; %U might want to uncomment this if you use a smaller step: (Memory purposes)
cfg.channel = freq3.label{w};
cfg.colormap=colormap(jet(256));
%%
h(7)=subplot(3,4,7)
ft_singleplotTFR(cfg, freq3);
% freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
g=title('High Gamma No Learning');
g.FontSize=12;
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%clear freq3
%%
%
h(8)=subplot(3,4,8);
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
ft_singleplotTFR(cfg, freq4);
g=title(strcat('High Gamma',{' '},labelconditions{iii}));
g.FontSize=12;
%title(strcat('High Gamma',{' '},labelconditions{iii}))
%xo
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%clear freq4
%%
% % % % % %
% % % % % % if ro==1200
% % % % % % [stats1]=stats_between_trials(freq3,freq4,label1,w);
% % % % % % else
% % % % % % [stats1]=stats_between_trials10(freq3,freq4,label1,w);
% % % % % % end
% % % % % %
% % % % % %
% % % % % % %% %
% % % % % %
% % % % % % h(10)=subplot(3,4,12);
% % % % % %
% % % % % % cfg = [];
% % % % % % cfg.channel = label1{2*w-1};
% % % % % % cfg.parameter = 'stat';
% % % % % % cfg.maskparameter = 'mask';
% % % % % % cfg.zlim = 'maxabs';
% % % % % % cfg.colorbar = 'yes';
% % % % % % cfg.colormap=colormap(jet(256));
% % % % % % %grid minor
% % % % % % % ft_singleplotTFR(cfg, stats1);
% % % % % % ft_singleplotTFR(cfg, stats1);
% % % % % %
% % % % % % %title('Ripple vs No Ripple')
% % % % % % g=title(strcat(labelconditions{iii},' vs No Learning'));
% % % % % % g.FontSize=12;
% % % % % % %title(strcat(labelconditions{iii},' vs No Learning'))
% % % % % % xlabel('Time (s)')
% % % % % % %ylabel('uV')
% % % % % % ylabel('Frequency (Hz)')
%% Equalize number of ripples between q and q_nl and recalculate freq3 and freq4
if length(q)~= length(q_nl)
clear freq3 freq4
if length(q)>length(q_nl)
q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
% timecell_nl=timecell_nl(1:length(q));
end
%Due to memory reasons use top 1000
if length(q)>1000
q=q(1:1000);
q_nl=q_nl(1:1000);
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
end
%% Pixel-based stats
zmap=stats_high(freq3,freq4,w);
h(10)=subplot(3,4,12);
colormap(jet(256))
zmap(zmap == 0) = NaN;
J=imagesc(freq3.time,freq3.freq,zmap)
xlabel('Time (s)'), ylabel('Frequency (Hz)')
%title('tf power map, thresholded')
set(gca,'xlim',xlim,'ydir','no')
% c=narrow_colorbar()
set(J,'AlphaData',~isnan(zmap))
c=narrow_colorbar()
c.YLim=[-max(abs(c.YLim)) max(abs(c.YLim))];
caxis([-max(abs(c.YLim)) max(abs(c.YLim))])
c=narrow_colorbar()
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%% EXTRA STATISTICS
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
gui_parameters.m
|
.m
|
CorticoHippocampal-master/Figures/Figure3/gui_parameters.m
| 16,398 |
utf_8
|
c68a674752851c6b9b949e563a721005
|
function varargout = gui_parameters(varargin)
% GUI_PARAMETERS MATLAB code for gui_parameters.fig
% GUI_PARAMETERS, by itself, creates a new GUI_PARAMETERS or raises the existing
% singleton*.
%
% H = GUI_PARAMETERS returns the handle to a new GUI_PARAMETERS or the handle to
% the existing singleton*.
%
% GUI_PARAMETERS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_PARAMETERS.M with the given input arguments.
%
% GUI_PARAMETERS('Property','Value',...) creates a new GUI_PARAMETERS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_parameters_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_parameters_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help gui_parameters
% Last Modified by GUIDE v2.5 11-Dec-2019 15:58:25
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_parameters_OpeningFcn, ...
'gui_OutputFcn', @gui_parameters_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before gui_parameters is made visible.
function gui_parameters_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to gui_parameters (see VARARGIN)
% Choose default command line output for gui_parameters
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
%Default parameters
RAT=1;
mergebaseline=0; %Make sure baselines's while loop condition is never equal to 2.
%Maximum number of ripples.
FiveHun=2; % Options: 0 all, 1 current (500), 2 1000?
%Swaps baseline sessions for testing purposes:
rat26session3=0; %Swaps session 1 for session 3 on Rat 26.
rat27session3=0; %Swaps session 1 for session 3 on Rat 26.
%Controls for Spectrograms: 0:NO, 1:YES.
rippletable=0; %Generate table with ripple information.
sanity=0; %Sanity check.
quinientos=0;
outlie=0; %More aggressive outlier detection.
acer=1;
win_ten=0;
equal_num=0;
win_stats=0;
rip_hist=0;
view_traces=0;
% sanity=1: This control test consists on selecting the same n random number of ripples among conditions. Since Plusmaze generates less ripples, this condition defines the value of n.
%
% quinientos=1: Similar to control above but this one makes sure to take the top 500 ripples instead of their random version. Could be more vulnerable to outliers.
%
% outlie=1: The use of this control activates a more agressive detection of outliers.
%For testing purposes only.
rat26session3=0; %Swaps session 1 for session 3 on Rat 26.
rat27session3=0; %Swaps session 1 for session 3 on Rat 26.
assignin('base', 'acer', acer)
assignin('base', 'RAT', RAT)
assignin('base', 'mergebaseline', mergebaseline)
assignin('base', 'FiveHun', FiveHun)
assignin('base', 'rat26session3', rat26session3)
assignin('base', 'rat27session3', rat27session3)
assignin('base', 'rippletable', rippletable)
assignin('base', 'sanity', sanity)
assignin('base', 'quinientos', quinientos)
assignin('base', 'outlie', outlie)
assignin('base', 'win_ten', win_ten)
assignin('base', 'equal_num', equal_num)
assignin('base', 'rat26session3', rat26session3)
assignin('base', 'rat27session3', rat27session3)
assignin('base', 'win_stats', win_stats)
assignin('base', 'rip_hist', rip_hist)
assignin('base', 'view_traces', view_traces)
% UIWAIT makes gui_parameters wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_parameters_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
% push_but=(handles.pushbutton1.Value)
% while ~push_but
% pause(10)
uiwait
% end
varargout{1} = handles.output;
% pause(8) %Wait for 8 seconds.
%close all
%varargout{1} = getappdata(hObject,'result');
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Val=get(hObject,'String');
val=get(hObject,'Value');
if strcmp(Val{val},'No')
acer=0;
else
acer=1;
end
assignin('base', 'acer', acer)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Val=get(hObject,'String');
val=get(hObject,'Value');
if strcmp(Val{val},'1000')
FiveHun=2;
end
if strcmp(Val{val},'All')
FiveHun=0;
end
if strcmp(Val{val},'500')
FiveHun=1;
end
assignin('base', 'FiveHun', FiveHun)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu2
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
Val=get(hObject,'String');
val=get(hObject,'Value');
if strcmp(Val{val},'No')
mergebaseline=0;
else
mergebaseline=1;
end
assignin('base', 'mergebaseline', mergebaseline)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu3
% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu4.
function popupmenu4_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Val=get(hObject,'String');
val=get(hObject,'Value');
if strcmp(Val{val},'No')
sanity=0;
else
sanity=1;
end
assignin('base', 'sanity', sanity)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu4 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu4
% --- Executes during object creation, after setting all properties.
function popupmenu4_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu5.
function popupmenu5_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Val=get(hObject,'String');
val=get(hObject,'Value');
if strcmp(Val{val},'No')
quinientos=0;
else
quinientos=1;
end
assignin('base', 'quinientos', quinientos)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu5 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu5
% --- Executes during object creation, after setting all properties.
function popupmenu5_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu6.
function popupmenu6_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Val=get(hObject,'String');
val=get(hObject,'Value');
if strcmp(Val{val},'No')
outlie=0;
else
outlie=1;
end
assignin('base', 'outlie', outlie)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu6 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu6
% --- Executes during object creation, after setting all properties.
function popupmenu6_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
cl_button=get(hObject,'Value');
if cl_button==1
close all
end
% close all
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
RAT=get(hObject,'Value');
assignin('base', 'RAT', RAT)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject handle to checkbox2 (see GCBO)
win_ten=hObject.Value;
win_comp=0;
assignin('base', 'win_ten', win_ten)
assignin('base', 'win_comp', win_comp)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox2
% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
% hObject handle to checkbox3 (see GCBO)
win_ten=hObject.Value;
win_comp=1;
assignin('base', 'win_ten', win_ten)
assignin('base', 'win_comp', win_comp)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox3
% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
equal_num=hObject.Value;
assignin('base', 'equal_num', equal_num)
% Hint: get(hObject,'Value') returns toggle state of radiobutton4
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rippletable=hObject.Value;
assignin('base', 'rippletable', rippletable)
% --- Executes on button press in radiobutton5.
function radiobutton5_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
win_stats=hObject.Value;
assignin('base', 'win_stats', win_stats)
% --- Executes on button press in checkbox6.
function checkbox6_Callback(hObject, eventdata, handles)
% hObject handle to checkbox6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rip_hist=hObject.Value;
assignin('base', 'rip_hist', rip_hist)
% Hint: get(hObject,'Value') returns toggle state of checkbox6
% --- Executes on button press in checkbox7.
function checkbox7_Callback(hObject, eventdata, handles)
% hObject handle to checkbox7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
view_traces=hObject.Value;
assignin('base', 'view_traces', view_traces)
% Hint: get(hObject,'Value') returns toggle state of checkbox7
|
github
|
Aleman-Z/CorticoHippocampal-master
|
axis_among_conditions2.m
|
.m
|
CorticoHippocampal-master/Figures/Figure3/axis_among_conditions2.m
| 10,860 |
utf_8
|
6eaf2d44e582671f7f9dccb071525271
|
% close all
% clear all
function axis_among_conditions2(Rat,selpath,ldura)
%acer=1;
labelconditions=[
{
'Baseline'}
'PlusMaze'
'Novelty'
'Foraging'
];
c = categorical(labelconditions);
labelconditions=[
{
'Baseline'}
'PlusMaze'
'Novelty'
'Foraging'
];
label1=cell(7,1);
label1{1}='HPC';
label1{2}='HPC';
label1{3}='Parietal';
label1{4}='Parietal';
label1{5}='PFC';
label1{6}='PFC';
label1{7}='Reference';
DUR{1}='1sec';
DUR{2}='10sec';
Block{1}='complete';
Block{2}='block1';
Block{3}='block2';
sanity=0;
quinientos=0;
% ldura=1; %1 for 1 sec, 2 for 10 sec.
outlie=1;
%%
%addingpath(acer)
% if acer==0
% addpath('/home/raleman/Documents/MATLAB/analysis-tools-master'); %Open Ephys data loader.
% addpath(genpath('/home/raleman/Documents/GitHub/CorticoHippocampal'))
% addpath(genpath('/home/raleman/Documents/GitHub/ADRITOOLS'))
% addpath('/home/raleman/Documents/internship')
% addpath /home/raleman/Documents/internship/fieldtrip-master/
% InitFieldtrip()
% else
% addpath('D:\internship\analysis-tools-master'); %Open Ephys data loader.
% addpath(genpath('C:\Users\addri\Documents\internship\CorticoHippocampal'))
% addpath(genpath('C:\Users\addri\Documents\GitHub\ADRITOOLS'))
%
% addpath D:\internship\fieldtrip-master
% InitFieldtrip()
% end
%%
%for Rat=3:3
cd(selpath)
if ldura==2
cd('..')
cd('10sec')
end
% if Rat==1
%
% if acer==0
% cd('/home/raleman/Dropbox/Figures/Figure3/26/Newest_first')
% if ldura==2
% cd('..')
% cd('10sec')
% end
% else
% %cd(strcat('C:\Users\Welt Meister\Dropbox\Figures\Figure2\',num2str(Rat)))
% cd('C:/Users/addri/Dropbox/Figures/Figure3/26/Newest_first')
% if ldura==2
% cd('..')
% cd('10sec')
% end
% end
% end
%
% if Rat==2
%
% if acer==0
% cd('/home/raleman/Dropbox/Figures/Figure3/27/Newest_first')
% if ldura==2
% cd('..')
% cd('10sec')
% end
% else
% %cd(strcat('C:\Users\Welt Meister\Dropbox\Figures\Figure2\',num2str(Rat)))
% cd('C:/Users/addri/Dropbox/Figures/Figure3/27/Newest_first')
% if ldura==2
% cd('..')
% cd('10sec')
% end
% end
% end
%
% if Rat==3
% if acer==0
% cd('/home/raleman/Dropbox/Figures/Figure3/24/LaMasMejor')
% else
% cd('C:/Users/addri/Dropbox/Figures/Figure3/24/LaMasMejor')
% end
% end
%xo
%%
for dura=ldura:ldura
for block_time=0:0
for w=2:3
for iii=2:length(labelconditions)
% if sanity~=1
% if outlie==1
% string=strcat('Spec2_outliers_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
% else
% string=strcat('Spec2_outliers_control_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
% end
%
% else
% if quinientos==1
% string=strcat('Control_500_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
%
% else
% string=strcat('Control_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
%
% end
% end
string=strcat('Spec2_outliers_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
%xo
openfig(string)
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes
VER1(iii-1,:)=[axesObjs(13).YLim];
VER2(iii-1,:)=[axesObjs(14).YLim];
end
mVER1=[ min(VER1(:,1)) max(VER1(:,2))];
mVER2=[ min(VER2(:,1)) max(VER2(:,2))];
close all
%xo
for iii=2:length(labelconditions)
% if sanity~=1
% if outlie==1
% string=strcat('Spec2_outliers_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
% else
% string=strcat('Spec2_outliers_control_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
% end
%
% else
% if quinientos==1
% string=strcat('Control_500_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
% else
% string=strcat('Control_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
% end
% end
string=strcat('Spec2_outliers_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
openfig(string)
%figure(1)
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes
axesObjs(13).YLim=mVER1;
axesObjs(15).YLim=mVER1;
axesObjs(14).YLim=mVER2;
axesObjs(16).YLim=mVER2;
%%
% figure()
% nx=dataObjs{13}.XData; %Same for all
% nv1=(dataObjs{16}.YData);
% nv2=(dataObjs{14}.YData);
% nv3=(dataObjs{15}.YData);
% nv4=(dataObjs{13}.YData);
% %
% subplot(3,4,5)
% I=imagesc(nv1);
% caxis(mVER1)
% %colormap(jet(256))
% c1=narrow_colorbar()
% % cax1=caxis;% -1.6465 8.3123
% % c1.YLim=[do(1) do(4)];
% I.CDataMapping = 'scaled';
% gg=gca;
% gg.YTickLabel=flip(gg.YTickLabel);
% colormap(jet(256))
% %set(gca,'YDir','normal')
% c1=narrow_colorbar()
% gg.XTick=[1 50 100 150 200];
% if dura==2
% gg.XTickLabel=[{-10} {-5} {0} {5} {10}];
% else
% gg.XTickLabel=[{-1} {-0.5} {0} {0.5} {1}];
% end
% xlabel('Time (s)')
% % title(strcat('Wide Band','{ }',lab))
% ylabel('Frequency (Hz)')
% title('Wide Band No Learning')
% %
% i=I.CData;
% set(gca, 'YTick',[1 size(i,1)/2/3 size(i,1)/2/3*2 size(i,1)/2 size(i,1)/2/3*4 size(i,1)/2/3*5] , 'YTickLabel', [30 25 20 15 10 5]) % 20 ticks
%%
%figure()
% nv=(dataObjs{5}.CData);
% subplot(3,4,6)
% I=imagesc(nv2)
% caxis(mVER1)
% %colormap(jet(256))
% c1=narrow_colorbar()
% % cax1=caxis;% -1.6465 8.3123
% % c1.YLim=[do(1) do(4)];
% I.CDataMapping = 'scaled';
% gg=gca;
% gg.YTickLabel=flip(gg.YTickLabel);
% colormap(jet(256))
% %set(gca,'YDir','normal')
% c1=narrow_colorbar()
% gg.XTick=[1 50 100 150 200];
% %gg.XTickLabel=[{-1} {-0.5} {0} {0.5} {1}];
% if dura==2
% gg.XTickLabel=[{-10} {-5} {0} {5} {10}];
% else
% gg.XTickLabel=[{-1} {-0.5} {0} {0.5} {1}];
% end
%
% xlabel('Time (s)')
% title(strcat('Wide Band','{ }',labelconditions{iii}))
% ylabel('Frequency (Hz)')
%
% %
% i=I.CData;
% set(gca, 'YTick',[1 size(i,1)/2/3 size(i,1)/2/3*2 size(i,1)/2 size(i,1)/2/3*4 size(i,1)/2/3*5] , 'YTickLabel', [30 25 20 15 10 5]) % 20 ticks
%%
%figure()
% nv=(dataObjs{9}.CData);
% subplot(3,4,7)
% I=imagesc(flip(nv3,1))
% caxis(mVER2)
% %colormap(jet(256))
% c1=narrow_colorbar()
% % cax1=caxis;% -1.6465 8.3123
% % c1.YLim=[do(1) do(4)];
% I.CDataMapping = 'scaled';
% gg=gca;
% gg.YTickLabel=flip(gg.YTickLabel);
% colormap(jet(256))
% %set(gca,'YDir','normal')
% c1=narrow_colorbar()
% gg.XTick=[1 50 100 150 200];
% %gg.XTickLabel=[{-1} {-0.5} {0} {0.5} {1}];
% if dura==2
% gg.XTickLabel=[{-10} {-5} {0} {5} {10}];
% else
% gg.XTickLabel=[{-1} {-0.5} {0} {0.5} {1}];
% end
%
% xlabel('Time (s)')
% % title(strcat('Wide Band','{ }',lab))
% ylabel('Frequency (Hz)')
% title('High Gamma No Learning')
%
% %
% i=I.CData;
% set(gca, 'YTick',[1 size(i,1)/4 size(i,1)/2 size(i,1)/4*3 size(i,1)] , 'YTickLabel', [300 250 200 150 100]) % 20 ticks
%%
%%
% figure()
% nv=(dataObjs{7}.CData);
% subplot(3,4,8)
% I=imagesc(flip(nv4,1))
% caxis(mVER2)
% %colormap(jet(256))
% c1=narrow_colorbar()
% % cax1=caxis;% -1.6465 8.3123
% % c1.YLim=[do(1) do(4)];
% I.CDataMapping = 'scaled';
% gg=gca;
% gg.YTickLabel=flip(gg.YTickLabel);
% colormap(jet(256))
% %set(gca,'YDir','normal')
% c1=narrow_colorbar()
% gg.XTick=[1 50 100 150 200];
% %gg.XTickLabel=[{-1} {-0.5} {0} {0.5} {1}];
% if dura==2
% gg.XTickLabel=[{-10} {-5} {0} {5} {10}];
% else
% gg.XTickLabel=[{-1} {-0.5} {0} {0.5} {1}];
% end
%
% xlabel('Time (s)')
% % title(strcat('Wide Band','{ }',lab))
% title(strcat('High Gamma','{ }',labelconditions{iii}))
% ylabel('Frequency (Hz)')
% %
% i=I.CData;
% set(gca, 'YTick',[1 size(i,1)/4 size(i,1)/2 size(i,1)/4*3 size(i,1)] , 'YTickLabel', [300 250 200 150 100]) % 20 ticks
%xo
if sanity ~=1
if outlie==1
string=strcat('Spec3_outliers_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.pdf');
figure_function(gcf,[],string,[]);
string=strcat('Spec3_outliers_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.eps');
print(string,'-depsc')
string=strcat('Spec3_outliers_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
saveas(gcf,string)
else
string=strcat('Spec3_outliers_control_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.pdf');
figure_function(gcf,[],string,[]);
string=strcat('Spec3_outliers_control_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.eps');
print(string,'-depsc')
string=strcat('Spec3_outliers_control_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
saveas(gcf,string)
end
else
if quinientos==1
string=strcat('Control2_500_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.pdf');
figure_function(gcf,[],string,[]);
string=strcat('Control2_500_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.eps');
print(string,'-depsc')
string=strcat('Control2_500_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
saveas(gcf,string)
else
string=strcat('Control2_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.pdf');
figure_function(gcf,[],string,[]);
string=strcat('Control2_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.eps');
print(string,'-depsc')
string=strcat('Control2_',labelconditions{iii},'_',label1{2*w-1},'_',Block{block_time+1},'_',DUR{dura},'.fig');
saveas(gcf,string)
end
end
end
%xo
%%
end
end
end
close all
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_conditions_33_high.m
|
.m
|
CorticoHippocampal-master/Figures/Figure3/plot_inter_conditions_33_high.m
| 17,234 |
utf_8
|
e0938e176eb984180648f5ab5d37be8c
|
%This one requires running data from Non Learning condition
function [h]=plot_inter_conditions_33_high(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,acer,block_time,NFF,mergebaseline,FiveHun,meth,rat26session3,rat27session3,notch,sanity,varargin)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% ripple3=ripple_nl;
%ran=randi(length(p),100,1);
randrip=varargin;
randrip=cell2mat(randrip);
%xo
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
%This one:
% % % [p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% if meth==3
% [p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),chtm);
% else
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% end
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
[ran_nl]=select_rip(p_nl,FiveHun);
%
% av=cat(1,p_nl{1:end});
% %av=cat(1,q_nl{1:end});
% av=av(1:3:end,:); %Only Hippocampus
%
% %AV=max(av.');
% %[B I]= maxk(AV,1000);
%
% %AV=max(av.');
% %[B I]= maxk(max(av.'),1000);
%
%
% [ach]=max(av.');
% achinga=sort(ach,'descend');
% %achinga=achinga(1:1000);
% if length(achinga)>1000
% if Rat==24
% achinga=achinga(6:1005);
% else
% achinga=achinga(1:1000);
% end
% end
%
% B=achinga;
% I=nan(1,length(B));
% for hh=1:length(achinga)
% % I(hh)= min(find(ach==achinga(hh)));
% I(hh)= find(ach==achinga(hh),1,'first');
% end
%
%
% [ajal ind]=unique(B);
% if length(ajal)>500
% ajal=ajal(end-499:end);
% ind=ind(end-499:end);
% end
% dex=I(ind);
%
% ran_nl=dex.';
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
%timecell_nl=timecell_nl([ran_nl]);
if sanity==1
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
if mergebaseline==1
%%
'MERGING BASELINES'
L1=length(p_nl);
NU{1}=p_nl;
QNU{1}=q_nl;
%% Other Baseline
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1}) %Baseline
% [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
if meth==1
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
end
if meth==2
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=median_std;
end
if meth==3
chtm=load('vq_loop2.mat');
chtm=chtm.vq;
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
if meth==4
[timeasleep]=find_thr_base;
ror=2000/timeasleep;
if acer==0
cd(strcat('/home/raleman/Dropbox/Figures/Figure2/',num2str(Rat)))
else
%cd(strcat('C:\Users\Welt Meister\Dropbox\Figures\Figure2\',num2str(Rat)))
cd(strcat('C:\Users\addri\Dropbox\Figures\Figure2\',num2str(Rat)))
end
if Rat==26
Base=[{'Baseline1'} {'Baseline2'}];
end
if Rat==26 && rat26session3==1
Base=[{'Baseline3'} {'Baseline2'}];
end
if Rat==27
Base=[{'Baseline2'} {'Baseline1'}];% We run Baseline 2 first, cause it is the one we prefer.
end
if Rat==27 && rat27session3==1
Base=[{'Baseline2'} {'Baseline3'}];% We run Baseline 2 first, cause it is the one we prefer.
end
base=2; %VERY IMPORTANT!
%openfig('Ripples_per_condition_best.fig')
openfig(strcat('Ripples_per_condition_',Base{base},'.fig'))
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes
ydata=dataObjs{2}(8).YData;
xdata=dataObjs{2}(8).XData;
% figure()
% plot(xdata,ydata)
chtm = interp1(ydata,xdata,ror);
close
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1})
%xo
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
%This seems incomplete:
% if meth==4
% [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
% CHTM2=[chtm chtm];
% end
if block_time==1
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,30,0);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
if block_time==2
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,60,30);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
[ran_nl]=select_rip(p_nl,FiveHun);
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
if sanity==1
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
NU{2}=p_nl;
QNU{2}=q_nl;
L2=length(p_nl);
amount=min([L1 L2]);
% p_nl(1:amount)=NU{1}(1:amount);
% p_nl(amount+1:2*amount)=NU{2}(1:amount);
p_nl(1:2*amount)=[NU{1}(1:amount) NU{1}(1:amount)];
p_nl(2:2:end)=[NU{2}(1:length(p_nl(2:2:end)))];
% q_nl(1:amount)=QNU{1}(1:amount);
% q_nl(amount+1:2*amount)=QNU{2}(1:amount);
q_nl(1:2*amount)=[QNU{1}(1:amount) QNU{1}(1:amount)];
q_nl(2:2:end)=[QNU{2}(1:length(q_nl(2:2:end)))];
end
%Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,create_timecell(ro,length(p_nl)));
P2_nl=avg_samples(p_nl,create_timecell(ro,length(p_nl)));
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
%cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
%%
h(1)=subplot(3,4,1)
%plot(timecell_nl{1},P2_nl(w,:))
plot(cell2mat(create_timecell(ro,1)),P2_nl(w,:))
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('Wide Band No Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(3)=subplot(3,4,3)
plot(cell2mat(create_timecell(ro,1)),P1_nl(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('High Gamma No Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%%
h(2)=subplot(3,4,2)
plot(cell2mat(create_timecell(ro,1)),P2(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(4)=subplot(3,4,4)
plot(cell2mat(create_timecell(ro,1)),P1(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%% Time Frequency plots
% Calculate Freq1 and Freq2
if ro==1200
toy = [-1.2:.01:1.2];
else
toy = [-10.2:.1:10.2];
end
%toy = [-1.2:.01:1.2];
if length(p)>length(p_nl)
p=p(1:length(p_nl));
%timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
%timecell_nl=timecell_nl(1:length(p));
end
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
h(5)=subplot(3,4,5)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band No Learning');
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
h(6)=subplot(3,4,6)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
ylim([0.5 30])
%%
if ro==1200
[stats]=stats_between_trials(freq1,freq2,label1,w);
%[stats]=stats_high(freq1,freq2,w)
else
[stats]=stats_between_trials10(freq1,freq2,label1,w);
end
%%
h(9)=subplot(3,4,10)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
g=title(strcat(labelconditions{iii},' vs No Learning'))
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%Calculate Freq3 and Freq4
%toy=[-1:.01:1];
if ro==1200
toy=[-1:.01:1];
else
toy=[-10:.1:10];
end
if length(q)>length(q_nl)
q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
% timecell_nl=timecell_nl(1:length(q));
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
cfg = [];
cfg.channel = freq3.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq3);
[zmin2, zmax2] = ft_getminmax(cfg, freq4);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;
cfg.channel = freq3.label{w};
cfg.colormap=colormap(jet(256));
%%
h(7)=subplot(3,4,7)
ft_singleplotTFR(cfg, freq3);
% freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
g=title('High Gamma No Learning');
g.FontSize=12;
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%
h(8)=subplot(3,4,8);
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
ft_singleplotTFR(cfg, freq4);
g=title(strcat('High Gamma',{' '},labelconditions{iii}));
g.FontSize=12;
%title(strcat('High Gamma',{' '},labelconditions{iii}))
%xo
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
zmap=stats_high(freq3,freq4,w);
% if ro==1200
% zmap=stats_high(freq3,freq4,w);
% else
% [stats1]=stats_between_trials10(freq3,freq4,label1,w);
% end
%% %
h(10)=subplot(3,4,12);
colormap(jet(256))
zmap(zmap == 0) = NaN;
J=imagesc(freq3.time,freq3.freq,zmap)
xlabel('Time (s)'), ylabel('Frequency (Hz)')
%title('tf power map, thresholded')
set(gca,'xlim',xlim,'ydir','no')
% c=narrow_colorbar()
set(J,'AlphaData',~isnan(zmap))
c=narrow_colorbar()
c.YLim=[-max(abs(c.YLim)) max(abs(c.YLim))];
caxis([-max(abs(c.YLim)) max(abs(c.YLim))])
c=narrow_colorbar()
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%%
%
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% %grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% g=title(strcat(labelconditions{iii},' vs No Learning'));
% g.FontSize=12;
% %title(strcat(labelconditions{iii},' vs No Learning'))
% xlabel('Time (s)')
% %ylabel('uV')
% ylabel('Frequency (Hz)')
%% EXTRA STATISTICS
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
smaller_window.m
|
.m
|
CorticoHippocampal-master/Figures/Figure3/smaller_window.m
| 362 |
utf_8
|
6927e7b5f794fa2aab6cadd6035b43ef
|
%freq3
function [mdam, sdam]=smaller_window(freq3,w)
dam=((squeeze(mean(squeeze(freq3.powspctrm(:,w,:,1+50:end-50)),1)))); %Average all ripples.
mdam=mean(dam(:)); %Mean value
sdam=std(dam(:));
% FG3=freq3;
% FG3.time=[-.05:.001:.05];
% FG3.powspctrm=freq3.powspctrm(:,:,:,1+50:end-50);
%
% [ zmin100, zmax100] = ft_getminmax(cfg, FG3);
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
findmultiplets.m
|
.m
|
CorticoHippocampal-master/Ripple_detection/findmultiplets.m
| 2,643 |
utf_8
|
718c85952a92bb65f24f04becbddca9b
|
%MULTIPLETS DETECTION (Consecutive ripples)
function [M_multiplets, Mx_multiplets]=findmultiplets(Mx)
%Input: Mx contains the timestamps of the detected ripples peak.
%This is output M of the findripples function.
% We take the timestamps of the ripple peaks and compute their difference.
% If the ripples are closer to 300ms we consider the ripples to be multiplets.
% We count how many events are consecutive.
% Two ripples= doublet
% Three ripples= triplet
% And so on.
multiplets=[{'singlets'} {'doublets'} {'triplets'} {'quatruplets'} {'pentuplets'} {'sextuplets'} {'septuplets'} {'octuplets'} {'nonuplets'}];
% Convert to cell array. Only need this if your input is not a cell array already.
if ~iscell(Mx)
Mx={Mx};
end
%% Multiplets detection
% M_multiplets contains the timestamps of the ripple peak for all the detected multiplets.
% Mx_multiplets contains the same timestamps but grouped for the specific multiplet type.
% For example, ripple 1 of a triplet is in Mx_multiplets.triplets.m_1
% ripple 2 of a triplet is in Mx_multiplets.triplets.m_2
% and ripple 3 of a triplet is in Mx_multiplets.triplets.m_3
for l=1:length(Mx)
hfo_sequence=ConsecutiveOnes(diff(Mx{l})<=0.300);
for ll=1:length(multiplets)
eval([multiplets{ll} '=(hfo_sequence==' num2str(ll-1) ');'])
cont=1;
M_multiplets.(multiplets{ll}){l}=[];
while cont<=ll
%eval(['Sx_' multiplets{ll} '_' num2str(cont) '{l}=Sx{l}(find(' multiplets{ll} ')+(cont-1));'])
eval(['Mx_' multiplets{ll} '_' num2str(cont) '{l}=Mx{l}(find(' multiplets{ll} ')+(cont-1));'])
%eval(['Ex_' multiplets{ll} '_' num2str(cont) '{l}=Ex{l}(find(' multiplets{ll} ')+(cont-1));'])
Mx_multiplets.(multiplets{ll}).(strcat('m_',num2str(cont))){l}=eval(['Mx_' multiplets{ll} '_' num2str(cont) '{l}']);
M_multiplets.(multiplets{ll}){l}=eval(['sort([M_multiplets.(multiplets{ll}){l} ' ' Mx_' multiplets{ll} '_' num2str(cont) '{l}])']); % Combined consecutive multiplets
% eval([ 'clear' ' ' 'Mx_' multiplets{ll} '_' num2str(cont)])
cont=cont+1;
end
end
%Correct singlets values
multiplets_stamps=[];
for i=2:length(multiplets)
multiplets_stamps=[multiplets_stamps (M_multiplets.(multiplets{i}){1})];
end
M_multiplets.singlets={ Mx{l}(~ismember(Mx{l}, multiplets_stamps))};
Mx_multiplets.singlets.m_1={Mx{l}(~ismember(Mx{l}, multiplets_stamps))};
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
clean.m
|
.m
|
CorticoHippocampal-master/Ripple_detection/clean.m
| 194 |
utf_8
|
80e38d95eaaea683902bf4d93a4c0b38
|
function [ncellx,ncellr]=clean(cellx,cellr)
clear ncellx
notnan=cellfun('length',cellx);
estos=(notnan~=1);
ncellx=cellx(estos,1);
ncellr=cellr(estos,1);
ncellx=ncellx.';
ncellr=ncellr.';
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
generate2.m
|
.m
|
CorticoHippocampal-master/Ripple_detection/generate2.m
| 330 |
utf_8
|
ca599d116e59579a4b1bad29d7c7cc65
|
%Hippocampus Bipolar
%Hippocampus Monopolar
%function [p3, p5,cellx,cellr]=generate2(cara,veamos, Bip17,S17,ro)
function [cellx,cellr]=generate2(cara,veamos, Bip17,S17,ro)
%Generates windows
[cellx,cellr]=win(cara,veamos,Bip17,S17,ro);
%Clears nans
[cellx,cellr]=clean(cellx,cellr);
% [p3 ,p5]=eta2(cellx,cellr,ro,1000);
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
getwin2.m
|
.m
|
CorticoHippocampal-master/Ripple_detection/getwin2.m
| 2,235 |
utf_8
|
b9a624aab5c5b2cd8bb0a4bd64e044ac
|
%function [p,q,timecell,Q,P1,P2]=getwin2(cara,veamos,sig1,sig2,ro)
function [p,q,Q,sos]=getwin2(cara,veamos,sig1,sig2,ro)
%,ripple,thr
% fn=1000;
% isempty(sig2{2})
i=1;
%allscreen()
%[p1, p4, z1, z4]=generate2(cara,veamos, sig1{i},sig2{i},ro);
[z1, z4]=generate2(cara,veamos, sig1{i},sig2{i},ro);
i=3;
%allscreen()
%[p2, p5, z2, z5]=generate2(cara,veamos, sig1{i},sig2{i},ro);
[z2, z5]=generate2(cara,veamos, sig1{i},sig2{i},ro);
%i=7;
i=5;
% allscreen()
%[p3, p6, z3, z6]=generate2(cara,veamos, sig1{i},sig2{i},ro);
[z3, z6]=generate2(cara,veamos, sig1{i},sig2{i},ro);
%Look for accelerometer windows.
if ~isempty(sig2{2})
i=2;
% disp(sig1)
% disp(sig2)
[sos]=generate2(cara,veamos, sig1{i},sig2{i},ro);
sos=cellfun(@transpose,sos,'UniformOutput',0);
% sos=sos.';
else
sos=[];
end
% %i=11;
% i=7;
% % allscreen()
% [p7, p8, z7, z8]=generate2(cara,veamos, sig1{i},sig2{i},ro);
%
p=cell(length(z1),1);
q=cell(length(z1),1);
% timecell=cell(length(z1),1);
%UNCOMMENT IF YOU WANT THE ENVELOPE:
% Q=cell(length(z1),1);
for i=1:length(z1)
% p{i,1}=[z1{i}.';z2{i}.';z3{i}.';z7{i}.']; %Widepass
% q{i,1}=[z4{i}.';z5{i}.';z6{i}.';z8{i}.']; %Bandpassed
p{i,1}=[z1{i}.';z2{i}.';z3{i}.']; %Widepass
q{i,1}=[z4{i}.';z5{i}.';z6{i}.']; %Bandpassed
% timecell{i,1}=[0:length(p7)-1]*(1/fn)-(ro/1000);
%Q{i,1}=[envelope1(z4{i}.');envelope1(z5{i}.');envelope1(z6{i}.');envelope1(z8{i}.')]; %Bandpassed
%Uncomment the following if you need the envelope
% Q{i,1}=[envelope1(z4{i}.');envelope1(z5{i}.');envelope1(z6{i}.')]; %Bandpassed
end
p=p.';
q=q.';
%timecell=timecell.';
%UNCOMMENT IF YOU WANT THE ENVELOPE:
%Q=Q.';
% GETTING THE ENVELOPE
%P=cell(length(z1),1);
% Q=cell(length(z1),1);
% % % for i=1:length(z1)
% % % % p{i,1}=[z1{i}.';z2{i}.';z3{i}.'];
% % % % q{i,1}=[z4{i}.';z5{i}.';z6{i}.'];
% % % % P{i,1}=[envelope1(z1{i}.',1000); envelope1(z2{i}.',1000); envelope1(z3{i}.',1000);envelope1(z7{i}.',1000)]; %Widepass
% % % Q{i,1}=[envelope1(z4{i}.');envelope1(z5{i}.');envelope1(z6{i}.');envelope1(z8{i}.')]; %Bandpassed
% % %
% % % end
%P=P.';
% Q=Q.';
% P1=[p1;p2;p3;p7];
% P2=[p4;p5;p6;p8];
% P1=[p1;p2;p3];
% P2=[p4;p5;p6];
%Comment this if you need Q:
Q=[];
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
gc_paper_single.m
|
.m
|
CorticoHippocampal-master/Ideas_testing/gc_paper_single.m
| 11,420 |
utf_8
|
6e210c10b4cb1f2f288b1754ce9c6754
|
function [granger,granger1]=gc_paper_single(q,timecell,label,ro,ord,freqrange,nu)
fn=1000;
data1.trial=q(nu);
data1.time= timecell; %Might have to change this one
data1.fsample=fn;
data1.label=cell(3,1);
data1.label{1}='Hippocampus';
data1.label{2}='Parietal';
data1.label{3}='PFC';
%data1.label{4}='Reference';
%Parametric model
cfg = [];
cfg.order = ord;
cfg.toolbox = 'bsmart';
mdata = ft_mvaranalysis(cfg, data1);
cfg = [];
cfg.method = 'mvar';
mfreq = ft_freqanalysis(cfg, mdata);
%Non parametric
cfg = [];
cfg.method = 'mtmfft';
cfg.taper = 'dpss';
%cfg.taper = 'hanning';
cfg.output = 'fourier';
cfg.tapsmofrq = 2;
cfg.pad = 10;
cfg.foi=freqrange;
freq = ft_freqanalysis(cfg, data1);
% %Non parametric- Multitaper
% cfg = [];
% cfg.method = 'mtmconvol';
% cfg.foi = 1:1:100;
% cfg.taper = 'dpss';
% cfg.output = 'fourier';
% cfg.tapsmofrq = 10;
% cfg.toi='50%';
% cfg.t_ftimwin = ones(length(cfg.foi),1).*.1; % length of time window = 0.5 sec
%
%
% freq1 = ft_freqanalysis(cfg, data1);
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % Nonparametric freq analysis (OTHER WAVELET)
% cfg = [];
% cfg.method = 'wavelet';
% % cfg.width=10;
% cfg.gwidth=5;
%
% cfg.foi = 0:5:300;
% %cfg.foilim=[10 100]
% % cfg.taper = 'dpss';
% cfg.output = 'powandcsd';
% %andcsd
% %cfg.toi=-0.2:0.001:0.2;
% cfg.toi=-0.199:0.1:0.2;
%
% %cfg.t_ftimwin = ones(length(cfg.foi),1).*0.1; % length of time window = 0.5 sec
% % % %
% % % % % Nonparametric freq analysis (MTMconvol)
% % % % cfg = [];
% % % % %cfg.method = 'mtmfft';
% % % % cfg.method = 'mtmconvol';
% % % % %cfg.pad = 'nextpow2';
% % % % cfg.pad = 10;
% % % %
% % % % cfg.taper = 'dpss';
% % % % cfg.output = 'fourier';
% % % % cfg.foi=[0:2:300];
% % % % cfg.tapsmofrq = 10;
% % % % cfg.t_ftimwin=ones(length(cfg.foi),1).*(0.1);
% % % % %cfg.t_ftimwin=1000./cfg.foi;
% % % % %cfg.tapsmofrq = 0.4*cfg.foi;
%cfg.t_ftimwin=7./cfg.foi;
% % % % % % % % cfg.toi='50%';
% % % % % % % cfg.toi=linspace(-0.2,0.2,10);
% % % % % % % freq1 = ft_freqanalysis(cfg, data1);
% % % % % % % %
% % % % % % % % % Nonparametric freq analysis (Wavelet)
% % % % % % % % cfg = [];
% % % % % % % % %cfg.method = 'mtmfft';
% % % % % % % % cfg.method = 'wavelet';
% % % % % % % % %cfg.pad = 'nextpow2';
% % % % % % % % cfg.pad = 2;
% % % % % % % %
% % % % % % % % cfg.width=1;
% % % % % % % %
% % % % % % % % cfg.taper = 'dpss';
% % % % % % % % cfg.output = 'powandcsd';
% % % % % % % % cfg.foi=[0:5:300];
% % % % % % % % % cfg.tapsmofrq = 2;
% % % % % % % % %cfg.t_ftimwin=ones(length(cfg.foi),1).*(0.1);
% % % % % % % % %cfg.t_ftimwin=7./cfg.foi;
% % % % % % % %
% % % % % % % % % cfg.toi='50%';
% % % % % % % % cfg.toi=linspace(-0.2,0.2,10);
% % % % % % % % freq_mtmfft = ft_freqanalysis(cfg, data1);
% % %
% % % % Nonparametric freq analysis (Wavelet OTHER)
% % % cfg = [];
% % % %cfg.method = 'mtmfft';
% % % cfg.method = 'tfr';
% % % %cfg.pad = 'nextpow2';
% % % cfg.pad = 2;
% % %
% % % cfg.width=2;
% % % %
% % % % cfg.taper = 'dpss';
% % % cfg.output = 'powandcsd';
% % % cfg.foi=[0:5:300];
% % % %%cfg.tapsmofrq = 2;
% % % cfg.t_ftimwin=ones(length(cfg.foi),1).*(0.1);
% % % %cfg.t_ftimwin=7./cfg.foi;
% % %
% % % % cfg.toi='50%';
% % % cfg.toi=linspace(-0.2,0.2,5);
% % % freq_wavt = ft_freqanalysis(cfg, data1);
cfg = [];
cfg.method = 'granger';
granger = ft_connectivityanalysis(cfg, freq);
granger1 = ft_connectivityanalysis(cfg, mfreq);
% % % % % % % % % % % % % % % % % % % % % % % %granger2 = ft_connectivityanalysis(cfg, freq1);
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % %%granger3 = ft_connectivityanalysis(cfg, freq_mtmfft); %Wavelet
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % granger4 = ft_connectivityanalysis(cfg, freq_wavt);
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % %lab=cell(16,1);
% % % % % % % % % % % % % % % % % % % % % % % % lab{1}='Hippo -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % % lab{2}='Hippo -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % % lab{3}='Hippo -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % % lab{4}='Hippo -> Reference';
% % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % lab{5}='Parietal -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % % lab{6}='Parietal -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % % lab{7}='Parietal -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % % lab{8}='Parietal -> Reference';
% % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % lab{9}='PFC -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % % lab{10}='PFC -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % % lab{11}='PFC -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % % lab{12}='PFC -> Reference';
% % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % lab{13}='Reference -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % % lab{14}='Reference -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % % lab{15}='Reference -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % % lab{16}='Reference -> Reference';
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % lab=cell(9,1);
% % % % % % % % % % % % % % % % % % % % % % % lab{1}='Hippo -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % lab{2}='Hippo -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % lab{3}='Hippo -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % %lab{4}='Hippo -> Reference';
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % lab{4}='Parietal -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % lab{5}='Parietal -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % lab{6}='Parietal -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % %lab{8}='Parietal -> Reference';
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % lab{7}='PFC -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % lab{8}='PFC -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % lab{9}='PFC -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % %lab{12}='PFC -> Reference';
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % lab{13}='Reference -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % % lab{14}='Reference -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % % lab{15}='Reference -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % % lab{16}='Reference -> Reference';
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % figure
% % % % % % % % % % % % % % % % % % % % % % % conta=0;
% % % % % % % % % % % % % % % % % % % % % % % compt=0;
% % % % % % % % % % % % % % % % % % % % % % % figure('units','normalized','outerposition',[0 0 1 1])
% % % % % % % % % % % % % % % % % % % % % % % %for j=1:length(freq1.time)
% % % % % % % % % % % % % % % % % % % % % % % compt=compt+1;
% % % % % % % % % % % % % % % % % % % % % % % conta=0;
% % % % % % % % % % % % % % % % % % % % % % % for row=1:length(data1.label)
% % % % % % % % % % % % % % % % % % % % % % % for col=1:length(data1.label)
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % subplot(length(data1.label),length(data1.label),(row-1)*length(data1.label)+col);
% % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % plot(granger2.freq, squeeze(granger2.grangerspctrm(row,col,:,j)),'LineWidth',.01,'Color',[0 0 0])
% % % % % % % % % % % % % % % % % % % % % % % % % % % % %hold on
% % % % % % % % % % % % % % % % % % % % % % % % % % % % plot(granger1.freq, squeeze(granger1.grangerspctrm(row,col,:)),'Color',[1 0 0])
% % % % % % % % % % % % % % % % % % % % % % % % % % % % hold on
% % % % % % % % % % % % % % % % % % % % % % % % % % % % plot(granger.freq, squeeze(granger.grangerspctrm(row,col,:)),'Color',[0 0 1])
% % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % %%plot(granger3.freq, squeeze(granger3.grangerspctrm(row,col,:,j)),'LineWidth',.01,'Color',[0 1 0])
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % %plot(granger2.freq, squeeze(granger2.grangerspctrm(row,col,:)))
% % % % % % % % % % % % % % % % % % % % % % % % plot(granger4.freq, squeeze(granger4.grangerspctrm(row,col,:,j)),'LineWidth',.01,'Color',[1 1 0])
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % ylim([0 1])
% % % % % % % % % % % % % % % % % % % % % % % xlim([0 300])
% % % % % % % % % % % % % % % % % % % % % % % xlabel('Frequency (Hz)')
% % % % % % % % % % % % % % % % % % % % % % % grid minor
% % % % % % % % % % % % % % % % % % % % % % % conta=conta+1;
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % if conta==1 || conta==6 || conta==11 || conta==16
% % % % % % % % % % % % % % % % % % % % % % % if conta==1 || conta==5 || conta==9
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % legend('NP:Multitaper','Parametric: AR(10)','NP:MTMFFT')
% % % % % % % % % % % % % % % % % % % % % % % % legend('Parametric: AR(10)','Non-P:Multitaper')
% % % % % % % % % % % % % % % % % % % % % % % % set(gca,'Color','k')
% % % % % % % % % % % % % % % % % % % % % % % % text(100,0.5,'A Simple Plot','Color','red','FontSize',14)
% % % % % % % % % % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % % % % % % % % % % if conta==5
% % % % % % % % % % % % % % % % % % % % % % % % text(100,0.5,'Monopolar','Color','red','FontSize',14)
% % % % % % % % % % % % % % % % % % % % % % % % text(100,0.35,label,'Color','red','FontSize',14)
% % % % % % % % % % % % % % % % % % % % % % % % text(100,0.20,strcat('(+/-',num2str(ro),'ms)'),'Color','red','FontSize',14)
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % % % % % % % % % % title(lab{conta})
% % % % % % % % % % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % % % % % % % % % % %end
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % mtit('Monopolar','fontsize',14,'color',[1 0 0],'position',[.5 1 ])
% % % % % % % % % % % % % % % % % % % % % % % %mtit(label,'fontsize',14,'color',[1 0 0],'position',[.5 0.75 ])
% % % % % % % % % % % % % % % % % % % % % % % %mtit(strcat('(+/-',num2str(ro),'ms)'),'fontsize',14,'color',[1 0 0],'position',[.5 0.5 ])
% % % % % % % % % % % % % % % % % % % % % % % compt
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_conditions_filtering.m
|
.m
|
CorticoHippocampal-master/Ideas_testing/plot_inter_conditions_filtering.m
| 12,699 |
utf_8
|
30447fb28e34ab95fad3ce0e601dbe17
|
%This one requires running data from Non Learning condition
function [h]=plot_inter_conditions_filtering(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,acer)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% ripple3=ripple_nl;
%ran=randi(length(p),100,1);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
[ran_nl]=select_rip(p_nl);
%
% av=cat(1,p_nl{1:end});
% %av=cat(1,q_nl{1:end});
% av=av(1:3:end,:); %Only Hippocampus
%
% %AV=max(av.');
% %[B I]= maxk(AV,1000);
%
% %AV=max(av.');
% %[B I]= maxk(max(av.'),1000);
%
%
% [ach]=max(av.');
% achinga=sort(ach,'descend');
% %achinga=achinga(1:1000);
% if length(achinga)>1000
% if Rat==24
% achinga=achinga(6:1005);
% else
% achinga=achinga(1:1000);
% end
% end
%
% B=achinga;
% I=nan(1,length(B));
% for hh=1:length(achinga)
% % I(hh)= min(find(ach==achinga(hh)));
% I(hh)= find(ach==achinga(hh),1,'first');
% end
%
%
% [ajal ind]=unique(B);
% if length(ajal)>500
% ajal=ajal(end-499:end);
% ind=ind(end-499:end);
% end
% dex=I(ind);
%
% ran_nl=dex.';
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
%timecell_nl=timecell_nl([ran_nl]);
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
%Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,create_timecell(ro,length(p_nl)));
P2_nl=avg_samples(p_nl,create_timecell(ro,length(p_nl)));
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
%cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
%%
h(1)=subplot(3,4,1)
%plot(timecell_nl{1},P2_nl(w,:))
plot(cell2mat(create_timecell(ro,1)),P2_nl(w,:))
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('Wide Band No Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (t)')
ylabel('uV')
%%
h(3)=subplot(3,4,3)
plot(cell2mat(create_timecell(ro,1)),P1_nl(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('High Gamma No Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
xlabel('Time (t)')
ylabel('uV')
%%
h(2)=subplot(3,4,2)
plot(cell2mat(create_timecell(ro,1)),P2(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(4)=subplot(3,4,4)
plot(cell2mat(create_timecell(ro,1)),P1(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%% Time Frequency plots
% Calculate Freq1 and Freq2
if ro==1200
toy = [-1.2:.01:1.2];
else
toy = [-10.2:.1:10.2];
end
%toy = [-1.2:.01:1.2];
if length(p)>length(p_nl)
p=p(1:length(p_nl));
%timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
%timecell_nl=timecell_nl(1:length(p));
end
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
h(5)=subplot(3,4,5)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band No Learning');
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
h(6)=subplot(3,4,6)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
ylim([0.5 30])
%%
% if ro==1200
% [stats]=stats_between_trials(freq1,freq2,label1,w);
% else
% [stats]=stats_between_trials10(freq1,freq2,label1,w);
% end
%%
h(9)=subplot(3,4,10)
%
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% %grid minor
% ft_singleplotTFR(cfg, stats);
% % title('Condition vs No Learning')
% g=title(strcat(labelconditions{iii},' vs No Learning'))
% g.FontSize=12;
% %title(strcat(labelconditions{iii},' vs No Learning'))
% xlabel('Time (s)')
% %ylabel('uV')
% ylabel('Frequency (Hz)')
%%
%Calculate Freq3 and Freq4
%toy=[-1:.01:1];
if ro==1200
toy=[-1:.01:1];
else
toy=[-10:.1:10];
end
if length(q)>length(q_nl)
q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
% timecell_nl=timecell_nl(1:length(q));
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
cfg = [];
cfg.channel = freq3.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq3);
[zmin2, zmax2] = ft_getminmax(cfg, freq4);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;
cfg.channel = freq3.label{w};
cfg.colormap=colormap(jet(256));
%%
h(7)=subplot(3,4,7)
ft_singleplotTFR(cfg, freq3);
% freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
g=title('High Gamma No Learning');
g.FontSize=12;
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%
h(8)=subplot(3,4,8);
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
ft_singleplotTFR(cfg, freq4);
g=title(strcat('High Gamma',{' '},labelconditions{iii}));
g.FontSize=12;
%title(strcat('High Gamma',{' '},labelconditions{iii}))
%xo
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
if ro==1200
[stats1]=stats_between_trials(freq3,freq4,label1,w);
else
[stats1]=stats_between_trials10(freq3,freq4,label1,w);
end
%% %
h(10)=subplot(3,4,12);
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%% EXTRA STATISTICS
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
ripples_per_stage.m
|
.m
|
CorticoHippocampal-master/Ideas_testing/ripples_per_stage.m
| 470 |
utf_8
|
e388e3fbf0bd6d4b7e26951812c32687
|
% [tr2]=sort_scoring(transitions,3);
% tr2=tr2(:,2:3);
%%
% x=tr2;
function ripples_per_stage(x,stage,plotting)
%ripples_per_stage(x)
%For plotting, plotting=1. Else use plotting=0.
nrow = size(x,1);
nline = repmat((stage.*ones(1,length(x)))',1,2);
% plot(x',nline','o-')
if plotting==1
plot(x'/60/60,nline','-','Color',[0 0 0],'LineWidth',10)
ylim([-.5*nrow 1.5*nrow])
xlabel('Time (Hours)')
hold on
ylim([0 6])
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_test_spindles.m
|
.m
|
CorticoHippocampal-master/Ideas_testing/plot_test_spindles.m
| 22,626 |
utf_8
|
0c024e56455fe8d665e2b4c4cfe36d1d
|
%This one requires running data from Non Learning condition
function [h]=plot_test_spindles(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,acer,block_time,NFF,mergebaseline,FiveHun,meth,rat26session3,rat27session3,notch,sanity,quinientos,outlie,varargin)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% ripple3=ripple_nl;
%ran=randi(length(p),100,1);
randrip=varargin;
randrip=cell2mat(randrip);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
%This one:
% % % [p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% if meth==3
% [p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),chtm);
% else
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% end
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
if outlie==1
ache=max_outlier(p_nl);
p_nl=p_nl(ache);
q_nl=q_nl(ache);
end
if quinientos==0
[ran_nl]=select_rip(p_nl,FiveHun);
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
else
if iii~=2
[ran_nl]=select_quinientos(p_nl,length(randrip));
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
% ran=1:length(randrip);
end
end
%timecell_nl=timecell_nl([ran_nl]);
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
if mergebaseline==1
%%
'MERGING BASELINES'
L1=length(p_nl);
NU{1}=p_nl;
QNU{1}=q_nl;
%% Other Baseline
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1}) %Baseline
% [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
if meth==1
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
end
if meth==2
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=median_std;
end
if meth==3
chtm=load('vq_loop2.mat');
chtm=chtm.vq;
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
if meth==4
[timeasleep]=find_thr_base;
ror=2000/timeasleep;
if acer==0
cd(strcat('/home/raleman/Dropbox/Figures/Figure2/',num2str(Rat)))
else
%cd(strcat('C:\Users\Welt Meister\Dropbox\Figures\Figure2\',num2str(Rat)))
cd(strcat('C:\Users\addri\Dropbox\Figures\Figure2\',num2str(Rat)))
end
if Rat==26
Base=[{'Baseline1'} {'Baseline2'}];
end
if Rat==26 && rat26session3==1
Base=[{'Baseline3'} {'Baseline2'}];
end
if Rat==27
Base=[{'Baseline2'} {'Baseline1'}];% We run Baseline 2 first, cause it is the one we prefer.
end
if Rat==27 && rat27session3==1
Base=[{'Baseline2'} {'Baseline3'}];% We run Baseline 2 first, cause it is the one we prefer.
end
base=2; %VERY IMPORTANT!
%openfig('Ripples_per_condition_best.fig')
openfig(strcat('Ripples_per_condition_',Base{base},'.fig'))
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes
ydata=dataObjs{2}(8).YData;
xdata=dataObjs{2}(8).XData;
% figure()
% plot(xdata,ydata)
chtm = interp1(ydata,xdata,ror);
close
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1})
%xo
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
%This seems incomplete:
% if meth==4
% [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
% CHTM2=[chtm chtm];
% end
if block_time==1
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,30,0);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
if block_time==2
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,60,30);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
%%
clear sig1_nl sig2_nl
if quinientos==0
[ran_nl]=select_rip(p_nl,FiveHun);
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
else
if iii~=2
[ran_nl]=select_quinientos(p_nl,length(randrip));
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
% ran=1:length(randrip);
end
end
%timecell_nl=timecell_nl([ran_nl]);
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
%%
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
NU{2}=p_nl;
QNU{2}=q_nl;
L2=length(p_nl);
amount=min([L1 L2]);
% p_nl(1:amount)=NU{1}(1:amount);
% p_nl(amount+1:2*amount)=NU{2}(1:amount);
p_nl(1:2*amount)=[NU{1}(1:amount) NU{1}(1:amount)];
p_nl(2:2:end)=[NU{2}(1:length(p_nl(2:2:end)))];
% q_nl(1:amount)=QNU{1}(1:amount);
% q_nl(amount+1:2*amount)=QNU{2}(1:amount);
q_nl(1:2*amount)=[QNU{1}(1:amount) QNU{1}(1:amount)];
q_nl(2:2:end)=[QNU{2}(1:length(q_nl(2:2:end)))];
end
clear sig1_nl sig2_nl
%Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,create_timecell(ro,length(p_nl)));
P2_nl=avg_samples(p_nl,create_timecell(ro,length(p_nl)));
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
%cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
%%
h(1)=subplot(3,4,1)
%plot(timecell_nl{1},P2_nl(w,:))
plot(cell2mat(create_timecell(ro,1)),P2_nl(w,:))
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('Wide Band No Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(3)=subplot(3,4,3)
plot(cell2mat(create_timecell(ro,1)),P1_nl(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('High Gamma No Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%%
h(2)=subplot(3,4,2)
plot(cell2mat(create_timecell(ro,1)),P2(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(4)=subplot(3,4,4)
plot(cell2mat(create_timecell(ro,1)),P1(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
clear P1 P2
%% Time Frequency plots
% Calculate Freq1 and Freq2
if ro==1200
toy = [-1.2:.01:1.2];
else
%toy = [-10.2:.1:10.2];
toy = [-10.2:.01:10.2];
end
%toy = [-1.2:.01:1.2];
if length(p)>length(p_nl)
p=p(1:length(p_nl));
%timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
%timecell_nl=timecell_nl(1:length(p));
end
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% freq1=barplot2_ft(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,toy);
% freq2=barplot2_ft(p,create_timecell(ro,length(p)),[1:0.5:30],w,toy);
% freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
% freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
h(5)=subplot(3,4,5)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band No Learning');
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
h(6)=subplot(3,4,6)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
ylim([0.5 30])
%%
h(7)=subplot(3,4,9)
[achis]=baseline_norm(freq1,w);
colormap(jet(256))
J=imagesc(freq1.time,freq1.freq,achis)
xlabel('Time (s)'), ylabel('Frequency (Hz)')
%title('tf power map, thresholded')
set(gca,'xlim',xlim,'ydir','no')
% c=narrow_colorbar()
xlim([-1 1])
set(J,'AlphaData',~isnan(achis))
c=narrow_colorbar()
c.YLim=[-max(abs(c.YLim)) max(abs(c.YLim))];
caxis([-max(abs(c.YLim)) max(abs(c.YLim))])
c=narrow_colorbar()
g=title('Wide Band No Learning');
g.FontSize=12;
%%
h(8)=subplot(3,4,10)
[achis2]=baseline_norm(freq2,w);
colormap(jet(256))
J=imagesc(freq1.time,freq1.freq,achis2)
xlabel('Time (s)'), ylabel('Frequency (Hz)')
%title('tf power map, thresholded')
set(gca,'xlim',xlim,'ydir','no')
% c=narrow_colorbar()
xlim([-1 1])
set(J,'AlphaData',~isnan(achis2))
c=narrow_colorbar()
c.YLim=[-max(abs(c.YLim)) max(abs(c.YLim))];
caxis([-max(abs(c.YLim)) max(abs(c.YLim))])
c=narrow_colorbar()
g=title(strcat(labelconditions{iii}));
g.FontSize=12;
%%
% if ro==1200
% [stats]=stats_between_trials(freq1,freq2,label1,w);
% else
% [stats]=stats_between_trials10(freq1,freq2,label1,w);
% end
%
% %%
% h(9)=subplot(3,4,10)
% %
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% %grid minor
% ft_singleplotTFR(cfg, stats);
% % title('Condition vs No Learning')
% g=title(strcat(labelconditions{iii},' vs No Learning'))
% g.FontSize=12;
% %title(strcat(labelconditions{iii},' vs No Learning'))
% xlabel('Time (s)')
% %ylabel('uV')
% ylabel('Frequency (Hz)')
%%
%%
% clear freq1 freq2 p_nl p
% %Calculate Freq3 and Freq4
% %toy=[-1:.01:1];
% if ro==1200
% toy=[-1:.01:1];
% else
% %toy=[-10:.1:10];
% toy = [-10:.01:10];
% end
%
% if length(q)>length(q_nl)
% q=q(1:length(q_nl));
% % timecell=timecell(1:length(q_nl));
% end
%
% if length(q)<length(q_nl)
% q_nl=q_nl(1:length(q));
% % timecell_nl=timecell_nl(1:length(q));
% end
%
% if ro==1200
% freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
% freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
% else
% freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
% freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
% end
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
%U might want to uncomment this if you use a smaller step: (Memory purposes)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg = [];
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg.channel = freq3.label{w};
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [ zmin1, zmax1] = ft_getminmax(cfg, freq3);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [zmin2, zmax2] = ft_getminmax(cfg, freq4);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % zlim=[-max(abs(zlim)) max(abs(zlim))];
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %%
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg = [];
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg.zlim=zlim; %U might want to uncomment this if you use a smaller step: (Memory purposes)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg.channel = freq3.label{w};
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg.colormap=colormap(jet(256));
%%
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % h(7)=subplot(3,4,7)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ft_singleplotTFR(cfg, freq3);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % g=title('High Gamma No Learning');
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % g.FontSize=12;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % xlabel('Time (s)')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %ylabel('uV')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ylabel('Frequency (Hz)')
%%
%clear freq3
%%
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % h(8)=subplot(3,4,8);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % freq4=barplot2_ft(q,timecell,[100:1:300],w)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %freq=justtesting(q,timecell,[100:1:300],w,0.5)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %title('High Gamma RIPPLE')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ft_singleplotTFR(cfg, freq4);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % g=title(strcat('High Gamma',{' '},labelconditions{iii}));
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % g.FontSize=12;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %title(strcat('High Gamma',{' '},labelconditions{iii}))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %xo
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % xlabel('Time (s)')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %ylabel('uV')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ylabel('Frequency (Hz)')
%%
%clear freq4
%%
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % if ro==1200
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [stats1]=stats_between_trials(freq3,freq4,label1,w);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % else
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [stats1]=stats_between_trials10(freq3,freq4,label1,w);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % end
%% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % h(10)=subplot(3,4,12);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg = [];
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg.channel = label1{2*w-1};
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg.parameter = 'stat';
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg.maskparameter = 'mask';
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg.zlim = 'maxabs';
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg.colorbar = 'yes';
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cfg.colormap=colormap(jet(256));
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %grid minor
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ft_singleplotTFR(cfg, stats1);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ft_singleplotTFR(cfg, stats1);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %title('Ripple vs No Ripple')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % g=title(strcat(labelconditions{iii},' vs No Learning'));
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % g.FontSize=12;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %title(strcat(labelconditions{iii},' vs No Learning'))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % xlabel('Time (s)')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %ylabel('uV')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ylabel('Frequency (Hz)')
%% EXTRA STATISTICS
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
ft_getminmax_OUTDATED.m
|
.m
|
CorticoHippocampal-master/Ideas_testing/ft_getminmax_OUTDATED.m
| 22,617 |
utf_8
|
6b51df1b7dcd4f59f90e88458cce313c
|
function [ zmin] = ft_getminmax_OUTDATED(cfg, data)
%function [cfg] = ft_singleplotTFR(cfg, data)
% FT_SINGLEPLOTTFR plots the time-frequency representation of power of a
% single channel or the average over multiple channels.
%
% Use as
% ft_singleplotTFR(cfg,data)
%
% The input freq structure should be a a time-frequency representation of
% power or coherence that was computed using the FT_FREQANALYSIS function.
%
% The configuration can have the following parameters:
% cfg.parameter = field to be plotted on z-axis, e.g. 'powspcrtrm' (default depends on data.dimord)
% cfg.maskparameter = field in the data to be used for masking of data
% (not possible for mean over multiple channels, or when input contains multiple subjects
% or trials)
% cfg.maskstyle = style used to masking, 'opacity', 'saturation', 'outline' or 'colormix' (default = 'opacity')
% use 'saturation' or 'outline' when saving to vector-format (like *.eps) to avoid all sorts of image-problems
% cfg.maskalpha = alpha value between 0 (transparant) and 1 (opaque) used for masking areas dictated by cfg.maskparameter (default = 1)
% cfg.masknans = 'yes' or 'no' (default = 'yes')
% cfg.xlim = 'maxmin' or [xmin xmax] (default = 'maxmin')
% cfg.ylim = 'maxmin' or [ymin ymax] (default = 'maxmin')
% cfg.zlim = plotting limits for color dimension, 'maxmin', 'maxabs', 'zeromax', 'minzero', or [zmin zmax] (default = 'maxmin')
% cfg.baseline = 'yes', 'no' or [time1 time2] (default = 'no'), see FT_FREQBASELINE
% cfg.baselinetype = 'absolute', 'relative', 'relchange' or 'db' (default = 'absolute')
% cfg.trials = 'all' or a selection given as a 1xN vector (default = 'all')
% cfg.channel = Nx1 cell-array with selection of channels (default = 'all'),
% see FT_CHANNELSELECTION for details
% cfg.title = string, title of plot
% cfg.refchannel = name of reference channel for visualising connectivity, can be 'gui'
% cfg.fontsize = font size of title (default = 8)
% cfg.hotkeys = enables hotkeys (leftarrow/rightarrow/uparrow/downarrow/pageup/pagedown/m) for dynamic zoom and translation (ctrl+) of the axes and color limits
% cfg.colormap = any sized colormap, see COLORMAP
% cfg.colorbar = 'yes', 'no' (default = 'yes')
% cfg.interactive = Interactive plot 'yes' or 'no' (default = 'yes')
% In a interactive plot you can select areas and produce a new
% interactive plot when a selected area is clicked. Multiple areas
% can be selected by holding down the SHIFT key.
% cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% cfg.directionality = '', 'inflow' or 'outflow' specifies for
% connectivity measures whether the inflow into a
% node, or the outflow from a node is plotted. The
% (default) behavior of this option depends on the dimor
% of the input data (see below).
%
% For the plotting of directional connectivity data the cfg.directionality
% option determines what is plotted. The default value and the supported
% functionality depend on the dimord of the input data. If the input data
% is of dimord 'chan_chan_XXX', the value of directionality determines
% whether, given the reference channel(s), the columns (inflow), or rows
% (outflow) are selected for plotting. In this situation the default is
% 'inflow'. Note that for undirected measures, inflow and outflow should
% give the same output. If the input data is of dimord 'chancmb_XXX', the
% value of directionality determines whether the rows in data.labelcmb are
% selected. With 'inflow' the rows are selected if the refchannel(s) occur in
% the right column, with 'outflow' the rows are selected if the
% refchannel(s) occur in the left column of the labelcmb-field. Default in
% this case is '', which means that all rows are selected in which the
% refchannel(s) occur. This is to robustly support linearly indexed
% undirected connectivity metrics. In the situation where undirected
% connectivity measures are linearly indexed, specifying 'inflow' or
% 'outflow' can result in unexpected behavior.
%
% See also FT_SINGLEPLOTER, FT_MULTIPLOTER, FT_MULTIPLOTTFR, FT_TOPOPLOTER, FT_TOPOPLOTTFR
% Copyright (C) 2005-2017, F.C. Donders Centre
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
% FieldTrip is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% FieldTrip is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DEVELOPERS NOTE: This code is organized in a similar fashion for multiplot/singleplot/topoplot
% and for ER/TFR and should remain consistent over those 6 functions.
% Section 1: general cfg handling that is independent from the data
% Section 2: data handling, this also includes converting bivariate (chan_chan and chancmb) into univariate data
% Section 3: select the data to be plotted and determine min/max range
% Section 4: do the actual plotting
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Section 1: general cfg handling that is independent from the data
% these are used by the ft_preamble/ft_postamble function and scripts
ft_revision = '$Id$';
ft_nargin = nargin;
ft_nargout = nargout;
% do the general setup of the function
ft_defaults
ft_preamble init
ft_preamble debug
ft_preamble provenance
ft_preamble trackconfig
% the ft_abort variable is set to true or false in ft_preamble_init
if ft_abort
return
end
% check if the input data is valid for this function
data = ft_checkdata(data, 'datatype', 'freq');
% check if the input cfg is valid for this function
cfg = ft_checkconfig(cfg, 'unused', {'cohtargetchannel'});
cfg = ft_checkconfig(cfg, 'renamed', {'matrixside', 'directionality'});
cfg = ft_checkconfig(cfg, 'renamedval', {'zlim', 'absmax', 'maxabs'});
cfg = ft_checkconfig(cfg, 'renamedval', {'directionality', 'feedforward', 'outflow'});
cfg = ft_checkconfig(cfg, 'renamedval', {'directionality', 'feedback', 'inflow'});
cfg = ft_checkconfig(cfg, 'renamed', {'channelindex', 'channel'});
cfg = ft_checkconfig(cfg, 'renamed', {'channelname', 'channel'});
cfg = ft_checkconfig(cfg, 'renamed', {'cohrefchannel', 'refchannel'});
cfg = ft_checkconfig(cfg, 'renamed', {'zparam', 'parameter'});
cfg = ft_checkconfig(cfg, 'deprecated', {'xparam', 'yparam'});
% Set the defaults
cfg.baseline = ft_getopt(cfg, 'baseline', 'no');
cfg.baselinetype = ft_getopt(cfg, 'baselinetype', 'absolute');
cfg.trials = ft_getopt(cfg, 'trials', 'all', 1);
cfg.xlim = ft_getopt(cfg, 'xlim', 'maxmin');
cfg.ylim = ft_getopt(cfg, 'ylim', 'maxmin');
cfg.zlim = ft_getopt(cfg, 'zlim', 'maxmin');
cfg.fontsize = ft_getopt(cfg, 'fontsize', 8);
cfg.colorbar = ft_getopt(cfg, 'colorbar', 'yes');
cfg.interactive = ft_getopt(cfg, 'interactive', 'yes');
cfg.hotkeys = ft_getopt(cfg, 'hotkeys', 'yes');
cfg.renderer = ft_getopt(cfg, 'renderer', []);
cfg.maskalpha = ft_getopt(cfg, 'maskalpha', 1);
cfg.maskparameter = ft_getopt(cfg, 'maskparameter', []);
cfg.maskstyle = ft_getopt(cfg, 'maskstyle', 'opacity');
cfg.channel = ft_getopt(cfg, 'channel', 'all');
cfg.title = ft_getopt(cfg, 'title', []);
cfg.masknans = ft_getopt(cfg, 'masknans', 'yes');
cfg.directionality = ft_getopt(cfg, 'directionality', []);
cfg.figurename = ft_getopt(cfg, 'figurename', []);
cfg.parameter = ft_getopt(cfg, 'parameter', 'powspctrm');
% this is needed for the figure title and correct labeling of graphcolor later on
if nargin>1
if isfield(cfg, 'dataname')
if iscell(cfg.dataname)
dataname = cfg.dataname{1};
else
dataname = cfg.dataname;
end
else
if ~isempty(inputname(2))
dataname = inputname(2);
else
dataname = ['data' num2str(1, '%02d')];
end
end
else % data provided through cfg.inputfile
dataname = cfg.inputfile;
end
%% Section 2: data handling, this also includes converting bivariate (chan_chan and chancmb) into univariate data
hastime = isfield(data, 'time');
hasfreq = isfield(data, 'freq');
assert((hastime && hasfreq), 'please use ft_singleplotER for time-only or frequency-only data');
xparam = 'time';
yparam = 'freq';
% check whether rpt/subj is present and remove if necessary
dimord = getdimord(data, cfg.parameter);
dimtok = tokenize(dimord, '_');
hasrpt = any(ismember(dimtok, {'rpt' 'subj'}));
if ~hasrpt
assert(isequal(cfg.trials, 'all') || isequal(cfg.trials, 1), 'incorrect specification of cfg.trials for data without repetitions');
else
assert(~isempty(cfg.trials), 'empty specification of cfg.trials for data with repetitions');
end
% parse cfg.channel
if isfield(cfg, 'channel') && isfield(data, 'label')
cfg.channel = ft_channelselection(cfg.channel, data.label);
elseif isfield(cfg, 'channel') && isfield(data, 'labelcmb')
cfg.channel = ft_channelselection(cfg.channel, unique(data.labelcmb(:)));
end
% Apply baseline correction:
if ~strcmp(cfg.baseline, 'no')
% keep mask-parameter if it is set
if ~isempty(cfg.maskparameter)
tempmask = data.(cfg.maskparameter);
end
data = ft_freqbaseline(cfg, data);
% put mask-parameter back if it is set
if ~isempty(cfg.maskparameter)
data.(cfg.maskparameter) = tempmask;
end
end
% channels should NOT be selected and averaged here, since a topoplot might follow in interactive mode
tmpcfg = keepfields(cfg, {'showcallinfo', 'trials'});
if hasrpt
tmpcfg.avgoverrpt = 'yes';
else
tmpcfg.avgoverrpt = 'no';
end
tmpvar = data;
[data] = ft_selectdata(tmpcfg, data);
% restore the provenance information and put back cfg.channel
tmpchannel = cfg.channel;
[cfg, data] = rollback_provenance(cfg, data);
cfg.channel = tmpchannel;
if isfield(tmpvar, cfg.maskparameter) && ~isfield(data, cfg.maskparameter)
% the mask parameter is not present after ft_selectdata, because it is
% not included in all input arguments. Make the same selection and copy
% it over
tmpvar = ft_selectdata(tmpcfg, tmpvar);
data.(cfg.maskparameter) = tmpvar.(cfg.maskparameter);
end
clear tmpvar tmpcfg dimord dimtok hastime hasfreq hasrpt
% ensure that the preproc specific options are located in the cfg.preproc
% substructure, but also ensure that the field 'refchannel' remains at the
% highest level in the structure. This is a little hack by JM because the field
% refchannel can relate to connectivity or to an EEg reference.
if isfield(cfg, 'refchannel'), refchannelincfg = cfg.refchannel; cfg = rmfield(cfg, 'refchannel'); end
cfg = ft_checkconfig(cfg, 'createsubcfg', {'preproc'});
if exist('refchannelincfg', 'var'), cfg.refchannel = refchannelincfg; end
if ~isempty(cfg.preproc)
% preprocess the data, i.e. apply filtering, baselinecorrection, etc.
fprintf('applying preprocessing options\n');
if ~isfield(cfg.preproc, 'feedback')
cfg.preproc.feedback = cfg.interactive;
end
data = ft_preprocessing(cfg.preproc, data);
end
% Handle the bivariate case
dimord = getdimord(data, cfg.parameter);
if startsWith(dimord, 'chan_chan_') || startsWith(dimord, 'chancmb_')
% convert the bivariate data to univariate and call this plotting function again
cfg.originalfunction = 'ft_singleplotTFR';
cfg.trials = 'all'; % trial selection has been taken care off
bivariate_common(cfg, data);
return
end
% Apply channel-type specific scaling
tmpcfg = keepfields(cfg, {'parameter', 'chanscale', 'ecgscale', 'eegscale', 'emgscale', 'eogscale', 'gradscale', 'magscale', 'megscale', 'mychan', 'mychanscale'});
[data] = chanscale_common(tmpcfg, data);
%% Section 3: select the data to be plotted and determine min/max range
% Take the subselection of channels that is contained in the layout, this is the same in all datasets
[selchan] = match_str(data.label, cfg.channel);
% Get physical min/max range of x, i.e. time
if strcmp(cfg.xlim, 'maxmin')
xmin = min(data.(xparam));
xmax = max(data.(xparam));
else
xmin = cfg.xlim(1);
xmax = cfg.xlim(2);
end
% Get the index of the nearest bin
xminindx = nearest(data.(xparam), xmin);
xmaxindx = nearest(data.(xparam), xmax);
xmin = data.(xparam)(xminindx);
xmax = data.(xparam)(xmaxindx);
selx = xminindx:xmaxindx;
xval = data.(xparam)(selx);
% Get physical min/max range of y, i.e. frequency
if strcmp(cfg.ylim, 'maxmin')
ymin = min(data.(yparam));
ymax = max(data.(yparam));
else
ymin = cfg.ylim(1);
ymax = cfg.ylim(2);
end
% Get the index of the nearest bin
yminindx = nearest(data.(yparam), ymin);
ymaxindx = nearest(data.(yparam), ymax);
ymin = data.(yparam)(yminindx);
ymax = data.(yparam)(ymaxindx);
sely = yminindx:ymaxindx;
yval = data.(yparam)(sely);
% test if X and Y are linearly spaced (to within 10^-12): % FROM UIMAGE
dx = min(diff(xval)); % smallest interval for X
dy = min(diff(yval)); % smallest interval for Y
evenx = all(abs(diff(xval)/dx-1)<1e-12); % true if X is linearly spaced
eveny = all(abs(diff(yval)/dy-1)<1e-12); % true if Y is linearly spaced
if ~evenx || ~eveny
ft_warning('(one of the) axis is/are not evenly spaced, but plots are made as if axis are linear')
end
% masking is only possible for evenly spaced axis
if strcmp(cfg.masknans, 'yes') && (~evenx || ~eveny)
ft_warning('(one of the) axis are not evenly spaced -> nans cannot be masked out -> cfg.masknans is set to ''no'';')
cfg.masknans = 'no';
end
% the usual data is chan_freq_time, but other dimords should also work
dimtok = tokenize(dimord, '_');
datamatrix = data.(cfg.parameter);
[c, ia, ib] = intersect(dimtok, {'chan', yparam, xparam});
datamatrix = permute(datamatrix, ia);
datamatrix = datamatrix(selchan, sely, selx);
if ~isempty(cfg.maskparameter)
maskmatrix = data.(cfg.maskparameter)(selchan, sely, selx);
if cfg.maskalpha ~= 1
maskmatrix( maskmatrix) = 1;
maskmatrix(~maskmatrix) = cfg.maskalpha;
end
else
% create an Nx0x0 matrix
maskmatrix = zeros(length(selchan), 0, 0);
end
%% Section 4: do the actual plotting
cla
hold on
zval = mean(datamatrix, 1); % over channels
zval = reshape(zval, size(zval,2), size(zval,3));
mask = squeeze(mean(maskmatrix, 1)); % over channels
% Get physical z-axis range (color axis):
if strcmp(cfg.zlim, 'maxmin')
zmin = nanmin(zval(:));
zmax = nanmax(zval(:));
elseif strcmp(cfg.zlim, 'maxabs')
zmin = -nanmax(abs(zval(:)));
zmax = nanmax(abs(zval(:)));
elseif strcmp(cfg.zlim, 'zeromax')
zmin = 0;
zmax = nanmax(zval(:));
elseif strcmp(cfg.zlim, 'minzero')
zmin = nanmin(zval(:));
zmax = 0;
else
zmin = cfg.zlim(1);
zmax = cfg.zlim(2);
end
% Draw the data and mask NaN's if requested
if isequal(cfg.masknans, 'yes') && isempty(cfg.maskparameter)
nans_mask = ~isnan(zval);
mask = double(nans_mask);
ft_plot_matrix(xval, yval, zval, 'clim', [zmin zmax], 'tag', 'cip', 'highlightstyle', cfg.maskstyle, 'highlight', mask)
elseif isequal(cfg.masknans, 'yes') && ~isempty(cfg.maskparameter)
nans_mask = ~isnan(zval);
mask = mask .* nans_mask;
mask = double(mask);
ft_plot_matrix(xval, yval, zval, 'clim', [zmin zmax], 'tag', 'cip', 'highlightstyle', cfg.maskstyle, 'highlight', mask)
elseif isequal(cfg.masknans, 'no') && ~isempty(cfg.maskparameter)
mask = double(mask);
ft_plot_matrix(xval, yval, zval, 'clim', [zmin zmax], 'tag', 'cip', 'highlightstyle', cfg.maskstyle, 'highlight', mask)
else
ft_plot_matrix(xval, yval, zval, 'clim', [zmin zmax], 'tag', 'cip')
end
% set colormap
if isfield(cfg, 'colormap')
if ~isnumeric(cfg.colormap)
cfg.colormap = colormap(cfg.colormap);
end
if size(cfg.colormap,2)~=3
ft_error('colormap must be a Nx3 matrix');
else
set(gcf, 'colormap', cfg.colormap);
end
end
% Set renderer if specified
if ~isempty(cfg.renderer)
set(gcf, 'renderer', cfg.renderer)
end
axis xy
if isequal(cfg.colorbar, 'yes')
% tag the colorbar so we know which axes are colorbars
%colorbar('tag', 'ft-colorbar');
narrow_colorbar()
end
% Set callback to adjust color axis
if strcmp('yes', cfg.hotkeys)
% Attach data and cfg to figure and attach a key listener to the figure
set(gcf, 'KeyPressFcn', {@key_sub, xmin, xmax, ymin, ymax, zmin, zmax})
end
% Create axis title containing channel name(s) and channel number(s):
if ~isempty(cfg.title)
t = cfg.title;
else
if length(cfg.channel) == 1
t = [char(cfg.channel) ' / ' num2str(selchan) ];
else
t = sprintf('mean(%0s)', join_str(', ', cfg.channel));
end
end
title(t, 'fontsize', cfg.fontsize);
% set the figure window title, add channel labels if number is small
if isempty(get(gcf, 'Name'))
if length(selchan) < 5
chans = join_str(', ', cfg.channel);
else
chans = '<multiple channels>';
end
if isempty(cfg.figurename)
set(gcf, 'Name', sprintf('%d: %s: %s (%s)', double(gcf), mfilename, dataname, chans));
set(gcf, 'NumberTitle', 'off');
else
set(gcf, 'name', cfg.figurename);
set(gcf, 'NumberTitle', 'off');
end
end
axis tight
hold off
% Make the figure interactive
if strcmp(cfg.interactive, 'yes')
% add the cfg/data information to the figure under identifier linked to this axis
ident = ['axh' num2str(round(sum(clock.*1e6)))]; % unique identifier for this axis
set(gca, 'tag',ident);
info = guidata(gcf);
info.(ident).dataname = dataname;
info.(ident).cfg = cfg;
info.(ident).data = data;
guidata(gcf, info);
set(gcf, 'WindowButtonUpFcn', {@ft_select_range, 'multiple', false, 'callback', {@select_topoplotTFR}, 'event', 'WindowButtonUpFcn'});
set(gcf, 'WindowButtonDownFcn', {@ft_select_range, 'multiple', false, 'callback', {@select_topoplotTFR}, 'event', 'WindowButtonDownFcn'});
set(gcf, 'WindowButtonMotionFcn', {@ft_select_range, 'multiple', false, 'callback', {@select_topoplotTFR}, 'event', 'WindowButtonMotionFcn'});
end
% add a menu to the figure, but only if the current figure does not have subplots
% also, delete any possibly existing previous menu, this is safe because delete([]) does nothing
delete(findobj(gcf, 'type', 'uimenu', 'label', 'FieldTrip'));
if numel(findobj(gcf, 'type', 'axes', '-not', 'tag', 'ft-colorbar')) <= 1
ftmenu = uimenu(gcf, 'Label', 'FieldTrip');
uimenu(ftmenu, 'Label', 'Show pipeline', 'Callback', {@menu_pipeline, cfg});
uimenu(ftmenu, 'Label', 'About', 'Callback', @menu_about);
end
% do the general cleanup and bookkeeping at the end of the function
ft_postamble debug
ft_postamble trackconfig
ft_postamble previous data
ft_postamble provenance
if ~nargout
% don't return anything
clear cfg
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUBFUNCTION which is called after selecting a time range
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function select_topoplotTFR(range, varargin)
% fetch cfg/data based on axis indentifier given as tag
ident = get(gca, 'tag');
info = guidata(gcf);
cfg = info.(ident).cfg;
data = info.(ident).data;
if ~isempty(range)
cfg = removefields(cfg, 'inputfile'); % the reading has already been done and varargin contains the data
cfg = removefields(cfg, 'showlabels'); % this is not allowed in topoplotER
cfg.trials = 'all'; % trial selection has already been taken care of
cfg.baseline = 'no'; % make sure the next function does not apply a baseline correction again
cfg.channel = 'all'; % make sure the topo displays all channels, not just the ones in this singleplot
cfg.comment = 'auto';
cfg.dataname = info.(ident).dataname; % put data name in here, this cannot be resolved by other means
cfg.xlim = range(1:2);
cfg.ylim = range(3:4);
fprintf('selected cfg.xlim = [%f %f]\n', cfg.xlim(1), cfg.xlim(2));
fprintf('selected cfg.ylim = [%f %f]\n', cfg.ylim(1), cfg.ylim(2));
% ensure that the new figure appears at the same position
f = figure('Position', get(gcf, 'Position'));
ft_topoplotTFR(cfg, data);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUBFUNCTION which handles hot keys in the current plot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function key_sub(handle, eventdata, varargin)
xlimits = xlim;
ylimits = ylim;
climits = caxis;
incr_x = abs(xlimits(2) - xlimits(1)) /10;
incr_y = abs(ylimits(2) - ylimits(1)) /10;
incr_c = abs(climits(2) - climits(1)) /10;
if length(eventdata.Modifier) == 1 && strcmp(eventdata.Modifier{:}, 'control')
% TRANSLATE by 10%
switch eventdata.Key
case 'pageup'
caxis([min(caxis)+incr_c max(caxis)+incr_c]);
case 'pagedown'
caxis([min(caxis)-incr_c max(caxis)-incr_c]);
case 'leftarrow'
xlim([xlimits(1)+incr_x xlimits(2)+incr_x])
case 'rightarrow'
xlim([xlimits(1)-incr_x xlimits(2)-incr_x])
case 'uparrow'
ylim([ylimits(1)-incr_y ylimits(2)-incr_y])
case 'downarrow'
ylim([ylimits(1)+incr_y ylimits(2)+incr_y])
end % switch
else
% ZOOM by 10%
switch eventdata.Key
case 'pageup'
caxis([min(caxis)-incr_c max(caxis)+incr_c]);
case 'pagedown'
caxis([min(caxis)+incr_c max(caxis)-incr_c]);
case 'leftarrow'
xlim([xlimits(1)-incr_x xlimits(2)+incr_x])
case 'rightarrow'
xlim([xlimits(1)+incr_x xlimits(2)-incr_x])
case 'uparrow'
ylim([ylimits(1)-incr_y ylimits(2)+incr_y])
case 'downarrow'
ylim([ylimits(1)+incr_y ylimits(2)-incr_y])
case 'm'
xlim([varargin{1} varargin{2}])
ylim([varargin{3} varargin{4}])
caxis([varargin{5} varargin{6}]);
end % switch
end % if
|
github
|
Aleman-Z/CorticoHippocampal-master
|
generate2_new.m
|
.m
|
CorticoHippocampal-master/Ideas_testing/generate2_new.m
| 354 |
utf_8
|
8cfbff66a7bba6d8e89a6b7ef2ba1515
|
%Hippocampus Bipolar
%Hippocampus Monopolar
%function [p3, p5,cellx,cellr,cfs,f]=generate2(carajo,veamos, Bip17,S17,label1,label2,Num)
function [cellx,cellr]=generate2_new(carajo,veamos, Bip17,S17,label1,label2,Num)
fn=1000;
%Generates windows
[cellx,cellr]=win_new(carajo,veamos,Bip17,S17,Num);
%Clears nans
% [cellx,cellr]=clean(cellx,cellr);
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_conditions_33_TEST.m
|
.m
|
CorticoHippocampal-master/Ideas_testing/plot_inter_conditions_33_TEST.m
| 12,603 |
utf_8
|
b3ba74de00c7c083ee226c557dc1cede
|
%This one requires running data from Non Learning condition
function [h]=plot_inter_conditions_33_TEST(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,acer)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% ripple3=ripple_nl;
%ran=randi(length(p),100,1);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
[ran_nl]=select_rip(p_nl);
%
% av=cat(1,p_nl{1:end});
% %av=cat(1,q_nl{1:end});
% av=av(1:3:end,:); %Only Hippocampus
%
% %AV=max(av.');
% %[B I]= maxk(AV,1000);
%
% %AV=max(av.');
% %[B I]= maxk(max(av.'),1000);
%
%
% [ach]=max(av.');
% achinga=sort(ach,'descend');
% %achinga=achinga(1:1000);
% if length(achinga)>1000
% if Rat==24
% achinga=achinga(6:1005);
% else
% achinga=achinga(1:1000);
% end
% end
%
% B=achinga;
% I=nan(1,length(B));
% for hh=1:length(achinga)
% % I(hh)= min(find(ach==achinga(hh)));
% I(hh)= find(ach==achinga(hh),1,'first');
% end
%
%
% [ajal ind]=unique(B);
% if length(ajal)>500
% ajal=ajal(end-499:end);
% ind=ind(end-499:end);
% end
% dex=I(ind);
%
% ran_nl=dex.';
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
%timecell_nl=timecell_nl([ran_nl]);
%Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,create_timecell(ro,length(p_nl)));
P2_nl=avg_samples(p_nl,create_timecell(ro,length(p_nl)));
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% cd(strcat('D:\internship\',num2str(Rat)))
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
%%
h(1)=subplot(3,4,1)
%plot(timecell_nl{1},P2_nl(w,:))
plot(cell2mat(create_timecell(ro,1)),P2_nl(w,:))
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('Wide Band No Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (t)')
ylabel('uV')
%%
h(3)=subplot(3,4,3)
plot(cell2mat(create_timecell(ro,1)),P1_nl(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('High Gamma No Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
xlabel('Time (t)')
ylabel('uV')
%%
h(2)=subplot(3,4,2)
plot(cell2mat(create_timecell(ro,1)),P2(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(4)=subplot(3,4,4)
plot(cell2mat(create_timecell(ro,1)),P1(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%% Time Frequency plots
% Calculate Freq1 and Freq2
if ro==1200
toy = [-1.2:.01:1.2];
else
%toy = [-10.2:.1:10.2];
toy = [-10.2:.01:10.2];
end
%toy = [-1.2:.01:1.2];
if length(p)>length(p_nl)
p=p(1:length(p_nl));
%timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
%timecell_nl=timecell_nl(1:length(p));
end
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
h(5)=subplot(3,4,5)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band No Learning');
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
h(6)=subplot(3,4,6)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
ylim([0.5 30])
%%
if ro==1200
[stats]=stats_between_trials(freq1,freq2,label1,w);
else
[stats]=stats_between_trials10(freq1,freq2,label1,w);
end
%%
h(9)=subplot(3,4,10)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
g=title(strcat(labelconditions{iii},' vs No Learning'))
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%Calculate Freq3 and Freq4
%toy=[-1:.01:1];
if ro==1200
toy=[-1:.01:1];
else
%toy=[-10:.1:10];
toy=[-10:.01:10];
end
if length(q)>length(q_nl)
q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
% timecell_nl=timecell_nl(1:length(q));
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
cfg = [];
cfg.channel = freq3.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq3);
[zmin2, zmax2] = ft_getminmax(cfg, freq4);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;
cfg.channel = freq3.label{w};
cfg.colormap=colormap(jet(256));
%%
h(7)=subplot(3,4,7)
ft_singleplotTFR(cfg, freq3);
% freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
g=title('High Gamma No Learning');
g.FontSize=12;
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%
h(8)=subplot(3,4,8);
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
ft_singleplotTFR(cfg, freq4);
g=title(strcat('High Gamma',{' '},labelconditions{iii}));
g.FontSize=12;
%title(strcat('High Gamma',{' '},labelconditions{iii}))
%xo
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
if ro==1200
[stats1]=stats_between_trials(freq3,freq4,label1,w);
else
[stats1]=stats_between_trials10(freq3,freq4,label1,w);
end
%% %
h(10)=subplot(3,4,12);
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%% EXTRA STATISTICS
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_cohen.m
|
.m
|
CorticoHippocampal-master/Ideas_testing/plot_inter_cohen.m
| 18,429 |
utf_8
|
f2214a1523c0875c527f9279b2153fa5
|
%This one requires running data from Non Learning condition
function [h]=plot_inter_cohen(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,acer,block_time,NFF,mergebaseline,FiveHun,meth,rat26session3,rat27session3,notch,sanity,quinientos,outlie,varargin)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% ripple3=ripple_nl;
%ran=randi(length(p),100,1);
randrip=varargin;
randrip=cell2mat(randrip);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
%This one:
% % % [p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% if meth==3
% [p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),chtm);
% else
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% end
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
if outlie==1
ache=max_outlier(p_nl);
p_nl=p_nl(ache);
q_nl=q_nl(ache);
end
if quinientos==0
[ran_nl]=select_rip(p_nl,FiveHun);
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
else
if iii~=2
[ran_nl]=select_quinientos(p_nl,length(randrip));
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
% ran=1:length(randrip);
end
end
%timecell_nl=timecell_nl([ran_nl]);
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
if mergebaseline==1
%%
'MERGING BASELINES'
L1=length(p_nl);
NU{1}=p_nl;
QNU{1}=q_nl;
%% Other Baseline
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1}) %Baseline
% [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
if meth==1
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=newest_only_ripple_level_ERASETHIS(level);
end
if meth==2
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,RipFreq3,timeasleep2]=median_std;
end
if meth==3
chtm=load('vq_loop2.mat');
chtm=chtm.vq;
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
if meth==4
[timeasleep]=find_thr_base;
ror=2000/timeasleep;
if acer==0
cd(strcat('/home/raleman/Dropbox/Figures/Figure2/',num2str(Rat)))
else
%cd(strcat('C:\Users\Welt Meister\Dropbox\Figures\Figure2\',num2str(Rat)))
cd(strcat('C:\Users\addri\Dropbox\Figures\Figure2\',num2str(Rat)))
end
if Rat==26
Base=[{'Baseline1'} {'Baseline2'}];
end
if Rat==26 && rat26session3==1
Base=[{'Baseline3'} {'Baseline2'}];
end
if Rat==27
Base=[{'Baseline2'} {'Baseline1'}];% We run Baseline 2 first, cause it is the one we prefer.
end
if Rat==27 && rat27session3==1
Base=[{'Baseline2'} {'Baseline3'}];% We run Baseline 2 first, cause it is the one we prefer.
end
base=2; %VERY IMPORTANT!
%openfig('Ripples_per_condition_best.fig')
openfig(strcat('Ripples_per_condition_',Base{base},'.fig'))
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes
ydata=dataObjs{2}(8).YData;
xdata=dataObjs{2}(8).XData;
% figure()
% plot(xdata,ydata)
chtm = interp1(ydata,xdata,ror);
close
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1})
%xo
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
CHTM2=[chtm chtm];
end
%This seems incomplete:
% if meth==4
% [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,RipFreq3,timeasleep2,~]=nrem_fixed_thr_Vfiles(chtm,notch);
% CHTM2=[chtm chtm];
% end
if block_time==1
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,30,0);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
if block_time==2
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,60,30);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
%%
clear sig1_nl sig2_nl
if quinientos==0
[ran_nl]=select_rip(p_nl,FiveHun);
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
else
if iii~=2
[ran_nl]=select_quinientos(p_nl,length(randrip));
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
% ran=1:length(randrip);
end
end
%timecell_nl=timecell_nl([ran_nl]);
if sanity==1 && quinientos==0
p_nl=p_nl(randrip);
q_nl=q_nl(randrip);
end
%%
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
NU{2}=p_nl;
QNU{2}=q_nl;
L2=length(p_nl);
amount=min([L1 L2]);
% p_nl(1:amount)=NU{1}(1:amount);
% p_nl(amount+1:2*amount)=NU{2}(1:amount);
p_nl(1:2*amount)=[NU{1}(1:amount) NU{1}(1:amount)];
p_nl(2:2:end)=[NU{2}(1:length(p_nl(2:2:end)))];
% q_nl(1:amount)=QNU{1}(1:amount);
% q_nl(amount+1:2*amount)=QNU{2}(1:amount);
q_nl(1:2*amount)=[QNU{1}(1:amount) QNU{1}(1:amount)];
q_nl(2:2:end)=[QNU{2}(1:length(q_nl(2:2:end)))];
end
clear sig1_nl sig2_nl
%This is where you may check both p and p_nl lenghts to make them the same.
if length(p)>length(p_nl)
p=p(1:length(p_nl));
%timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
%timecell_nl=timecell_nl(1:length(p));
end
if length(q)>length(q_nl)
q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
% timecell_nl=timecell_nl(1:length(q));
end
%Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,create_timecell(ro,length(p_nl)));
P2_nl=avg_samples(p_nl,create_timecell(ro,length(p_nl)));
P1=avg_samples(q,create_timecell(ro,length(p)));
P2=avg_samples(p,create_timecell(ro,length(p)));
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
%cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%%
allscreen()
%%
h(1)=subplot(3,4,1)
%plot(timecell_nl{1},P2_nl(w,:))
plot(cell2mat(create_timecell(ro,1)),P2_nl(w,:))
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('Wide Band No Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(3)=subplot(3,4,3)
plot(cell2mat(create_timecell(ro,1)),P1_nl(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('High Gamma No Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%%
h(2)=subplot(3,4,2)
plot(cell2mat(create_timecell(ro,1)),P2(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(4)=subplot(3,4,4)
plot(cell2mat(create_timecell(ro,1)),P1(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%%
clear P1 P2
%% Time Frequency plots
% Calculate Freq1 and Freq2
if ro==1200
toy = [-1.2:.01:1.2];
else
%toy = [-10.2:.1:10.2];
toy = [-10.2:.01:10.2];
end
%toy = [-1.2:.01:1.2];
if length(p)>length(p_nl)
p=p(1:length(p_nl));
%timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
%timecell_nl=timecell_nl(1:length(p));
end
%%
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
h(5)=subplot(3,4,5)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band No Learning');
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
h(6)=subplot(3,4,6)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
ylim([0.5 30])
%%
if ro==1200
[stats]=stats_between_trials(freq1,freq2,label1,w);
else
[stats]=stats_between_trials10(freq1,freq2,label1,w);
end
%%
h(9)=subplot(3,4,9)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
g=title(strcat(labelconditions{iii},' vs No Learning'))
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
zmap=stats_high(freq1,freq2,w);
subplot(3,4,10);
colormap(jet(256))
zmap(zmap == 0) = NaN;
J=imagesc(freq1.time,freq1.freq,zmap)
xlabel('Time (s)'), ylabel('Frequency (Hz)')
%title('tf power map, thresholded')
set(gca,'xlim',xlim,'ydir','no')
% c=narrow_colorbar()
set(J,'AlphaData',~isnan(zmap))
c=narrow_colorbar()
c.YLim=[-max(abs(c.YLim)) max(abs(c.YLim))];
caxis([-max(abs(c.YLim)) max(abs(c.YLim))])
c=narrow_colorbar()
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
xlim([-1 1])
%%
clear freq1 freq2 p_nl p
%Calculate Freq3 and Freq4
%toy=[-1:.01:1];
if ro==1200
toy=[-1:.01:1];
else
%toy=[-10:.1:10];
toy = [-10:.01:10];
end
if length(q)>length(q_nl)
q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
% timecell_nl=timecell_nl(1:length(q));
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
%U might want to uncomment this if you use a smaller step: (Memory purposes)
cfg = [];
cfg.channel = freq3.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq3);
[zmin2, zmax2] = ft_getminmax(cfg, freq4);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim; %U might want to uncomment this if you use a smaller step: (Memory purposes)
cfg.channel = freq3.label{w};
cfg.colormap=colormap(jet(256));
%%
h(7)=subplot(3,4,7)
ft_singleplotTFR(cfg, freq3);
% freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
g=title('High Gamma No Learning');
g.FontSize=12;
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%clear freq3
%%
%
h(8)=subplot(3,4,8);
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
ft_singleplotTFR(cfg, freq4);
g=title(strcat('High Gamma',{' '},labelconditions{iii}));
g.FontSize=12;
%title(strcat('High Gamma',{' '},labelconditions{iii}))
%xo
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%clear freq4
%%
if ro==1200
[stats1]=stats_between_trials(freq3,freq4,label1,w);
else
[stats1]=stats_between_trials10(freq3,freq4,label1,w);
end
%% %
h(10)=subplot(3,4,11);
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
% ft_singleplotTFR(cfg, stats1);
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%% EXTRA STATISTICS
zmap=stats_high(freq3,freq4,w);
subplot(3,4,12);
colormap(jet(256))
zmap(zmap == 0) = NaN;
J=imagesc(freq3.time,freq3.freq,zmap)
xlabel('Time (s)'), ylabel('Frequency (Hz)')
%title('tf power map, thresholded')
set(gca,'xlim',xlim,'ydir','no')
% c=narrow_colorbar()
set(J,'AlphaData',~isnan(zmap))
c=narrow_colorbar()
c.YLim=[-max(abs(c.YLim)) max(abs(c.YLim))];
caxis([-max(abs(c.YLim)) max(abs(c.YLim))])
c=narrow_colorbar()
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%%
%%
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_inter_conditions_mergebaselines.m
|
.m
|
CorticoHippocampal-master/Ideas_testing/plot_inter_conditions_mergebaselines.m
| 14,731 |
utf_8
|
6d8536abe8287dcd4fc58286df64dbd5
|
%This one requires running data from Non Learning condition
function [h]=plot_inter_conditions_mergebaselines(Rat,nFF,level,ro,w,labelconditions,label1,label2,iii,P1,P2,p,timecell,sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,q,timeasleep2,RipFreq3,RipFreq2,timeasleep,ripple,CHTM,acer,block_time,NFF,mergebaseline)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % cd(nFF{3})
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %run('newest_load_data_nl.m')
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % [sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2]=newest_only_ripple_nl;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % ripple3=ripple_nl;
% ripple3=ripple_nl;
%ran=randi(length(p),100,1);
% % % % % % % sig1_nl=cell(7,1);
% % % % % % %
% % % % % % % sig1_nl{1}=Mono17_nl;
% % % % % % % sig1_nl{2}=Bip17_nl;
% % % % % % % sig1_nl{3}=Mono12_nl;
% % % % % % % sig1_nl{4}=Bip12_nl;
% % % % % % % sig1_nl{5}=Mono9_nl;
% % % % % % % sig1_nl{6}=Bip9_nl;
% % % % % % % sig1_nl{7}=Mono6_nl;
% % % % % % %
% % % % % % %
% % % % % % % sig2_nl=cell(7,1);
% % % % % % %
% % % % % % % sig2_nl{1}=V17_nl;
% % % % % % % sig2_nl{2}=S17_nl;
% % % % % % % sig2_nl{3}=V12_nl;
% % % % % % % % sig2{4}=R12;
% % % % % % % sig2_nl{4}=S12_nl;
% % % % % % % %sig2{6}=SSS12;
% % % % % % % sig2_nl{5}=V9_nl;
% % % % % % % % sig2{7}=R9;
% % % % % % % sig2_nl{6}=S9_nl;
% % % % % % % %sig2{10}=SSS9;
% % % % % % % sig2_nl{7}=V6_nl;
% % % % % % %
% % % % % % % % ripple=length(M);
% % % % % % %
% % % % % % % %Number of ripples per threshold.
% % % % % % % ripple_nl=sum(s17_nl);
% [p_nl,q_nl,timecell_nl,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),thr_nl(level+1));
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
[ran_nl]=select_rip(p_nl);
%
% av=cat(1,p_nl{1:end});
% %av=cat(1,q_nl{1:end});
% av=av(1:3:end,:); %Only Hippocampus
%
% %AV=max(av.');
% %[B I]= maxk(AV,1000);
%
% %AV=max(av.');
% %[B I]= maxk(max(av.'),1000);
%
%
% [ach]=max(av.');
% achinga=sort(ach,'descend');
% %achinga=achinga(1:1000);
% if length(achinga)>1000
% if Rat==24
% achinga=achinga(6:1005);
% else
% achinga=achinga(1:1000);
% end
% end
%
% B=achinga;
% I=nan(1,length(B));
% for hh=1:length(achinga)
% % I(hh)= min(find(ach==achinga(hh)));
% I(hh)= find(ach==achinga(hh),1,'first');
% end
%
%
% [ajal ind]=unique(B);
% if length(ajal)>500
% ajal=ajal(end-499:end);
% ind=ind(end-499:end);
% end
% dex=I(ind);
%
% ran_nl=dex.';
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
%timecell_nl=timecell_nl([ran_nl]);
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
L1=length(p_nl);
NU{1}=p_nl;
QNU{1}=q_nl;
%TNU{1}=create_timecell(ro,length(p_nl));
%% Other Baseline
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
cd(NFF{1}) %Baseline
%run('newest_load_data_nl.m')
%[sig1_nl,sig2_nl,ripple2_nl,carajo_nl,veamos_nl,CHTM_nl]=newest_only_ripple_nl;
[sig1_nl,sig2_nl,ripple_nl,carajo_nl,veamos_nl,CHTM2,timeasleep2,RipFreq3]=newest_only_ripple_nl_level(level);
if block_time==1
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,30,0);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
if block_time==2
[carajo_nl,veamos_nl]=equal_time2(sig1_nl,sig2_nl,carajo_nl,veamos_nl,60,30);
ripple_nl=sum(cellfun('length',carajo_nl{1}(:,1)));
end
%xo
[p_nl,q_nl,~,~,~,~]=getwin2(carajo_nl{:,:,level},veamos_nl{level},sig1_nl,sig2_nl,label1,label2,ro,ripple_nl(level),CHTM2(level+1));
% % % % % load(strcat('randnum2_',num2str(level),'.mat'))
% % % % % ran_nl=ran;
[ran_nl]=select_rip(p_nl);
p_nl=p_nl([ran_nl]);
q_nl=q_nl([ran_nl]);
%timecell_nl=timecell_nl([ran_nl]);
[q_nl]=filter_ripples(q_nl,[66.67 100 150 266.7 133.3 200 300 333.3 266.7 233.3 250 166.7 133.3],.5,.5);
NU{2}=p_nl;
QNU{2}=q_nl;
%TNU{2}=create_timecell(ro,length(p_nl));
L2=length(p_nl);
amount=min([L1 L2]);
p_nl(1:amount)=NU{1}(1:amount);
p_nl(amount+1:2*amount)=NU{2}(1:amount);
q_nl(1:amount)=QNU{1}(1:amount);
q_nl(amount+1:2*amount)=QNU{2}(1:amount);
% [L1 L2]
% length(p_nl)
%xo
%%
%Need: P1, P2 ,p, q.
P1_nl=avg_samples(q_nl,create_timecell(ro,length(p_nl)));
P2_nl=avg_samples(p_nl,create_timecell(ro,length(p_nl)));
%cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
if acer==0
cd(strcat('/home/raleman/Documents/internship/',num2str(Rat)))
else
cd(strcat('D:\internship\',num2str(Rat)))
end
%cd(strcat('D:\internship\',num2str(Rat)))
cd(nFF{iii})
%%
%Plot both: No ripples and Ripples.
allscreen()
%%
h(1)=subplot(3,4,1)
%plot(timecell_nl{1},P2_nl(w,:))
plot(cell2mat(create_timecell(ro,1)),P2_nl(w,:))
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('Wide Band No Learning')
win1=[min(P2_nl(w,:)) max(P2_nl(w,:)) min(P2(w,:)) max(P2(w,:))];
win1=[(min(win1)) round(max(win1))];
ylim(win1)
xlabel('Time (t)')
ylabel('uV')
%%
h(3)=subplot(3,4,3)
plot(cell2mat(create_timecell(ro,1)),P1_nl(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title('High Gamma No Learning')
win2=[min(P1_nl(w,:)) max(P1_nl(w,:)) min(P1(w,:)) max(P1(w,:))];
win2=[(min(win2)) (max(win2))];
ylim(win2)
xlabel('Time (t)')
ylabel('uV')
%%
h(2)=subplot(3,4,2)
plot(cell2mat(create_timecell(ro,1)),P2(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
title(strcat('Wide Band',{' '},labelconditions{iii}))
%title(strcat('Wide Band',{' '},labelconditions{iii}))
ylim(win1)
xlabel('Time (s)')
ylabel('uV')
%%
h(4)=subplot(3,4,4)
plot(cell2mat(create_timecell(ro,1)),P1(w,:))
%xlim([-1,1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
%xlim([-0.8,0.8])
%grid minor
% narrow_colorbar()
%title('High Gamma RIPPLE')
title(strcat('High Gamma',{' '},labelconditions{iii}))
%title(strcat('High Gamma',{' '},labelconditions{iii}))
ylim(win2)
xlabel('Time (s)')
ylabel('uV')
%% Time Frequency plots
% Calculate Freq1 and Freq2
if ro==1200
toy = [-1.2:.01:1.2];
else
toy = [-10.2:.1:10.2];
end
%toy = [-1.2:.01:1.2];
if length(p)>length(p_nl)
p=p(1:length(p_nl));
%timecell=timecell(1:length(p_nl));
end
if length(p)<length(p_nl)
p_nl=p_nl(1:length(p));
%timecell_nl=timecell_nl(1:length(p));
end
freq1=justtesting(p_nl,create_timecell(ro,length(p_nl)),[1:0.5:30],w,10,toy);
freq2=justtesting(p,create_timecell(ro,length(p)),[1:0.5:30],w,0.5,toy);
%
% FREQ1=justtesting(p_nl,timecell_nl,[0.5:0.5:30],w,10,toy);
% FREQ2=justtesting(p,timecell,[0.5:0.5:30],w,0.5,toy);
% Calculate zlim
%%
% Freq10=ft_freqbaseline(cfg,FREQ1);
% Freq20=ft_freqbaseline(cfg,FREQ2);
%%
cfg = [];
cfg.channel = freq1.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq1);
[zmin2, zmax2] = ft_getminmax(cfg, freq2);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;% Uncomment this!
cfg.channel = freq1.label{w};
cfg.colormap=colormap(jet(256));
% % cfg.baseline = 'yes';
% % % cfg.baseline = [ -0.1];
% %
% % cfg.baselinetype = 'absolute';
% % cfg.renderer = [];
% % %cfg.renderer = 'painters', 'zbuffer', ' opengl' or 'none' (default = [])
% % cfg.colorbar = 'yes';
%%
h(5)=subplot(3,4,5)
ft_singleplotTFR(cfg, freq1);
% freq1=justtesting(p_nl,timecell_nl,[1:0.5:30],w,10)
g=title('Wide Band No Learning');
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
h(6)=subplot(3,4,6)
ft_singleplotTFR(cfg, freq2);
% freq2=justtesting(p,timecell,[1:0.5:30],w,0.5)
%title('Wide Band RIPPLE')
g=title(strcat('Wide Band',{' '},labelconditions{iii}));
%title(strcat('Wide Band',{' '},labelconditions{iii}))
g.FontSize=12;
%xlim([-1 1])
if ro==1200
xlim([-1,1])
else
xlim([-10,10])
end
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%error('stop')
ylim([0.5 30])
%%
if ro==1200
[stats]=stats_between_trials(freq1,freq2,label1,w);
else
[stats]=stats_between_trials10(freq1,freq2,label1,w);
end
%%
h(9)=subplot(3,4,10)
%
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats);
% title('Condition vs No Learning')
g=title(strcat(labelconditions{iii},' vs No Learning'))
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%Calculate Freq3 and Freq4
%toy=[-1:.01:1];
if ro==1200
toy=[-1:.01:1];
else
toy=[-10:.1:10];
end
if length(q)>length(q_nl)
q=q(1:length(q_nl));
% timecell=timecell(1:length(q_nl));
end
if length(q)<length(q_nl)
q_nl=q_nl(1:length(q));
% timecell_nl=timecell_nl(1:length(q));
end
if ro==1200
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:1:300],w,toy);
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:1:300],w,toy);
else
freq3=barplot2_ft(q_nl,create_timecell(ro,length(q_nl)),[100:2:300],w,toy); %Memory reasons
freq4=barplot2_ft(q,create_timecell(ro,length(q)),[100:2:300],w,toy);
end
%%
% % % % % % % % % % cfg=[];
% % % % % % % % % % cfg.baseline=[-1 -0.5];
% % % % % % % % % % %cfg.baseline='yes';
% % % % % % % % % % cfg.baselinetype='db';
% % % % % % % % % % freq30=ft_freqbaseline(cfg,freq3);
% % % % % % % % % % freq40=ft_freqbaseline(cfg,freq4);
%%
% Calculate zlim
cfg = [];
cfg.channel = freq3.label{w};
[ zmin1, zmax1] = ft_getminmax(cfg, freq3);
[zmin2, zmax2] = ft_getminmax(cfg, freq4);
zlim=[min([zmin1 zmin2]) max([zmax1 zmax2])];
% zlim=[-max(abs(zlim)) max(abs(zlim))];
%%
cfg = [];
cfg.zlim=zlim;
cfg.channel = freq3.label{w};
cfg.colormap=colormap(jet(256));
%%
h(7)=subplot(3,4,7)
ft_singleplotTFR(cfg, freq3);
% freq3=barplot2_ft(q_nl,timecell_nl,[100:1:300],w);
g=title('High Gamma No Learning');
g.FontSize=12;
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
%
h(8)=subplot(3,4,8);
% freq4=barplot2_ft(q,timecell,[100:1:300],w)
%freq=justtesting(q,timecell,[100:1:300],w,0.5)
%title('High Gamma RIPPLE')
ft_singleplotTFR(cfg, freq4);
g=title(strcat('High Gamma',{' '},labelconditions{iii}));
g.FontSize=12;
%title(strcat('High Gamma',{' '},labelconditions{iii}))
%xo
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%%
if ro==1200
[stats1]=stats_between_trials(freq3,freq4,label1,w);
else
[stats1]=stats_between_trials10(freq3,freq4,label1,w);
end
%% %
h(10)=subplot(3,4,12);
cfg = [];
cfg.channel = label1{2*w-1};
cfg.parameter = 'stat';
cfg.maskparameter = 'mask';
cfg.zlim = 'maxabs';
cfg.colorbar = 'yes';
cfg.colormap=colormap(jet(256));
%grid minor
ft_singleplotTFR(cfg, stats1);
%title('Ripple vs No Ripple')
g=title(strcat(labelconditions{iii},' vs No Learning'));
g.FontSize=12;
%title(strcat(labelconditions{iii},' vs No Learning'))
xlabel('Time (s)')
%ylabel('uV')
ylabel('Frequency (Hz)')
%% EXTRA STATISTICS
% [stats1]=stats_between_trials(freq30,freq40,label1,w);
% % %
% subplot(3,4,11)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
%title(strcat(labelconditions{iii},' vs No Learning'))
%%
% [stats1]=stats_between_trials(freq10,freq20,label1,w);
% % %
% subplot(3,4,9)
% cfg = [];
% cfg.channel = label1{2*w-1};
% cfg.parameter = 'stat';
% cfg.maskparameter = 'mask';
% cfg.zlim = 'maxabs';
% cfg.colorbar = 'yes';
% cfg.colormap=colormap(jet(256));
% grid minor
% ft_singleplotTFR(cfg, stats1);
% %title('Ripple vs No Ripple')
% title(strcat(labelconditions{iii-3},' vs No Learning (Baseline)'))
% %title(strcat(labelconditions{iii},' vs No Learning'))
%%
% %% Baseline parameters
% mtit('No Learning:','fontsize',14,'color',[1 0 0],'position',[.1 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM2(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.1 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.1 0.2 ])
%
%
% mtit(strcat('Rip/sec:',num2str(RipFreq3(level))),'fontsize',14,'color',[1 0 0],'position',[.1 0.05 ])
%
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep2)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.1 0.005 ])
%
% %% Condition
% mtit(labelconditions{iii-3},'fontsize',14,'color',[1 0 0],'position',[.65 0.25 ])
%
% mtit(strcat('Events:',num2str(ripple(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.10 ])
% labelthr=strcat('Thr:',num2str(round(CHTM(level+1))));
% mtit(strcat(labelthr),'fontsize',14,'color',[1 0 0],'position',[.65 0.15 ])
%
% mtit(strcat(label1{2*w-1},' (',label2{1},')'),'fontsize',14,'color',[1 0 0],'position',[.65 0.2 ])
%
% mtit(strcat('Rip/sec:',num2str(RipFreq2(level))),'fontsize',14,'color',[1 0 0],'position',[.65 0.05 ])
%
% mtit(cell2mat(strcat({'Sleep:'},{num2str(timeasleep)},{' '},{'min'})),'fontsize',14,'color',[1 0 0],'position',[.65 0.005 ])
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
no_ripples.m
|
.m
|
CorticoHippocampal-master/Ideas_testing/no_ripples/no_ripples.m
| 2,338 |
utf_8
|
53b7298d606de347b9569189461701c4
|
%Vector with times
% for k=1:length(ti)-1
% caco=ti(1,k);
%
% if max(caco>S{1})&& (caco<E{1});
% end
% end
function [chec,chec2,checQ]=no_ripples(ti,S,E,ro,signal_array,signal_array2,signal_arrayQ)
% Find times with no ripples
caco=ti;
cao=signal_array;
cao2=signal_array2;
caoQ=signal_arrayQ;
for L=1:length(S)
% caco=caco (find( not(caco>=S{1}(L) & caco<= E{1}(L) )));
% caco=caco (find( not(caco>=S(L) & caco<= E(L) )));
% cao=cao(find( not(caco>=S(L) & caco<= E(L) )),:);
% cao2=cao2(find( not(caco>=S(L) & caco<= E(L) )),:);
% caoQ=caoQ(find( not(caco>=S(L) & caco<= E(L) )),:);
caco=caco (( not(caco>=S(L) & caco<= E(L) )));
cao=cao(( not(caco>=S(L) & caco<= E(L) )),:);
cao2=cao2(( not(caco>=S(L) & caco<= E(L) )),:);
caoQ=caoQ(( not(caco>=S(L) & caco<= E(L) )),:);
disp(strcat('Waiting:',num2str(round(L*100/length(S))),'%'))
end
%caco contains the concatenation all times when there are no ripples.
%
% caco=caco*(1000); %Multiply by sampling freq.
k=sum(diff(caco)>0.0011); %Number of discontinuities.
% no_rip=cell(k+1,1);
%Find samples where discontinuities occur.
pks=find(diff(caco)>0.0011);
if sum(pks)==0
%chec=0;
chec=cell.empty;
chec2=cell.empty;
checQ=cell.empty;
return;
else
for i=1:k+1
if i==1
%no_rip{1}= caco(1:pks(1))*1000; %MUltiply by 1000 to convert seconds to samples.
NR{1,1}=cao(1:pks(1),:);
NR2{1,1}=cao2(1:pks(1),:);
NRQ{1,1}=caoQ(1:pks(1),:);
elseif i==k+1
% no_rip{i}= caco((pks(i-1)+1):(end))*1000;
NR{i,1}=cao((pks(i-1)+1):(end),:);
NR2{i,1}=cao2((pks(i-1)+1):(end),:);
NRQ{i,1}=caoQ((pks(i-1)+1):(end),:);
else
% no_rip{i}= caco((pks(i-1)+1):(pks(i)))*1000;
NR{i,1}=cao((pks(i-1)+1):(pks(i)),:);
NR2{i,1}=cao2((pks(i-1)+1):(pks(i)),:);
NRQ{i,1}=caoQ((pks(i-1)+1):(pks(i)),:);
end
end
%aff=cellfun('length',no_rip);
aff=cellfun('length',NR);
chec= NR(find(aff>=ro*2+1));
chec2= NR2(find(aff>=ro*2+1));
checQ= NRQ(find(aff>=ro*2+1));
% A=cellfun('length',chec)./(2*ro+1);
% A=floor(A);
%
% %Standardize all windows to have same lenght
for index=1:length(chec)
dumm=chec{index};
chec{index}=dumm(1:ro*2+1,:).'; %time
dumm2=chec2{index};
chec2{index}=dumm2(1:ro*2+1,:).'; %time
dummQ=checQ{index};
checQ{index}=dummQ(1:ro*2+1,:).'; %time
end
end
end
%
|
github
|
Aleman-Z/CorticoHippocampal-master
|
ps_rip2.m
|
.m
|
CorticoHippocampal-master/Ideas_testing/scatter_plots/ps_rip2.m
| 358 |
utf_8
|
fbbeb09aa26b51f4c4ac122f01e0d83c
|
function [vecpow,vecpow2]=ps_rip2(p,w)
[ran]=rip_select(p);
p=p(ran);
for j=1:length(p)
%Hippocampus
F = fft(p{j}(1,:));
pow = F.*conj(F);
vecpow(1,j)=sum(pow);
%Other brain area
F2 = fft(p{j}(w,:)); % w is either 2 or 3
pow2 = F2.*conj(F2);
vecpow2(1,j)=sum(pow2);
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
ps_rip.m
|
.m
|
CorticoHippocampal-master/Ideas_testing/scatter_plots/ps_rip.m
| 180 |
utf_8
|
3a4098a567980faa53c1efe1aa24b010
|
function [vecpow]=ps_rip(p,w)
[ran]=rip_select(p);
p=p(ran);
for j=1:length(p)
F = fft(p{j}(w,:));
pow = F.*conj(F);
vecpow(1,j)=sum(pow);
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
getsignal.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/getsignal.m
| 227 |
utf_8
|
b45d7863f88d22dd5f1b6c0b2d047669
|
function [sig]=getsignal(Sx,Ex,ti,V,k)
if ~isempty(Sx{k})
for j=1:length(Sx{k})
[~,ts]=min(abs(ti{k}-Sx{k}(j)));
[~,tend]=min(abs(ti{k}-Ex{k}(j)));
sig{j}=V{k}(ts:tend);
end
else
sig=[];
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
granger_plot.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/granger_plot.m
| 1,734 |
utf_8
|
10330b848dff4f95d6fef765835898fe
|
function granger_plot(g,g_f,labelconditions,freqrange)
%Plots granger values across frequencies
allscreen()
myColorMap=StandardColors;
F= [1 2; 1 3; 2 3] ;
%Labels
lab=cell(6,1);
lab{2}='PFC -> PAR';
lab{1}='PAR -> PFC';
lab{4}='HPC -> PAR';
lab{3}='PAR -> HPC';
lab{6}='HPC -> PFC';
lab{5}='PFC -> HPC';
%
for j=1:3
f=F(j,:);
mmax1=max([max(squeeze(g{1}(f(1),f(2),:))) max(squeeze(g{2}(f(1),f(2),:))) ...
max(squeeze(g{3}(f(1),f(2),:))) max(squeeze(g{4}(f(1),f(2),:)))]);
mmax2=max([max(squeeze(g{1}(f(2),f(1),:))) max(squeeze(g{2}(f(2),f(1),:))) ...
max(squeeze(g{3}(f(2),f(1),:))) max(squeeze(g{4}(f(2),f(1),:)))]);
mmax=max([mmax1 mmax2]);
subplot(3,2,2*j-1)
plot(g_f, squeeze(g{1}(f(1),f(2),:)),'LineWidth',2,'Color',myColorMap(1,:))
hold on
plot(g_f, squeeze(g{2}(f(1),f(2),:)),'LineWidth',2,'Color',myColorMap(2,:))
plot(g_f, squeeze(g{3}(f(1),f(2),:)),'LineWidth',2,'Color',myColorMap(3,:))
plot(g_f, squeeze(g{4}(f(1),f(2),:)),'LineWidth',2,'Color',myColorMap(4,:))
xlim(freqrange)
xlabel('Frequency (Hz)')
ylabel('G-causality')
title(lab{2*j-1})
subplot(3,2,2*j)
plot(g_f, squeeze(g{1}(f(2),f(1),:)),'LineWidth',2,'Color',myColorMap(1,:))
hold on
plot(g_f, squeeze(g{2}(f(2),f(1),:)),'LineWidth',2,'Color',myColorMap(2,:))
plot(g_f, squeeze(g{3}(f(2),f(1),:)),'LineWidth',2,'Color',myColorMap(3,:))
plot(g_f, squeeze(g{4}(f(2),f(1),:)),'LineWidth',2,'Color',myColorMap(4,:))
xlim(freqrange)
xlabel('Frequency (Hz)')
ylabel('G-causality')
if j==1
legend(labelconditions,'Location','best') %Might have to change to default.
end
title(lab{2*j})
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
gui_finddeltawavesZugaro.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/gui_finddeltawavesZugaro.m
| 3,478 |
utf_8
|
9fde62e74dbf0e1c1841aec353799d98
|
% gui_finddeltawavesZugaro.m
function [deltaWave_count,deltaFreq,delta_duration,Mx,timeasleep,sig,Ex,Sx, DeltaWaves, ti_cont,duration_epoch_cumsum]=gui_finddeltawavesZugaro(CORTEX,states,xx,multiplets,fn, thresholds)
%Band pass filter design:
Wn1=[0.3/(fn/2) 300/(fn/2)];
[b2,a2] = butter(3,Wn1); %0.3 to 300Hz
%Convert signal to 1 sec epochs.
e_t=1;
e_samples=e_t*(fn); %fs=1kHz
ch=length(CORTEX);
nc=floor(ch/e_samples); %Number of epochsw
NC=[];
for kk=1:nc
NC(:,kk)= CORTEX(1+e_samples*(kk-1):e_samples*kk);
end
vec_bin=states;
%Convert to 1 if NREM.
vec_bin(vec_bin~=3)=0;
vec_bin(vec_bin==3)=1;
%Cluster one values:
v2=ConsecutiveOnes(vec_bin);
v_index=find(v2~=0);
v_values=v2(v2~=0);
for epoch_count=1:length(v_index)
v{epoch_count,1}=reshape(NC(:, v_index(epoch_count):v_index(epoch_count)+(v_values(1,epoch_count)-1)), [], 1);
end
V=cellfun(@(equis) filtfilt(b2,a2,equis), v ,'UniformOutput',false); %0.3 to 300Hz
Wn1=[1/(fn/2) 6/(fn/2)]; % Cutoff=1-4 Hz % maingret and lisa both prefer 4 Hz.
[b1,a1] = butter(3,Wn1,'bandpass'); %Filter coefficients
Mono=cellfun(@(equis) filtfilt(b1,a1,equis), V ,'UniformOutput',false); %Regular 9-20Hz bandpassed for sig variable.
Concat_mono=vertcat(Mono{:});
%Total amount of NREM time:
timeasleep=sum(cellfun('length',V))*(1/fn)/60; % In minutes
ti=cellfun(@(equis) reshape(linspace(0, length(equis)-1,length(equis))*(1/fn),[],1) ,Mono,'UniformOutput',false);
%% Finding number of spindles in the dataset
ti_cont=(1:length(Concat_mono))./1000;
Concat_input = [ti_cont' Concat_mono];
DeltaWaves=FindDeltaWaves(Concat_input, 'thresholds', thresholds );
%finding number of Delta waves per per epoch
%duration of each epoch of non-rem sleep
duration_epoch=cellfun(@length, ti)/1000;
duration_epoch_cumsum=cumsum(duration_epoch);
for f=1:length(duration_epoch_cumsum)
if(f==1)
vec=find(DeltaWaves(:,1)>=0 & DeltaWaves(:,3)<=duration_epoch_cumsum(f));
elseif(f>1)
vec=find(DeltaWaves(:,1)>=duration_epoch_cumsum(f-1) & DeltaWaves(:,3)<=duration_epoch_cumsum(f));
end
delta_per_epoch(f)=length(vec);
% assigning each spindle an epoch number
DeltaWaves(vec,7)=f;
%assigning each spindle a local start and stop time wrt the epoch
if(f==1)
DeltaWaves(vec, 8:10)=DeltaWaves(vec,1:3);
elseif(f>1)
DeltaWaves(vec, 8:10)=DeltaWaves(vec,1:3)-duration_epoch_cumsum(f-1);
end
Sx(f)={(DeltaWaves(vec,8))'};
Ex(f)={(DeltaWaves(vec,10))'};
Mx(f)={(DeltaWaves(vec,9))'};
% Sx(f,1)={spindles(vec,6)};
% Ex(f,1)={spindles(vec,8)};
% Mx(f,1)= {spindles(vec,7)};
end
%%
% %% Find largest epoch.
max_length=cellfun(@length,v);
nrem_epoch=find(max_length==max(max_length)==1);
nrem_epoch=nrem_epoch(1);
% append all spindles together
for l=1:length(Sx)
sig{l}=getsignal(Sx,Ex,ti,Mono,l);
end
% Find # of spindles, spindle frequency, median spindle duration
[deltaWave_count, deltaFreq,delta_duration]=hfo_count_freq_duration(Sx,Ex,timeasleep);
%deltaFreq=deltaFreq*60; %Spindles per minute.
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
co_hfo.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/co_hfo.m
| 367 |
utf_8
|
abe24b3c6e164e3ccc3b4ec1dbe931d4
|
function [co_vec1,co_vec2]=co_hfo(a,N)%HPC,Cortex
co_vec1=[];%HPC
co_vec2=[];%Cortex
for index_hfo=1:length(N);
n=N(index_hfo);
[val,idx]=min(abs(a-n));
minVal=a(idx);
%Diference
df=abs(minVal-n);
%Coocur if closer to 50ms
if df<=0.050
co_vec1=[co_vec1 minVal];
co_vec2=[co_vec2 n];
end
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
getsignal_spec.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/getsignal_spec.m
| 840 |
utf_8
|
42cbb39c1c33c6a6b779ac15b2f611a4
|
function [sig,p,q,cont,sig_pq]=getsignal_spec(Sx,Ex,ti,Mono,k,Mx,V,Mono2,V2,Mono3,V3,ro)
cont=0;
if ~isempty(Sx{k})
for j=1:length(Sx{k})
ts=find(ti{k}==Sx{k}(j));
tend=find(ti{k}==Ex{k}(j));
sig{j}=Mono{k}(ts:tend);
if nargin>5
%Ripple-centered window.
tm=find(ti{k}==Mx{k}(j));
if tm+ro<=length(ti{k}) && tm-ro>=1
p{j}=[V{k}(tm-ro:tm+ro).';V2{k}(tm-ro:tm+ro).';V3{k}(tm-ro:tm+ro).'];
q{j}=[Mono{k}(tm-ro:tm+ro).';Mono2{k}(tm-ro:tm+ro).';Mono3{k}(tm-ro:tm+ro).'];
sig_pq{j}=Mono{k}(ts:tend);
else
p{j}=[];
q{j}=[];
sig_pq{j}=[];
cont=cont+1;
end
else
p{j}=[];
q{j}=[];
sig_pq{j}=[];
end
end
else
sig=[];
p=[];
q=[];
sig_pq=[];
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
getgranger.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/getgranger.m
| 682 |
utf_8
|
a18e5e27efdb45f1d2401a6ae8194b6b
|
function [granger,granger1,granger_cond,granger_cond_multi]=getgranger(q,timecell,label,ro,ord,freqrange,fn)
%Computes multiple types of granger causality.
%Mainly parametric and Non parametric.
data1.trial=q;
data1.time= timecell;
data1.fsample=fn;
data1.label=cell(3,1);
data1.label{1}='PAR';
data1.label{2}='PFC';
data1.label{3}='HPC';
%Parametric model
[granger1]=createauto(data1,ord,'yes');
%Non parametric
[granger]=createauto_np(data1,freqrange,[]);
%Non parametric Conditional
[granger_cond]=createauto_np(data1,freqrange,'yes');
%Parametric with multivariate setting set on (testing purposes)
[granger_cond_multi]=createauto_cond_multivariate(data1,ord);
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
create_timecell.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/create_timecell.m
| 193 |
utf_8
|
7503e1d7a1cfc26c6b302762f594593b
|
function [C]=create_timecell(ro,leng,fn)
%create_timecell(ro,leng)
%iNPUTS:
%ro:1200
%leng:length(p)
%fn=1000;
vec=-ro/fn:1/fn:ro/fn;
C = cell(1, leng);
C(:) = {vec};
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
stats_high.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/stats_high.m
| 3,495 |
utf_8
|
2daba78b7181f2ba7e0924361fbc822c
|
function [zmap]=stats_high(freq1,freq2,w)
ntrials=size(freq1.powspctrm,1);
%Requires converting NaNs values into zeros.
no1=freq1.powspctrm;
no2=freq2.powspctrm;
no1(isnan(no1))=0;
no2(isnan(no2))=0;
%%
freq1.powspctrm=no1;
freq2.powspctrm=no2;
%% statistics via permutation testing
% p-value
pval = 0.05;
% convert p-value to Z value
zval = abs(norminv(pval));
% number of permutations
n_permutes = 500;
% initialize null hypothesis maps
permmaps = zeros(n_permutes,length(freq1.freq),length(freq1.time));
% for convenience, tf power maps are concatenated
% in this matrix, trials 1:ntrials are from channel "1"
% and trials ntrials+1:end are from channel "2"
tf3d = cat(3,reshape(squeeze(freq1.powspctrm(:,w,:,:)),[length(freq1.freq) length(freq1.time)...
ntrials ]),reshape(squeeze(freq2.powspctrm(:,w,:,:)),[length(freq1.freq) length(freq1.time)...
ntrials ]));
%concatenated in time.
% freq, time, trials
% generate maps under the null hypothesis
for permi = 1:n_permutes
permi
% randomize trials, which also randomly assigns trials to channels
randorder = randperm(size(tf3d,3));
temp_tf3d = tf3d(:,:,randorder);
% compute the "difference" map
% what is the difference under the null hypothesis?
permmaps(permi,:,:) = squeeze( mean(temp_tf3d(:,:,1:ntrials),3) - mean(temp_tf3d(:,:,ntrials+1:end),3) );
end
%% show non-corrected thresholded maps
diffmap = squeeze(mean(freq2.powspctrm(:,w,:,:),1 )) - squeeze(mean(freq1.powspctrm(:,w,:,:),1 ));
% compute mean and standard deviation maps
mean_h0 = squeeze(mean(permmaps));
std_h0 = squeeze(std(permmaps));
% now threshold real data...
% first Z-score
zmap = (diffmap-mean_h0) ./ std_h0;
% threshold image at p-value, by setting subthreshold values to 0
zmap(abs(zmap)<zval) = 0;
%%
% initialize matrices for cluster-based correction
max_cluster_sizes = zeros(1,n_permutes);
% ... and for maximum-pixel based correction
max_val = zeros(n_permutes,2); % "2" for min/max
% loop through permutations
for permi = 1:n_permutes
% take each permutation map, and transform to Z
threshimg = squeeze(permmaps(permi,:,:));
threshimg = (threshimg-mean_h0)./std_h0;
% threshold image at p-value
threshimg(abs(threshimg)<zval) = 0;
% find clusters (need image processing toolbox for this!)
islands = bwconncomp(threshimg);
if numel(islands.PixelIdxList)>0
% count sizes of clusters
tempclustsizes = cellfun(@length,islands.PixelIdxList);
% store size of biggest cluster
max_cluster_sizes(permi) = max(tempclustsizes);
end
% get extreme values (smallest and largest)
temp = sort( reshape(permmaps(permi,:,:),1,[] ));
max_val(permi,:) = [ min(temp) max(temp) ];
end
%%
cluster_thresh = prctile(max_cluster_sizes,100-(100*pval));
% now find clusters in the real thresholded zmap
% if they are "too small" set them to zero
islands = bwconncomp(zmap);
for i=1:islands.NumObjects
% if real clusters are too small, remove them by setting to zero!
if numel(islands.PixelIdxList{i}==i)<cluster_thresh
zmap(islands.PixelIdxList{i})=0;
end
end
%% now with max-pixel-based thresholding
% find the threshold for lower and upper values
thresh_lo = prctile(max_val(:,1),100-100*pval); % what is the
thresh_hi = prctile(max_val(:,2),100-100*pval); % true p-value?
% threshold real data
zmap = diffmap;
zmap(zmap>thresh_lo & zmap<thresh_hi) = 0;
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
single_hfos_mx.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/single_hfos_mx.m
| 188 |
utf_8
|
fe47b76b8cde0084e8cd42f91e414cbe
|
function [ach,ach2]=single_hfos_mx(cohfos1,ach,ach2)
for k=1:length(cohfos1)
ach2(find(ach==cohfos1(k)))=[];
ach(find(ach==cohfos1(k)))=[];
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
co_hfo_delta_spindle.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/co_hfo_delta_spindle.m
| 410 |
utf_8
|
fc7c576e1535dc2170ad872fd46f11eb
|
function [co_vec1,co_vec2]=co_hfo_delta_spindle(a,N)%delta,spindle
co_vec1=[];%delta
co_vec2=[];%spindle
for index_hfo=1:length(N);
n=N(index_hfo);
[val,idx]=min(abs(a-n));
minVal=a(idx);
%Diference
df=(minVal-n);
%Coocur if within -0.5 to 1 sec difference
if df<=1 & df>=-0.50
co_vec1=[co_vec1 minVal];
co_vec2=[co_vec2 n];
end
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
small_window.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/small_window.m
| 824 |
utf_8
|
b3d2f6add0bf4a29768d38b84f3a15cf
|
function [mdam,mdam2,mdam3,mdam4]=small_window(freq2,w,win_size)
%Compute mean power value of window for different frequency bands
dam=((squeeze(mean(squeeze(freq2.powspctrm(:,w,:,1+win_size:end-win_size)),1)))); %Average all events.
mdam=mean(dam(:)); %Mean value
freqs=freq2.freq;
%100 to 150 Hz
n1=sum(freqs<=150);
dam=((squeeze(mean(squeeze(freq2.powspctrm(:,w,1:n1,1+win_size:end-win_size)),1)))); %Average all events.
mdam2=mean(dam(:)); %Mean value
%151 to 200 Hz
n2=sum(freqs<=200);
dam=((squeeze(mean(squeeze(freq2.powspctrm(:,w,n1+1:n2,1+win_size:end-win_size)),1)))); %Average all events.
mdam3=mean(dam(:)); %Mean value
%201 to 250 Hz
n3=sum(freqs<=250);
dam=((squeeze(mean(squeeze(freq2.powspctrm(:,w,n2+1:n3,1+win_size:end-win_size)),1)))); %Average all events.
mdam4=mean(dam(:)); %Mean value
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
isivector.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/FMAtoolbox_functions/isivector.m
| 2,130 |
iso_8859_13
|
fb6d2426defdb32c4121d3ed9e0d6ef8
|
%isivector - Test if parameter is a vector of integers satisfying an optional list of tests.
%
% USAGE
%
% test = isivector(x,test1,test2,...)
%
% x parameter to test
% test1... optional list of additional tests (see examples below)
%
% EXAMPLES
%
% % Test if x is a vector of doubles
% isivector(x)
%
% % Test if x is a vector of strictly positive doubles
% isivector(x,'>0')
%
% % Test if x is a vector of doubles included in [2,3]
% isivector(x,'>=2','<=3')
%
% % Special test: test if x is a vector of doubles of length 3
% isivector(x,'#3')
%
% % Special test: test if x is a vector of strictly ordered doubles
% isivector(x,'>')
%
% NOTE
%
% The tests ignore NaNs, e.g. isivector([500 nan]), isivector([1 nan 3],'>0') and
% isivector([nan -7],'<=0') all return 1.
%
% SEE ALSO
%
% See also isdmatrix, isdvector, isdscalar, isimatrix, isiscalar, isastring,
% islscalar, islvector, islmatrix.
%
% Copyright (C) 2010 by Michaël Zugaro
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.
function test = isivector(x,varargin)
% Check number of parameters
if nargin < 1,
error('Incorrect number of parameters (type ''help <a href="matlab:help isivector">isivector</a>'' for details).');
end
% Test: double, vector
test = isa(x,'double') & isvector(x);
% Ignore NaNs
x = x(~isnan(x));
% Test: integers?
test = test & all(round(x)==x);
% Optional tests
for i = 1:length(varargin),
try
if varargin{i}(1) == '#',
if length(x) ~= str2num(varargin{i}(2:end)), test = false; return; end
elseif isastring(varargin{i},'>','>=','<','<='),
dx = diff(x);
if ~eval(['all(0' varargin{i} 'dx);']), test = false; return; end
else
if ~eval(['all(x' varargin{i} ');']), test = false; return; end
end
catch err
error(['Incorrect test ''' varargin{i} ''' (type ''help <a href="matlab:help isivector">isivector</a>'' for details).']);
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
isiscalar.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/FMAtoolbox_functions/isiscalar.m
| 1,624 |
iso_8859_13
|
cfd172b108f357be076ab239961c52c9
|
%isiscalar - Test if parameter is a scalar (integer) satisfying an optional list of tests.
%
% USAGE
%
% test = isiscalar(x,test1,test2,...)
%
% x parameter to test
% test1... optional list of additional tests
%
% EXAMPLES
%
% % Test if x is a scalar (double)
% isiscalar(x)
%
% % Test if x is a strictly positive scalar (double)
% isiscalar(x,'>0')
%
% % Test if x is a scalar (double) included in [2,3]
% isiscalar(x,'>=2','<=3')
%
% NOTE
%
% The tests ignore NaN, e.g. isiscalar(nan), isiscalar(nan,'>0') and isiscalar(nan,'<=0')
% all return 1.
%
% SEE ALSO
%
% See also isdmatrix, isdvector, isdscalar, isimatrix, isivector, isastring,
% islscalar, islvector, islmatrix.
%
% Copyright (C) 2010 by Michaël Zugaro
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.
function test = isiscalar(x,varargin)
% Check number of parameters
if nargin < 1,
error('Incorrect number of parameters (type ''help <a href="matlab:help isiscalar">isiscalar</a>'' for details).');
end
% Test: double, scalar
test = isa(x,'double') & isscalar(x);
if ~test, return; end
% Test: integers?
test = test & round(x)==x;
% Optional tests
for i = 1:length(varargin),
try
if ~eval(['x' varargin{i} ';']), test = false; return; end
catch err
error(['Incorrect test ''' varargin{i} ''' (type ''help <a href="matlab:help isiscalar">isiscalar</a>'' for details).']);
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
isdvector.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/FMAtoolbox_functions/isdvector.m
| 2,083 |
iso_8859_13
|
b6c923bf5b7013b5ccdf39ab51441db1
|
%isdvector - Test if parameter is a vector of doubles satisfying an optional list of tests.
%
% USAGE
%
% test = isdvector(x,test1,test2,...)
%
% x parameter to test
% test1... optional list of additional tests (see examples below)
%
% EXAMPLES
%
% % Test if x is a vector of doubles
% isdvector(x)
%
% % Test if x is a vector of strictly positive doubles
% isdvector(x,'>0')
%
% % Test if x is a vector of doubles included in [2,3]
% isdvector(x,'>=2','<=3')
%
% % Special test: test if x is a vector of doubles of length 3
% isdvector(x,'#3')
%
% % Special test: test if x is a vector of strictly ordered doubles
% isdvector(x,'>')
%
% NOTE
%
% The tests ignore NaNs, e.g. isdvector([5e-3 nan]), isdvector([1.7 nan 3],'>0') and
% isdvector([nan -7.4],'<=0') all return 1.
%
% SEE ALSO
%
% See also isdmatrix, isdscalar, isimatrix, isivector, isiscalar, isastring,
% islscalar, islvector, islmatrix.
%
% Copyright (C) 2010 by Michaël Zugaro
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.
function test = isdvector(x,varargin)
% Check number of parameters
if nargin < 1,
error('Incorrect number of parameters (type ''help <a href="matlab:help isdvector">isdvector</a>'' for details).');
end
% Test: double, vector
test = isa(x,'double') & isvector(x);
% Ignore NaNs
x = x(~isnan(x));
% Optional tests
for i = 1:length(varargin),
try
if varargin{i}(1) == '#',
if length(x) ~= str2num(varargin{i}(2:end)), test = false; return; end
elseif isastring(varargin{i},'>','>=','<','<='),
dx = diff(x);
if ~eval(['all(0' varargin{i} 'dx);']), test = false; return; end
else
if ~eval(['all(x' varargin{i} ');']), test = false; return; end
end
catch err
error(['Incorrect test ''' varargin{i} ''' (type ''help <a href="matlab:help isdvector">isdvector</a>'' for details).']);
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
isdscalar.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/FMAtoolbox_functions/isdscalar.m
| 1,576 |
iso_8859_13
|
b57157fcad5380ccefe965b9d5f2cba0
|
%isdscalar - Test if parameter is a scalar (double) satisfying an optional list of tests.
%
% USAGE
%
% test = isdscalar(x,test1,test2,...)
%
% x parameter to test
% test1... optional list of additional tests
%
% EXAMPLES
%
% % Test if x is a scalar (double)
% isdscalar(x)
%
% % Test if x is a strictly positive scalar (double)
% isdscalar(x,'>0')
%
% % Test if x is a scalar (double) included in [2,3]
% isdscalar(x,'>=2','<=3')
%
% NOTE
%
% The tests ignore NaN, e.g. isdscalar(nan), isdscalar(nan,'>0') and isdscalar(nan,'<=0')
% all return 1.
%
% SEE ALSO
%
% See also isdmatrix, isdvector, isimatrix, isivector, isiscalar, isastring,
% islscalar, islvector, islmatrix.
%
% Copyright (C) 2010 by Michaël Zugaro
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.
function test = isdscalar(x,varargin)
% Check number of parameters
if nargin < 1,
error('Incorrect number of parameters (type ''help <a href="matlab:help isdscalar">isdscalar</a>'' for details).');
end
% Test: double, scalar
test = isa(x,'double') & isscalar(x);
if ~test, return; end
% Optional tests
for i = 1:length(varargin),
try
if ~eval(['x' varargin{i} ';']), test = false; return; end
catch err
error(['Incorrect test ''' varargin{i} ''' (type ''help <a href="matlab:help isdscalar">isdscalar</a>'' for details).']);
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
isastring.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/FMAtoolbox_functions/isastring.m
| 1,042 |
iso_8859_13
|
ccf515e97f4f9f13a98dec5005717419
|
%isastring - Test if parameter is an (admissible) character string.
%
% USAGE
%
% test = isastring(x,string1,string2,...)
%
% x item to test
% string1... optional list of admissible strings
%
% SEE ALSO
%
% See also isdmatrix, isdvector, isdscalar, isimatrix, isivector, isiscalar.
%
% Copyright (C) 2004-2016 by Michaël Zugaro
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.
function test = isastring(x,varargin)
% Check number of parameters
if nargin < 1,
error('Incorrect number of parameters (type ''help <a href="matlab:help isastring">isastring</a>'' for details).');
end
test = true;
if ~isvector(x),
test = false;
return;
end
if ~ischar(x),
test = false;
return;
end
if isempty(varargin), return; end
for i = 1:length(varargin),
if strcmp(x,varargin{i}), return; end
end
test = false;
|
github
|
Aleman-Z/CorticoHippocampal-master
|
isdmatrix.m
|
.m
|
CorticoHippocampal-master/Fast_and_slow_hfos/subfunctions/FMAtoolbox_functions/isdmatrix.m
| 1,958 |
iso_8859_13
|
c6cf39b50b44f697c7a9f642f6a7a2ab
|
%isdmatrix - Test if parameter is a matrix of doubles (>= 2 columns).
%
% USAGE
%
% test = isdmatrix(x,test1,test2,...)
%
% x parameter to test
% test1... optional list of additional tests
%
% EXAMPLES
%
% % Test if x is a matrix of doubles
% isdmatrix(x)
%
% % Test if x is a matrix of strictly positive doubles
% isdmatrix(x,'>0')
%
% % Special test: test if x is a 3-line matrix of doubles
% isdmatrix(x,'#3')
%
% % Special test: test if x is a 2-column matrix of doubles
% isdmatrix(x,'@2')
%
% NOTE
%
% The tests ignore NaNs, e.g. isdmatrix([5e-3 nan;4 79]), isdmatrix([1.7 nan 3],'>0') and
% isdmatrix([nan -7.4;nan nan;-2.3 -5],'<=0') all return 1.
%
% SEE ALSO
%
% See also isdvector, isdscalar, isimatrix, isivector, isiscalar, isastring,
% islscalar, islvector, islmatrix.
%
% Copyright (C) 2010-2015 by Michaël Zugaro
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.
function test = isdmatrix(x,varargin)
% Check number of parameters
if nargin < 1,
error('Incorrect number of parameters (type ''help <a href="matlab:help isdmatrix">isdmatrix</a>'' for details).');
end
% Test: doubles, two dimensions, two or more columns?
test = isa(x,'double') & length(size(x)) == 2 & size(x,2) >= 2;
% Optional tests
for i = 1:length(varargin),
try
if varargin{i}(1) == '#',
if size(x,1) ~= str2num(varargin{i}(2:end)), test = false; return; end
elseif varargin{i}(1) == '@',
if size(x,2) ~= str2num(varargin{i}(2:end)), test = false; return; end
elseif ~eval(['all(x(~isnan(x))' varargin{i} ');']), test = false; return; end
catch err
error(['Incorrect test ''' varargin{i} ''' (type ''help <a href="matlab:help isdmatrix">isdmatrix</a>'' for details).']);
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
granger_baseline_learning_stats.m
|
.m
|
CorticoHippocampal-master/Granger/granger_baseline_learning_stats.m
| 3,292 |
utf_8
|
3e0a4bb592280ada6757d4907aa46168
|
function granger_baseline_learning_stats(g,g_f,labelconditions,freqrange,GRGRNP,GRGRNP_base,AL)
allscreen()
F= [1 2; 1 3; 2 3] ;
lab=cell(6,1);
lab{1}='HPC -> PAR';
lab{2}='PAR -> HPC';
lab{3}='HPC -> PFC';
lab{4}='PFC -> HPC';
lab{5}='PAR -> PFC';
lab{6}='PFC -> PAR';
%
% k=1; %Condition 1.
for j=1:3
f=F(j,:);
mmax1=max([max(squeeze(g{1}(f(1),f(2),:))) max(squeeze(g{2}(f(1),f(2),:))) ...
max(squeeze(g{3}(f(1),f(2),:))) max(squeeze(g{4}(f(1),f(2),:)))]);
mmax2=max([max(squeeze(g{1}(f(2),f(1),:))) max(squeeze(g{2}(f(2),f(1),:))) ...
max(squeeze(g{3}(f(2),f(1),:))) max(squeeze(g{4}(f(2),f(1),:)))]);
mmax=max([mmax1 mmax2]);
%
NU1=[];
NU2=[];
for jj=1:length(GRGRNP);
nu1=GRGRNP{jj};
nu1=squeeze(nu1(f(1),f(2),:));
nu2=GRGRNP_base{jj};
nu2=squeeze(nu2(f(1),f(2),:));
NU1=[NU1 nu1];
NU2=[NU2 nu2];
end
for jj=1:size(NU1,1) % All frequencies.
%Wilcoxon rank sum test
[p,h,~] = ranksum(detrend(NU1(jj,:)),detrend(NU2(jj,:)));
P(jj)=p;
H(jj)=h;
%kruskalwallis
pp = kruskalwallis([detrend(NU1(jj,:)).' detrend(NU2(jj,:)).' ],[],'off');
PP(jj)=pp;
%kstest2
[h,p] = kstest2(detrend(NU1(jj,:)),detrend(NU2(jj,:)));
PPP(jj)=p;
[~,~,stats] = anova2([NU1(jj,:).' NU2(jj,:).' ],1,'off');
c = multcompare(stats,'Display','off');
PE(jj)=c(end);
end
subplot(3,2,2*j-1)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(1),f(2),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(1),f(2),:)),'LineWidth',2,'Color',[0.5 0.5 0.5])
hold on
%plot(g_f, squeeze(g{2}(f(1),f(2),:)),'LineWidth',2)
%plot(g_f, squeeze(g{3}(f(1),f(2),:)),'LineWidth',2)
plot(g_f, squeeze(g{4}(f(1),f(2),:)),'LineWidth',2,'Color',[0 0 0])
area(g_f,PP<AL)
alpha(0.2)
xlim(freqrange)
ylim([0 mmax])
%grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
title(lab{2*j-1})
% legend('Parametric: AR(10)','Non-P:Multitaper')
%if j==1
% legend(labelconditions)
%end
NU1=[];
NU2=[];
for jj=1:length(GRGRNP);
nu1=GRGRNP{jj};
nu1=squeeze(nu1(f(2),f(1),:));
nu2=GRGRNP_base{jj};
nu2=squeeze(nu2(f(2),f(1),:));
NU1=[NU1 nu1];
NU2=[NU2 nu2];
end
for jj=1:size(NU1,1) % All frequencies.
%Wilcoxon rank sum test
[p,h,~] = ranksum(detrend(NU1(jj,:)),detrend(NU2(jj,:)));
P(jj)=p;
H(jj)=h;
%kruskalwallis
pp = kruskalwallis([detrend(NU1(jj,:)).' detrend(NU2(jj,:)).' ],[],'off');
PP(jj)=pp;
%kstest2
[h,p] = kstest2(detrend(NU1(jj,:)),detrend(NU2(jj,:)));
PPP(jj)=p;
[~,~,stats] = anova2([NU1(jj,:).' NU2(jj,:).' ],1,'off');
c = multcompare(stats,'Display','off');
PE(jj)=c(end);
end
subplot(3,2,2*j)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(2),f(1),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(2),f(1),:)),'LineWidth',2,'Color',[0.5 0.5 0.5])
hold on
%plot(g_f, squeeze(g{2}(f(2),f(1),:)),'LineWidth',2)
%plot(g_f, squeeze(g{3}(f(2),f(1),:)),'LineWidth',2)
plot(g_f, squeeze(g{4}(f(2),f(1),:)),'LineWidth',2,'Color',[0 0 0])
area(g_f,PP<AL)
alpha(0.2)
xlim(freqrange)
%grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
%legend('Parametric: AR(10)','Non-P:Multitaper')
if j==1
labcon=[labelconditions(1);labelconditions(4)]
labcon=['Control';labelconditions(4)]
legend(labcon,'Location','best') %Might have to change to default.
end
title(lab{2*j})
ylim([0 mmax])
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
granger_paper3.m
|
.m
|
CorticoHippocampal-master/Granger/granger_paper3.m
| 1,159 |
utf_8
|
71aecb5716ee91350cb2c8b80e41c506
|
function granger_paper3(g,g_f,labelconditions,k)
%allscreen()
F= [1 2; 1 3; 2 3] ;
lab=cell(6,1);
lab{1}='HPC -> Parietal';
lab{2}='Parietal -> HPC';
lab{3}='HPC -> PFC';
lab{4}='PFC -> HPC';
lab{5}='Parietal -> PFC';
lab{6}='PFC -> Parietal';
%
% k=1; %Condition 1.
for j=1:3
f=F(j,:);
mmax1=[max(squeeze(g{k}(f(1),f(2),:)))];
mmax1=max(mmax1);
mmax2=[max(squeeze(g{k}(f(2),f(1),:)))];
mmax2=max(mmax2);
mmax=max([mmax1 mmax2]);
%
subplot(3,2,2*j-1)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(1),f(2),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{k}(f(1),f(2),:)))
xlim([0 300])
ylim([0 mmax])
grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
title(lab{2*j-1})
% legend('Parametric: AR(10)','Non-P:Multitaper')
legend(labelconditions{k})
subplot(3,2,2*j)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(2),f(1),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{k}(f(2),f(1),:)))
xlim([0 300])
grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
%legend('Parametric: AR(10)','Non-P:Multitaper')
legend(labelconditions{k})
title(lab{2*j})
ylim([0 mmax])
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
granger_paper4_stripes.m
|
.m
|
CorticoHippocampal-master/Granger/granger_paper4_stripes.m
| 2,019 |
utf_8
|
a14d4d43e63990e4590572ca77bab12e
|
function granger_paper4_stripes(g,g_f,labelconditions,freqrange,aver,Xaver)
allscreen()
F= [1 2; 1 3; 2 3] ;
lab=cell(6,1);
lab{1}='HPC -> Parietal';
lab{2}='Parietal -> HPC';
lab{3}='HPC -> PFC';
lab{4}='PFC -> HPC';
lab{5}='Parietal -> PFC';
lab{6}='PFC -> Parietal';
%
% k=1; %Condition 1.
for j=1:3
f=F(j,:);
mmax1=max([max(squeeze(g{1}(f(1),f(2),:))) max(squeeze(g{2}(f(1),f(2),:))) ...
max(squeeze(g{3}(f(1),f(2),:))) max(squeeze(g{4}(f(1),f(2),:)))]);
mmax2=max([max(squeeze(g{1}(f(2),f(1),:))) max(squeeze(g{2}(f(2),f(1),:))) ...
max(squeeze(g{3}(f(2),f(1),:))) max(squeeze(g{4}(f(2),f(1),:)))]);
mmax=max([mmax1 mmax2]);
%
subplot(3,2,2*j-1)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(1),f(2),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(1),f(2),:)),'LineWidth',2)
hold on
plot(g_f, squeeze(g{2}(f(1),f(2),:)),'LineWidth',2)
plot(g_f, squeeze(g{3}(f(1),f(2),:)),'LineWidth',2)
plot(g_f, squeeze(g{4}(f(1),f(2),:)),'LineWidth',2)
xlim(freqrange)
ylim([0 mmax])
grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
title(lab{2*j-1})
% Add stripes
hold on
rrc=area(aver(j,:),'FaceColor','none')
set(rrc, 'FaceColor', 'r')
alpha(0.2)
% legend('Parametric: AR(10)','Non-P:Multitaper')
%if j==1
% legend(labelconditions)
%end
subplot(3,2,2*j)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(2),f(1),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(2),f(1),:)),'LineWidth',2)
hold on
plot(g_f, squeeze(g{2}(f(2),f(1),:)),'LineWidth',2)
plot(g_f, squeeze(g{3}(f(2),f(1),:)),'LineWidth',2)
plot(g_f, squeeze(g{4}(f(2),f(1),:)),'LineWidth',2)
xlim(freqrange)
grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
% Add stripes
hold on
rrc=area(Xaver(j,:),'FaceColor','none')
set(rrc, 'FaceColor', 'r')
alpha(0.2)
%legend('Parametric: AR(10)','Non-P:Multitaper')
if j==1
legend(labelconditions,'Location','best') %Might have to change to default.
end
title(lab{2*j})
ylim([0 mmax])
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_granger.m
|
.m
|
CorticoHippocampal-master/Granger/plot_granger.m
| 2,162 |
utf_8
|
6ce16c82d18c3e31f12a3620b8d4719f
|
%% plot_spw
%
% Plot spectral pairwise quantities on a grid
%
% <matlab:open('plot_spw.m') code>
%
%% Syntax
%
% plot_spw(P,fs)
%
%% Arguments
%
% _input_
%
% P matrix of spectral pairwise quantities
% fs sample rate in Hz (default: normalised freq as per routine 'sfreqs')
% frange frequency range to plot: empty for all (default) else an ascending 2-vector
%
%% Description
%
% Plot pairwise spectral quantities in |P|, a 3-dim numerical matrix with
% first index representing target ("to"), second index source ("from")
% quantities and third index frequencies - typically spectral causalities (see
% e.g. <autocov_to_spwcgc.html |autocov_to_spwcgc|>).
%
%% See also
%
% <autocov_to_spwcgc.html |autocov_to_spwcgc|> |
% <mvgc_demo.html |mvgc_demo|> |
% <sfreqs.html |sfreqs|>
%
% (C) Lionel Barnett and Anil K. Seth, 2012. See file license.txt in
% installation directory for licensing terms.
%
%%
function plot_granger(P,fs,frange)
n = size(P,1);
assert(ndims(P) == 3 && size(P,2) == n,'must be a 3-dim matrix with the first two dims square');
h = size(P,3);
if nargin < 2, fs = []; end % default to normalised frequency as per 'sfreqs'
if nargin < 3, frange = []; end; % default to all
if ~isempty(frange)
assert(isvector(frange) && length(frange) == 2 && frange(1) < frange(2),'frequency range must be an ascending 2-vector of frequencies');
end
fres = h-1;
lam = sfreqs(fres,fs)';
if ~isempty(frange)
idx = lam >= frange(1) & lam <= frange(2);
lam = lam(idx);
P = P(:,:,idx,:);
end
xlims = [lam(1) lam(end)];
ylims = [min(P(:)) 1.1*max(P(:))];
if isempty(fs), xlab = 'normalised frequency'; else xlab = 'frequency (Hz)'; end
label=cell(4,1);
label{1,1}='Hippo';
label{2,1}='Parietal';
label{3,1}='PFC';
label{4,1}='Reference';
k = 0;
for i = 1:n
for j = 1:n
k = k+1;
if i ~= j
subplot(n,n,k);
plot(lam,squeeze(P(i,j,:)));
axis('square');
xlim(xlims);
ylim(ylims);
xlabel(xlab);
%ylabel(sprintf('%d -> %d',j,i));
ylabel(strcat(label{j,1},'->',label{i,1}))
end
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
PSI_Analysis.m
|
.m
|
CorticoHippocampal-master/Granger/PSI_Analysis.m
| 2,417 |
utf_8
|
5b85c1d9e1d4e5b065abdaace3827007
|
%%
function psi_val=PSI_Analysis(cwt_sig_area_1,cwt_sig_area_2,F)
% Phase-slope index for two signals
%Initialize
% F is the vector of frequencies used to decompose the signal in the
% analytical signal
S_12=zeros(numel(F),1);
S_11=zeros(numel(F),1);
S_22=zeros(numel(F),1);
C_12=zeros(numel(F),1);
C_12_jk=zeros(numel(F),4);
% Here cwt_sig_are 1 and 2 are the two analytical signals FxT (F are the frequencies used and T is time bins)
tb=size(cwt_sig_area_1,2);
for ff=1:numel(F)
% Definition (2) in the paper
S_11(ff)=mean(cwt_sig_area_1(ff,:).*conj(cwt_sig_area_1(ff,:)));
S_22(ff)=mean(cwt_sig_area_2(ff,:).*conj(cwt_sig_area_2(ff,:)));
S_12(ff)=mean(cwt_sig_area_1(ff,:).*conj(cwt_sig_area_2(ff,:)));
% Complex coherency used to compute (3)
C_12(ff)=S_12(ff)/sqrt(S_11(ff)*S_22(ff));
end
% Same as above but for subsets of data, here I use 4-drop-1 bootstrapping
for jk=1:4
cwt_sig_area_1_jk=cwt_sig_area_1;
cwt_sig_area_2_jk=cwt_sig_area_2;
cwt_sig_area_1_jk(:,floor(tb/4)*(jk-1)+1:floor(tb/4)*(jk))=[];
cwt_sig_area_2_jk(:,floor(tb/4)*(jk-1)+1:floor(tb/4)*(jk))=[];
for ff=1:numel(F)
S_11(ff)=mean(cwt_sig_area_1_jk(ff,:).*conj(cwt_sig_area_1_jk(ff,:)));
S_22(ff)=mean(cwt_sig_area_2_jk(ff,:).*conj(cwt_sig_area_2_jk(ff,:)));
S_12(ff)=mean(cwt_sig_area_1_jk(ff,:).*conj(cwt_sig_area_2_jk(ff,:)));
C_12_jk(ff,jk)=S_12(ff)/sqrt(S_11(ff)*S_22(ff));
end
end
% DoLim=[20 50 90 150];
% UpLim=[50 90 150 300];
DoLim=[0 20 0 4 8 100];
UpLim=[20 300 4 8 20 250];
% Here I compute the Phase Slope Index for different frequency ranges (you can change this)
for cc=1:length(DoLim)
[~,F1]=min(abs(F-DoLim(cc)));
[~,F2]=min(abs(F-UpLim(cc)));
% Compute quantity psi-tilde of (4) in the paper
%Psi_12=sum(conj(C_12(F1+1:F2)).*C_12(F1:F2-1));
Psi_12=sum(conj(C_12(F1:F2-1)).*C_12(F1+1:F2));
Psi_12=imag(Psi_12);
% Compute the normalization factor
for jk=1:4
%Psi_12_jk(jk)=sum(conj(C_12_jk(F2+1:F1,jk)).*C_12_jk(F2:F1-1,jk));
% Psi_12_jk(jk)=sum(conj(C_12_jk(F1+1:F2,jk)).*C_12_jk(F1:F2-1,jk));
Psi_12_jk(jk)=sum(conj(C_12_jk(F1:F2-1,jk)).*C_12_jk(F1+1:F2,jk));
end
% Compute std(psi-tilde) - See text for details of the formula (sqrt(k)*std_set)
sigma=2*std(imag(Psi_12_jk));
% Print the resulting normalized PSI (Phase Slope Index)
psi_val(cc)=Psi_12/sigma;
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
granger_paper4.m
|
.m
|
CorticoHippocampal-master/Granger/granger_paper4.m
| 2,194 |
utf_8
|
0b710bb53785f560c67158311d418222
|
function granger_paper4(g,g_f,labelconditions,freqrange)
allscreen()
myColorMap=StandardColors;
F= [1 2; 1 3; 2 3] ;
lab=cell(6,1);
% lab{1}='HPC -> Parietal';
% lab{2}='Parietal -> HPC';
%
% lab{3}='HPC -> PFC';
% lab{4}='PFC -> HPC';
%
% lab{5}='Parietal -> PFC';
% lab{6}='PFC -> Parietal';
lab{2}='PFC -> PAR';
lab{1}='PAR -> PFC';
lab{4}='HPC -> PAR';
lab{3}='PAR -> HPC';
lab{6}='HPC -> PFC';
lab{5}='PFC -> HPC';
%
% k=1; %Condition 1.
for j=1:3
f=F(j,:);
mmax1=max([max(squeeze(g{1}(f(1),f(2),:))) max(squeeze(g{2}(f(1),f(2),:))) ...
max(squeeze(g{3}(f(1),f(2),:))) max(squeeze(g{4}(f(1),f(2),:)))]);
mmax2=max([max(squeeze(g{1}(f(2),f(1),:))) max(squeeze(g{2}(f(2),f(1),:))) ...
max(squeeze(g{3}(f(2),f(1),:))) max(squeeze(g{4}(f(2),f(1),:)))]);
mmax=max([mmax1 mmax2]);
%
subplot(3,2,2*j-1)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(1),f(2),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(1),f(2),:)),'LineWidth',2,'Color',myColorMap(1,:))
hold on
plot(g_f, squeeze(g{2}(f(1),f(2),:)),'LineWidth',2,'Color',myColorMap(2,:))
plot(g_f, squeeze(g{3}(f(1),f(2),:)),'LineWidth',2,'Color',myColorMap(3,:))
plot(g_f, squeeze(g{4}(f(1),f(2),:)),'LineWidth',2,'Color',myColorMap(4,:))
xlim(freqrange)
% ylim([0 mmax])
%grid minor
xlabel('Frequency (Hz)')
% ylabel('G-causality')
ylabel('PSI')
title(lab{2*j-1})
% legend('Parametric: AR(10)','Non-P:Multitaper')
%if j==1
% legend(labelconditions)
%end
subplot(3,2,2*j)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(2),f(1),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(2),f(1),:)),'LineWidth',2,'Color',myColorMap(1,:))
hold on
plot(g_f, squeeze(g{2}(f(2),f(1),:)),'LineWidth',2,'Color',myColorMap(2,:))
plot(g_f, squeeze(g{3}(f(2),f(1),:)),'LineWidth',2,'Color',myColorMap(3,:))
plot(g_f, squeeze(g{4}(f(2),f(1),:)),'LineWidth',2,'Color',myColorMap(4,:))
xlim(freqrange)
%grid minor
xlabel('Frequency (Hz)')
% ylabel('G-causality')
ylabel('PSI')
%legend('Parametric: AR(10)','Non-P:Multitaper')
if j==1
legend(labelconditions,'Location','best') %Might have to change to default.
end
title(lab{2*j})
%ylim([0 mmax])
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
gc_paper.m
|
.m
|
CorticoHippocampal-master/Granger/gc_paper.m
| 11,941 |
utf_8
|
3d43d2a8647413fea38534fc4a1cdf70
|
function [granger,granger1,granger_cond,granger_cond_multi]=gc_paper(q,timecell,label,ro,ord,freqrange,fn)
%fn=1000;
data1.trial=q;
data1.time= timecell; %Might have to change this one
data1.fsample=fn;
data1.label=cell(3,1);
% data1.label{1}='Hippocampus';
% data1.label{2}='Parietal';
% data1.label{3}='PFC';
data1.label{1}='PAR';
data1.label{2}='PFC';
data1.label{3}='HPC';
%data1.label{4}='Reference';
%Parametric model
%[granger1]=createauto(data1,ord); %this is the good one .
%[granger1_cond]=createauto_conditional(data1,ord);
[granger1]=createauto(data1,ord,'yes');
% cfg = [];
% cfg.order = ord;
% cfg.toolbox = 'bsmart';
% mdata = ft_mvaranalysis(cfg, data1);
%
% cfg = [];
% cfg.method = 'mvar';
% mfreq = ft_freqanalysis(cfg, mdata);
% granger1 = ft_connectivityanalysis(cfg, mfreq);
%Non parametric
[granger]=createauto_np(data1,freqrange,[]);
[granger_cond]=createauto_np(data1,freqrange,'yes');
[granger_cond_multi]=createauto_cond_multivariate(data1,ord);
% cfg = [];
% cfg.method = 'mtmfft';
% cfg.taper = 'dpss';
% %cfg.taper = 'hanning';
%
% cfg.output = 'fourier';
% cfg.tapsmofrq = 2;
% cfg.pad = 10;
% cfg.foi=freqrange;
% freq = ft_freqanalysis(cfg, data1);
% %Non parametric- Multitaper
% cfg = [];
% cfg.method = 'mtmconvol';
% cfg.foi = 1:1:100;
% cfg.taper = 'dpss';
% cfg.output = 'fourier';
% cfg.tapsmofrq = 10;
% cfg.toi='50%';
% cfg.t_ftimwin = ones(length(cfg.foi),1).*.1; % length of time window = 0.5 sec
%
%
% freq1 = ft_freqanalysis(cfg, data1);
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % Nonparametric freq analysis (OTHER WAVELET)
% cfg = [];
% cfg.method = 'wavelet';
% % cfg.width=10;
% cfg.gwidth=5;
%
% cfg.foi = 0:5:300;
% %cfg.foilim=[10 100]
% % cfg.taper = 'dpss';
% cfg.output = 'powandcsd';
% %andcsd
% %cfg.toi=-0.2:0.001:0.2;
% cfg.toi=-0.199:0.1:0.2;
%
% %cfg.t_ftimwin = ones(length(cfg.foi),1).*0.1; % length of time window = 0.5 sec
% % % %
% % % % % Nonparametric freq analysis (MTMconvol)
% % % % cfg = [];
% % % % %cfg.method = 'mtmfft';
% % % % cfg.method = 'mtmconvol';
% % % % %cfg.pad = 'nextpow2';
% % % % cfg.pad = 10;
% % % %
% % % % cfg.taper = 'dpss';
% % % % cfg.output = 'fourier';
% % % % cfg.foi=[0:2:300];
% % % % cfg.tapsmofrq = 10;
% % % % cfg.t_ftimwin=ones(length(cfg.foi),1).*(0.1);
% % % % %cfg.t_ftimwin=1000./cfg.foi;
% % % % %cfg.tapsmofrq = 0.4*cfg.foi;
%cfg.t_ftimwin=7./cfg.foi;
% % % % % % % % cfg.toi='50%';
% % % % % % % cfg.toi=linspace(-0.2,0.2,10);
% % % % % % % freq1 = ft_freqanalysis(cfg, data1);
% % % % % % % %
% % % % % % % % % Nonparametric freq analysis (Wavelet)
% % % % % % % % cfg = [];
% % % % % % % % %cfg.method = 'mtmfft';
% % % % % % % % cfg.method = 'wavelet';
% % % % % % % % %cfg.pad = 'nextpow2';
% % % % % % % % cfg.pad = 2;
% % % % % % % %
% % % % % % % % cfg.width=1;
% % % % % % % %
% % % % % % % % cfg.taper = 'dpss';
% % % % % % % % cfg.output = 'powandcsd';
% % % % % % % % cfg.foi=[0:5:300];
% % % % % % % % % cfg.tapsmofrq = 2;
% % % % % % % % %cfg.t_ftimwin=ones(length(cfg.foi),1).*(0.1);
% % % % % % % % %cfg.t_ftimwin=7./cfg.foi;
% % % % % % % %
% % % % % % % % % cfg.toi='50%';
% % % % % % % % cfg.toi=linspace(-0.2,0.2,10);
% % % % % % % % freq_mtmfft = ft_freqanalysis(cfg, data1);
% % %
% % % % Nonparametric freq analysis (Wavelet OTHER)
% % % cfg = [];
% % % %cfg.method = 'mtmfft';
% % % cfg.method = 'tfr';
% % % %cfg.pad = 'nextpow2';
% % % cfg.pad = 2;
% % %
% % % cfg.width=2;
% % % %
% % % % cfg.taper = 'dpss';
% % % cfg.output = 'powandcsd';
% % % cfg.foi=[0:5:300];
% % % %%cfg.tapsmofrq = 2;
% % % cfg.t_ftimwin=ones(length(cfg.foi),1).*(0.1);
% % % %cfg.t_ftimwin=7./cfg.foi;
% % %
% % % % cfg.toi='50%';
% % % cfg.toi=linspace(-0.2,0.2,5);
% % % freq_wavt = ft_freqanalysis(cfg, data1);
% cfg = [];
% cfg.method = 'granger';
% granger = ft_connectivityanalysis(cfg, freq);
% granger1 = ft_connectivityanalysis(cfg, mfreq);
% % % % % % % % % % % % % % % % % % % % % % % %granger2 = ft_connectivityanalysis(cfg, freq1);
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % %%granger3 = ft_connectivityanalysis(cfg, freq_mtmfft); %Wavelet
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % granger4 = ft_connectivityanalysis(cfg, freq_wavt);
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % %lab=cell(16,1);
% % % % % % % % % % % % % % % % % % % % % % % % lab{1}='Hippo -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % % lab{2}='Hippo -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % % lab{3}='Hippo -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % % lab{4}='Hippo -> Reference';
% % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % lab{5}='Parietal -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % % lab{6}='Parietal -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % % lab{7}='Parietal -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % % lab{8}='Parietal -> Reference';
% % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % lab{9}='PFC -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % % lab{10}='PFC -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % % lab{11}='PFC -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % % lab{12}='PFC -> Reference';
% % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % lab{13}='Reference -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % % lab{14}='Reference -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % % lab{15}='Reference -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % % lab{16}='Reference -> Reference';
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % lab=cell(9,1);
% % % % % % % % % % % % % % % % % % % % % % % lab{1}='Hippo -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % lab{2}='Hippo -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % lab{3}='Hippo -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % %lab{4}='Hippo -> Reference';
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % lab{4}='Parietal -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % lab{5}='Parietal -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % lab{6}='Parietal -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % %lab{8}='Parietal -> Reference';
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % lab{7}='PFC -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % lab{8}='PFC -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % lab{9}='PFC -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % %lab{12}='PFC -> Reference';
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % lab{13}='Reference -> Hippo';
% % % % % % % % % % % % % % % % % % % % % % % % lab{14}='Reference -> Parietal';
% % % % % % % % % % % % % % % % % % % % % % % % lab{15}='Reference -> PFC';
% % % % % % % % % % % % % % % % % % % % % % % % lab{16}='Reference -> Reference';
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % figure
% % % % % % % % % % % % % % % % % % % % % % % conta=0;
% % % % % % % % % % % % % % % % % % % % % % % compt=0;
% % % % % % % % % % % % % % % % % % % % % % % figure('units','normalized','outerposition',[0 0 1 1])
% % % % % % % % % % % % % % % % % % % % % % % %for j=1:length(freq1.time)
% % % % % % % % % % % % % % % % % % % % % % % compt=compt+1;
% % % % % % % % % % % % % % % % % % % % % % % conta=0;
% % % % % % % % % % % % % % % % % % % % % % % for row=1:length(data1.label)
% % % % % % % % % % % % % % % % % % % % % % % for col=1:length(data1.label)
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % subplot(length(data1.label),length(data1.label),(row-1)*length(data1.label)+col);
% % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % plot(granger2.freq, squeeze(granger2.grangerspctrm(row,col,:,j)),'LineWidth',.01,'Color',[0 0 0])
% % % % % % % % % % % % % % % % % % % % % % % % % % % % %hold on
% % % % % % % % % % % % % % % % % % % % % % % % % % % % plot(granger1.freq, squeeze(granger1.grangerspctrm(row,col,:)),'Color',[1 0 0])
% % % % % % % % % % % % % % % % % % % % % % % % % % % % hold on
% % % % % % % % % % % % % % % % % % % % % % % % % % % % plot(granger.freq, squeeze(granger.grangerspctrm(row,col,:)),'Color',[0 0 1])
% % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % %%plot(granger3.freq, squeeze(granger3.grangerspctrm(row,col,:,j)),'LineWidth',.01,'Color',[0 1 0])
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % %plot(granger2.freq, squeeze(granger2.grangerspctrm(row,col,:)))
% % % % % % % % % % % % % % % % % % % % % % % % plot(granger4.freq, squeeze(granger4.grangerspctrm(row,col,:,j)),'LineWidth',.01,'Color',[1 1 0])
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % ylim([0 1])
% % % % % % % % % % % % % % % % % % % % % % % xlim([0 300])
% % % % % % % % % % % % % % % % % % % % % % % xlabel('Frequency (Hz)')
% % % % % % % % % % % % % % % % % % % % % % % grid minor
% % % % % % % % % % % % % % % % % % % % % % % conta=conta+1;
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % if conta==1 || conta==6 || conta==11 || conta==16
% % % % % % % % % % % % % % % % % % % % % % % if conta==1 || conta==5 || conta==9
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % legend('NP:Multitaper','Parametric: AR(10)','NP:MTMFFT')
% % % % % % % % % % % % % % % % % % % % % % % % legend('Parametric: AR(10)','Non-P:Multitaper')
% % % % % % % % % % % % % % % % % % % % % % % % set(gca,'Color','k')
% % % % % % % % % % % % % % % % % % % % % % % % text(100,0.5,'A Simple Plot','Color','red','FontSize',14)
% % % % % % % % % % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % % % % % % % % % % if conta==5
% % % % % % % % % % % % % % % % % % % % % % % % text(100,0.5,'Monopolar','Color','red','FontSize',14)
% % % % % % % % % % % % % % % % % % % % % % % % text(100,0.35,label,'Color','red','FontSize',14)
% % % % % % % % % % % % % % % % % % % % % % % % text(100,0.20,strcat('(+/-',num2str(ro),'ms)'),'Color','red','FontSize',14)
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % % % % % % % % % % title(lab{conta})
% % % % % % % % % % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % % % % % % % % % % end
% % % % % % % % % % % % % % % % % % % % % % % %end
% % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % mtit('Monopolar','fontsize',14,'color',[1 0 0],'position',[.5 1 ])
% % % % % % % % % % % % % % % % % % % % % % % %mtit(label,'fontsize',14,'color',[1 0 0],'position',[.5 0.75 ])
% % % % % % % % % % % % % % % % % % % % % % % %mtit(strcat('(+/-',num2str(ro),'ms)'),'fontsize',14,'color',[1 0 0],'position',[.5 0.5 ])
% % % % % % % % % % % % % % % % % % % % % % % compt
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
granger_paper4_cond.m
|
.m
|
CorticoHippocampal-master/Granger/granger_paper4_cond.m
| 2,069 |
utf_8
|
dc8ad22deb0845211b50759db2049b0c
|
function granger_paper4_cond(g,g_f,labelconditions,freqrange)
allscreen()
myColorMap=StandardColors;
F= [1 3 5] ;
lab=cell(6,1);
% lab{1}='HPC -> Parietal';
% lab{2}='Parietal -> HPC';
%
% lab{3}='HPC -> PFC';
% lab{4}='PFC -> HPC';
%
% lab{5}='Parietal -> PFC';
% lab{6}='PFC -> Parietal';
%
lab{1}='PFC -> PAR';
lab{2}='PAR -> PFC';
lab{3}='HPC -> PAR';
lab{4}='PAR -> HPC';
lab{5}='HPC -> PFC';
lab{6}='PFC -> HPC';
% k=1; %Condition 1.
for j=1:3
%2,1
%4,3
%6,5
f=F(j);
mmax1=max([max(squeeze(g{1}(f,:))) max(squeeze(g{2}(f,:))) ...
max(squeeze(g{3}(f,:))) max(squeeze(g{4}(f,:)))]);
mmax2=max([max(squeeze(g{1}(f+1,:))) max(squeeze(g{2}(f+1,:))) ...
max(squeeze(g{3}(f+1,:))) max(squeeze(g{4}(f+1,:)))]);
mmax=max([mmax1 mmax2]);
%
subplot(3,2,2*j-1)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(1),f(2),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f,:)),'LineWidth',2,'Color',myColorMap(1,:))
hold on
plot(g_f, squeeze(g{2}(f,:)),'LineWidth',2,'Color',myColorMap(2,:))
plot(g_f, squeeze(g{3}(f,:)),'LineWidth',2,'Color',myColorMap(3,:))
plot(g_f, squeeze(g{4}(f,:)),'LineWidth',2,'Color',myColorMap(4,:))
xlim(freqrange)
ylim([0 mmax])
%grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
title(lab{2*j-1})
% legend('Parametric: AR(10)','Non-P:Multitaper')
%if j==1
% legend(labelconditions)
%end
subplot(3,2,2*j)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(2),f(1),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f+1,:)),'LineWidth',2,'Color',myColorMap(1,:))
hold on
plot(g_f, squeeze(g{2}(f+1,:)),'LineWidth',2,'Color',myColorMap(2,:))
plot(g_f, squeeze(g{3}(f+1,:)),'LineWidth',2,'Color',myColorMap(3,:))
plot(g_f, squeeze(g{4}(f+1,:)),'LineWidth',2,'Color',myColorMap(4,:))
xlim(freqrange)
%grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
%legend('Parametric: AR(10)','Non-P:Multitaper')
if j==1
legend(labelconditions,'Location','best') %Might have to change to default.
end
title(lab{2*j})
ylim([0 mmax])
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
granger_paper.m
|
.m
|
CorticoHippocampal-master/Granger/granger_paper.m
| 1,352 |
utf_8
|
82387c68a7ce7186b35c32a25f7b520b
|
function granger_paper(granger,granger1,condition)
allscreen()
F= [1 2; 1 3; 2 3] ;
lab=cell(6,1);
lab{1}='HPC -> Parietal';
lab{2}='Parietal -> HPC';
lab{3}='HPC -> PFC';
lab{4}='PFC -> HPC';
lab{5}='Parietal -> PFC';
lab{6}='PFC -> Parietal';
for j=1:3
f=F(j,:);
mmax1=[max(squeeze(granger1.grangerspctrm(f(1),f(2),:))) max(squeeze(granger.grangerspctrm(f(1),f(2),:)))];
mmax1=max(mmax1);
mmax2=[max(squeeze(granger1.grangerspctrm(f(2),f(1),:))) max(squeeze(granger.grangerspctrm(f(2),f(1),:)))];
mmax2=max(mmax2);
mmax=max([mmax1 mmax2]);
%
subplot(3,2,2*j-1)
plot(granger1.freq, squeeze(granger1.grangerspctrm(f(1),f(2),:)),'Color',[1 0 0])
hold on
plot(granger.freq, squeeze(granger.grangerspctrm(f(1),f(2),:)),'Color',[0 0 1])
xlim([0 300])
ylim([0 mmax])
grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
title(lab{2*j-1})
% legend('Parametric: AR(10)','Non-P:Multitaper')
legend('Baseline',condition)
subplot(3,2,2*j)
plot(granger1.freq, squeeze(granger1.grangerspctrm(f(2),f(1),:)),'Color',[1 0 0])
hold on
plot(granger.freq, squeeze(granger.grangerspctrm(f(2),f(1),:)),'Color',[0 0 1])
xlim([0 300])
grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
%legend('Parametric: AR(10)','Non-P:Multitaper')
legend('Baseline',condition)
title(lab{2*j})
ylim([0 mmax])
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
pal_test_ft_granger_cond.m
|
.m
|
CorticoHippocampal-master/Granger/pal_test_ft_granger_cond.m
| 9,187 |
utf_8
|
becb3859245b08ec4138a92466bbef75
|
%
% This function performs spectrally resolved Granger causality using the
% non-parametric spectral matrix factorization of Wilson, as implemented
% by Dhahama & Rangarajan in sfactorization_wilson. Both standard and
% conditional Granger causality are attempted.
%
% FieldTrip code being used is a recent download zip file dated
% 6/3/2014. Running on Windows 7, Student Edition Matlab R2012a.
%
function [] = pal_test_ft_granger_cond()
close all;
NTrials = 100;
NSamples = 300;
FS = 200;
%NSamples2 = floor(NSamples/2)+1; % number of samples 0-PI
%Freqs = [0:NSamples-1]*(FS/NSamples);
%Freqs2 = Freqs(1:NSamples2); % frequencies 0-PI
%Times = [0:(NSamples-1)]/FS; % times corresponding to samples
%
% Build a sample MVAR system
%
% X.trial is a 1xNTrials cell array, with each cell containing a
% PxNSamples array of doubles.
%
fprintf('Generating sample MVAR trials...');
mvar_cfg = [];
mvar_cfg.ntrials = NTrials;
mvar_cfg.triallength = NSamples/FS;
mvar_cfg.fsample = FS;
mvar_cfg.nsignal = 3;
mvar_cfg.method = 'ar';
if (0)
%
% From Dhamala, Rangarajan, & Ding, 2008, Physical Review Letters
% (with addition of third noise series if desired).
% Direction of causality does not change mid-trial as in the paper.
%
% x1(t) = 0.5*x1(t-1) - 0.8*x1(t-2)
% x2(t) = 0.5*x2(t-1) - 0.8*x2(t-2) + 0.25*x1(t-1)
% x3(t) = noise, no AR structure, not linked to x1, x2
%
% The spectrum of these series have a characteristic peak around 40 Hz.
%
if (mvar_cfg.nsignal == 2)
mvar_cfg.params(:,:,1) = [ 0.5 0.0 ;
0.25 0.5 ];
mvar_cfg.params(:,:,2) = [-0.8 0.0 ;
0.0 -0.8];
mvar_cfg.noisecov = [ 1.0 0.0 ;
0.0 1.0];
else
mvar_cfg.params(:,:,1) = [ 0.5 0.0 0.0 ;
0.25 0.5 0.0 ;
0.0 0.0 0.0];
mvar_cfg.params(:,:,2) = [-0.8 0.0 0.0 ;
0.0 -0.8 0.0 ;
0.0 0.0 0.0];
mvar_cfg.noisecov = [ 1.0 0.0 0.0 ;
0.0 1.0 0.0 ;
0.0 0.0 1.0];
end
else
%
% From Dhamala, Rangarajan, & Ding, 2008, NeuroImage. 3-variable
% system used to test condition Granger causality. Here y->z->x.
% Conditional Granger will show this, but non-conditional will show
% y->x as well.
%
% x(t) = 0.80*x(t-1) - 0.50*x(t-2) + 0.40*z(t-1)
% y(t) = 0.53*y(t-1) - 0.80*y(t-2)
% z(t) = 0.50*z(t-1) - 0.20*z(t-2) + 0.50*y(t-1)
%
mvar_cfg.params(:,:,1) = [ 0.8 0.0 0.4 ;
0.0 0.53 0.0 ;
0.0 0.5 0.5];
mvar_cfg.params(:,:,2) = [-0.5 0.0 0.0 ;
0.0 -0.8 0.0 ;
0.0 0.0 -0.2];
mvar_cfg.noisecov = [ 1.0 0.0 0.0 ;
0.0 1.0 0.0 ;
0.0 0.0 1.0];
end
X = ft_connectivitysimulation(mvar_cfg);
size(X)
X
%
% Estimate the parameters of the system we just built - sanity check.
% This works fine with the possible exception that the individual
% series noise variances are estimated as 0.0033 instead of 1. The
% estimated model order is 5 but coefficients are small where expected
% to be.
%
if (0)
fprintf('Estimating parameters of MVAR system...\n');
mvar_est_cfg = [];
mvar_est_cfg.order = 5;
mvar_est_cfg.toolbox = 'bsmart';
mvar_est_X = ft_mvaranalysis(mvar_est_cfg, X);
mvar_est_X
mvar_est_X.coeffs
mvar_est_X.noisecov
end
%
% Transform the system into the Fourier frequency domain. It appears
% that the output is an average of the individual trial spectra.
%
fprintf('Transforming MVAR trials into average Fourier spectra...\n');
fourier_cfg = [];
fourier_cfg.output = 'powandcsd';
fourier_cfg.method = 'mtmfft';
fourier_cfg.taper = 'dpss';
fourier_cfg.tapsmofrq = 2;
fourier_freq = ft_freqanalysis(fourier_cfg, X);
fourier_freq
%
% Plot the Fourier frequency power and cross-power spectra. Abs is
% applied to the complex cross-power, but is unnecessary for the real-
% valued auto-power spectra. Everything looks good here.
%
fprintf('Plotting average Fourier spectra and cross-spectra...\n');
figure;
csidx=1;
n = mvar_cfg.nsignal;
for (r=1:n) % rows in subplot
for (c=r:n) % cols in subplot
pos = ((r-1)*n)+c; % position index to use in subplot
pos2 = ((c-1)*n)+r; % reflection of pos across diagonal
if (r==c)
subplot(n,n, pos); plot(fourier_freq.freq, fourier_freq.powspctrm(r, :) ); xlim([0 100]); ylim([0 0.2]);
else
subplot(n,n, pos); plot(fourier_freq.freq,abs(fourier_freq.crsspctrm(csidx,:))); xlim([0 100]); ylim([0 0.2]);
subplot(n,n,pos2); plot(fourier_freq.freq,abs(fourier_freq.crsspctrm(csidx,:))); xlim([0 100]); ylim([0 0.2]);
csidx = csidx+1;
end
end
end
%
% Do spectral decomposition and non-conditional granger causality in
% Fourier domain. This calls the non-parametric spectral
% factorization code sfactorization_wilson via
% ft_connectivity_csd2transfer.
%
% The Granger calculations appear to take place around line 100 of
% ft_connectivity_granger, and the equation is recognizatble from
% several sources including Dhamala, Rangarajan, & Ding, 2008, PRL,
% Eq 8.
%
fprintf('Non-conditional Granger causality in Fourier domain...\n');
fourier_granger_cfg = [];
fourier_granger_cfg.method = 'granger';
fourier_granger_cfg.granger.feedback = 'yes';
fourier_granger_cfg.granger = [];
fourier_granger_cfg.granger.conditional = 'no';
fourier_granger = ft_connectivityanalysis(fourier_granger_cfg, fourier_freq);
fourier_granger
fourier_granger.cfg
%
% Plot Granger results in Fourier frequency domain.
%
% Results are as expected for both MVAR systems described above. For
% the first system, the only non-zero output is for x1->x2 (subplot(3,3,2))
% in the 40 Hz range. Peak Granger output is ~0.75. Matches Fig 1. of
% Dhamala, Rangarajan, & Ding, 2008, PRL. Addition of the third noise
% variable makes no difference.
%
% For the second system, prima facie causality is seen y->x, y->z, and
% z->x, as expected from Dhamala, Rangarajan, & Ding, NeuroImage 2008,
% Fig. 1.
%
% My plotting convention is "row-causing-column".
%
figure;
for (r=1:n)
for (c=1:n)
pos = ((r-1)*n)+c;
subplot(n,n, pos); plot(fourier_granger.freq,squeeze(abs(fourier_granger.grangerspctrm(r,c,:)))); xlim([0 100]); ylim([0 1]);
end
end
%
% Same as block above but this time calculate conditional Granger.
% It appears that the Granger calculation is being performed in
% blockwise_conditionalgranger.m, but I do not recognize the
% normaliation matrix being applied.
%
% Three variables are required in order to avoid a crash in
% blockwise_conditionalgranger.m at line 21 (i.e. no test for a
% misguided attempt to perform conditional analysis on a bivariate
% system).
%
fprintf('Conditional Granger causality in Fourier domain...\n');
fourier_granger_cfg.granger.conditional = 'yes';
fourier_granger = ft_connectivityanalysis(fourier_granger_cfg, fourier_freq);
fourier_granger
fourier_granger.cfg
%
% Plot conditional Granger output.
%
% For the first MVAR system above there should be no difference in
% the non-conditional and conditional output (no opportunity for prima
% facie causality in this system). However, the conditional output
% shows constant non-zero values for x->x, y->x, and z->x, while
% all other plots are uniformly zero.
%
% For the second MVAR system output appears to be near zero in all
% plots for all frequencies.
%
figure;
for (r=1:n)
for (c=1:n)
pos = ((r-1)*n)+c;
subplot(n,n, pos); plot(fourier_granger.freq,squeeze(abs(fourier_granger.grangerspctrm(r,c,:)))); xlim([0 100]);
end
end
return;
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
granger_baseline_learning.m
|
.m
|
CorticoHippocampal-master/Granger/granger_baseline_learning.m
| 1,945 |
utf_8
|
89faf0775c6a1e6b5bb51f3c8f12c66b
|
function granger_baseline_learning(g,g_f,labelconditions,freqrange)
allscreen()
F= [1 2; 1 3; 2 3] ;
lab=cell(6,1);
lab{1}='HPC -> PAR';
lab{2}='PAR -> HPC';
lab{3}='HPC -> PFC';
lab{4}='PFC -> HPC';
lab{5}='PAR -> PFC';
lab{6}='PFC -> PAR';
%
% k=1; %Condition 1.
for j=1:3
f=F(j,:);
mmax1=max([max(squeeze(g{1}(f(1),f(2),:))) max(squeeze(g{2}(f(1),f(2),:))) ...
max(squeeze(g{3}(f(1),f(2),:))) max(squeeze(g{4}(f(1),f(2),:)))]);
mmax2=max([max(squeeze(g{1}(f(2),f(1),:))) max(squeeze(g{2}(f(2),f(1),:))) ...
max(squeeze(g{3}(f(2),f(1),:))) max(squeeze(g{4}(f(2),f(1),:)))]);
mmax=max([mmax1 mmax2]);
%
subplot(3,2,2*j-1)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(1),f(2),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(1),f(2),:)),'LineWidth',2,'Color',[0.5 0.5 0.5])
hold on
%plot(g_f, squeeze(g{2}(f(1),f(2),:)),'LineWidth',2)
%plot(g_f, squeeze(g{3}(f(1),f(2),:)),'LineWidth',2)
plot(g_f, squeeze(g{2}(f(1),f(2),:)),'LineWidth',2,'Color',[0 0 0])
xlim(freqrange)
ylim([0 mmax])
%grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
title(lab{2*j-1})
% legend('Parametric: AR(10)','Non-P:Multitaper')
%if j==1
% legend(labelconditions)
%end
subplot(3,2,2*j)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(2),f(1),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(2),f(1),:)),'LineWidth',2,'Color',[0.5 0.5 0.5])
hold on
%plot(g_f, squeeze(g{2}(f(2),f(1),:)),'LineWidth',2)
%plot(g_f, squeeze(g{3}(f(2),f(1),:)),'LineWidth',2)
plot(g_f, squeeze(g{2}(f(2),f(1),:)),'LineWidth',2,'Color',[0 0 0])
xlim(freqrange)
%grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
%legend('Parametric: AR(10)','Non-P:Multitaper')
if j==1
labcon=[labelconditions(1);labelconditions(2)]
labcon=['Control';labelconditions(2)]
legend(labcon,'Location','best') %Might have to change to default.
end
title(lab{2*j})
ylim([0 mmax])
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
granger_paper2.m
|
.m
|
CorticoHippocampal-master/Granger/granger_paper2.m
| 1,198 |
utf_8
|
9142d0b8d47cd3ea797e8e97b5e692c4
|
function granger_paper2(granger,condition)
%allscreen()
F= [1 2; 1 3; 2 3] ;
lab=cell(6,1);
lab{1}='HPC -> Parietal';
lab{2}='Parietal -> HPC';
lab{3}='HPC -> PFC';
lab{4}='PFC -> HPC';
lab{5}='Parietal -> PFC';
lab{6}='PFC -> Parietal';
for j=1:3
f=F(j,:);
mmax1=[max(squeeze(granger.grangerspctrm(f(1),f(2),:)))];
mmax1=max(mmax1);
mmax2=[max(squeeze(granger.grangerspctrm(f(2),f(1),:)))];
mmax2=max(mmax2);
mmax=max([mmax1 mmax2]);
%
subplot(3,2,2*j-1)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(1),f(2),:)),'Color',[1 0 0])
% hold on
plot(granger.freq, squeeze(granger.grangerspctrm(f(1),f(2),:)))
xlim([0 300])
ylim([0 mmax])
grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
title(lab{2*j-1})
% legend('Parametric: AR(10)','Non-P:Multitaper')
legend(condition)
subplot(3,2,2*j)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(2),f(1),:)),'Color',[1 0 0])
% hold on
plot(granger.freq, squeeze(granger.grangerspctrm(f(2),f(1),:)))
xlim([0 300])
grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
%legend('Parametric: AR(10)','Non-P:Multitaper')
legend(condition)
title(lab{2*j})
ylim([0 mmax])
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
plot_spw2.m
|
.m
|
CorticoHippocampal-master/Granger/plot_spw2.m
| 2,132 |
utf_8
|
bd11dcc87a2a2fad8aa9017d43e1759c
|
%% plot_spw
%
% Plot spectral pairwise quantities on a grid
%
% <matlab:open('plot_spw.m') code>
%
%% Syntax
%
% plot_spw(P,fs)
%
%% Arguments
%
% _input_
%
% P matrix of spectral pairwise quantities
% fs sample rate in Hz (default: normalised freq as per routine 'sfreqs')
% frange frequency range to plot: empty for all (default) else an ascending 2-vector
%
%% Description
%
% Plot pairwise spectral quantities in |P|, a 3-dim numerical matrix with
% first index representing target ("to"), second index source ("from")
% quantities and third index frequencies - typically spectral causalities (see
% e.g. <autocov_to_spwcgc.html |autocov_to_spwcgc|>).
%
%% See also
%
% <autocov_to_spwcgc.html |autocov_to_spwcgc|> |
% <mvgc_demo.html |mvgc_demo|> |
% <sfreqs.html |sfreqs|>
%
% (C) Lionel Barnett and Anil K. Seth, 2012. See file license.txt in
% installation directory for licensing terms.
%
%%
function plot_spw2(P,fs,frange)
P=rot90(fliplr(P));
n = size(P,1);
assert(ndims(P) == 3 && size(P,2) == n,'must be a 3-dim matrix with the first two dims square');
h = size(P,3);
if nargin < 2, fs = []; end % default to normalised frequency as per 'sfreqs'
if nargin < 3, frange = []; end; % default to all
if ~isempty(frange)
assert(isvector(frange) && length(frange) == 2 && frange(1) < frange(2),'frequency range must be an ascending 2-vector of frequencies');
end
fres = h-1;
lam = sfreqs(fres,fs)';
if ~isempty(frange)
idx = lam >= frange(1) & lam <= frange(2);
lam = lam(idx);
P = P(:,:,idx,:);
end
xlims = [lam(1) lam(end)];
ylims = [min(P(:)) 1.1*max(P(:))];
if isempty(fs), xlab = 'normalised frequency'; else xlab = 'frequency (Hz)'; end
k = 0;
for i = 1:n
for j = 1:n
k = k+1;
if i ~= j
subplot(n,n,k);
%plot(lam,squeeze(P(i,j,:)));
plot(lam,squeeze(P(j,i,:)));
axis('square');
xlim(xlims);
ylim(ylims);
xlabel(xlab);
% ylabel(sprintf('%d -> %d',j,i));
ylabel(sprintf('%d -> %d',i,j));
end
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
granger_paper4_row.m
|
.m
|
CorticoHippocampal-master/Granger/granger_paper4_row.m
| 2,256 |
utf_8
|
d7591695a93ac6831958a4dcd1ed4678
|
function granger_paper4_row(g,g_f,labelconditions,freqrange,wd)
allscreen()
myColorMap=StandardColors;
F= [1 2; 1 3; 2 3] ;
lab=cell(6,1);
lab{1}='HPC -> Parietal';
lab{2}='Parietal -> HPC';
lab{3}='HPC -> PFC';
lab{4}='PFC -> HPC';
lab{5}='Parietal -> PFC';
lab{6}='PFC -> Parietal';
%
% k=1; %Condition 1.
for j=wd:wd
f=F(j,:);
mmax1=max([max(squeeze(g{1}(f(1),f(2),:))) max(squeeze(g{2}(f(1),f(2),:))) ...
max(squeeze(g{3}(f(1),f(2),:))) max(squeeze(g{4}(f(1),f(2),:)))]);
mmax2=max([max(squeeze(g{1}(f(2),f(1),:))) max(squeeze(g{2}(f(2),f(1),:))) ...
max(squeeze(g{3}(f(2),f(1),:))) max(squeeze(g{4}(f(2),f(1),:)))]);
mmax=max([mmax1 mmax2]);
%
subplot(3,2,2*j-1)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(1),f(2),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(1),f(2),:)),'LineWidth',2,'Color',myColorMap(1,:))
hold on
plot(g_f, squeeze(g{2}(f(1),f(2),:)),'LineWidth',2,'Color',myColorMap(2,:))
plot(g_f, squeeze(g{3}(f(1),f(2),:)),'LineWidth',2,'Color',myColorMap(3,:))
plot(g_f, squeeze(g{4}(f(1),f(2),:)),'LineWidth',2,'Color',myColorMap(4,:))
xlim(freqrange)
ylim([0 mmax])
%grid minor
% xlabel('Frequency (Hz)')
% ylabel('G-causality')
ho=xlabel('Frequency (Hz)');
ho.FontSize=20;
ho=ylabel('G-causality');
ho.FontSize=20;
tp=title(lab{2*j-1});
tp.FontSize=20;
% legend('Parametric: AR(10)','Non-P:Multitaper')
%if j==1
% legend(labelconditions)
%end
set(gca,'FontSize',16)
subplot(3,2,2*j)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(2),f(1),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(2),f(1),:)),'LineWidth',2,'Color',myColorMap(1,:))
hold on
plot(g_f, squeeze(g{2}(f(2),f(1),:)),'LineWidth',2,'Color',myColorMap(2,:))
plot(g_f, squeeze(g{3}(f(2),f(1),:)),'LineWidth',2,'Color',myColorMap(3,:))
plot(g_f, squeeze(g{4}(f(2),f(1),:)),'LineWidth',2,'Color',myColorMap(4,:))
xlim(freqrange)
%grid minor
ho=xlabel('Frequency (Hz)');
ho.FontSize=20;
ho=ylabel('G-causality');
ho.FontSize=20;
%legend('Parametric: AR(10)','Non-P:Multitaper')
if j==1
lgd=legend(labelconditions) %Might have to change to default.
lgd.FontSize = 14;
end
tp=title(lab{2*j});
tp.FontSize=20;
ylim([0 mmax])
set(gca,'FontSize',16)
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
granger_paper4_with_stripes.m
|
.m
|
CorticoHippocampal-master/Granger/granger_paper4_with_stripes.m
| 2,376 |
utf_8
|
dae7509b8a54fb3066f76ef987717dfe
|
function granger_paper4_with_stripes(g,g_f,labelconditions,freqrange)
allscreen()
F= [1 2; 1 3; 2 3] ;
lab=cell(6,1);
lab{1}='HPC -> Parietal';
lab{2}='Parietal -> HPC';
lab{3}='HPC -> PFC';
lab{4}='PFC -> HPC';
lab{5}='Parietal -> PFC';
lab{6}='PFC -> Parietal';
%
% k=1; %Condition 1.
for j=1:3
f=F(j,:);
mmax1=max([max(squeeze(g{1}(f(1),f(2),:))) max(squeeze(g{2}(f(1),f(2),:))) ...
max(squeeze(g{3}(f(1),f(2),:))) max(squeeze(g{4}(f(1),f(2),:)))]);
mmax2=max([max(squeeze(g{1}(f(2),f(1),:))) max(squeeze(g{2}(f(2),f(1),:))) ...
max(squeeze(g{3}(f(2),f(1),:))) max(squeeze(g{4}(f(2),f(1),:)))]);
mmax=max([mmax1 mmax2]);
%
subplot(3,2,2*j-1)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(1),f(2),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(1),f(2),:)),'LineWidth',2)
hold on
plot(g_f, squeeze(g{2}(f(1),f(2),:)),'LineWidth',2)
plot(g_f, squeeze(g{3}(f(1),f(2),:)),'LineWidth',2)
plot(g_f, squeeze(g{4}(f(1),f(2),:)),'LineWidth',2)
je_base=g{1};
je_plus=g{4};
% Select direction
je_base=squeeze(je_base(f(1),f(2),:));
je_plus=squeeze(je_plus(f(1),f(2),:));
diffo=je_plus-je_base;
maxfreq=find(g_f==300);
[oud]=isoutlier(diffo(1:maxfreq));
ind=find(oud);
Ind=zeros(size(diffo));
Ind(ind)=1;
stripes(Ind,0.2,g_f)
xlim(freqrange)
ylim([0 mmax])
%grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
title(lab{2*j-1})
% legend('Parametric: AR(10)','Non-P:Multitaper')
%if j==1
% legend(labelconditions)
%end
subplot(3,2,2*j)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(2),f(1),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(2),f(1),:)),'LineWidth',2)
hold on
plot(g_f, squeeze(g{2}(f(2),f(1),:)),'LineWidth',2)
plot(g_f, squeeze(g{3}(f(2),f(1),:)),'LineWidth',2)
plot(g_f, squeeze(g{4}(f(2),f(1),:)),'LineWidth',2)
je_base=g{1};
je_plus=g{4};
% Select direction
je_base=squeeze(je_base(f(2),f(1),:));
je_plus=squeeze(je_plus(f(2),f(1),:));
diffo=je_plus-je_base;
maxfreq=find(g_f==300);
[oud]=isoutlier(diffo(1:maxfreq));
ind=find(oud);
Ind=zeros(size(diffo));
Ind(ind)=1;
stripes(Ind,0.2,g_f)
xlim(freqrange)
%grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
%legend('Parametric: AR(10)','Non-P:Multitaper')
if j==1
legend(labelconditions,'Location','best') %Might have to change to default.
end
title(lab{2*j})
ylim([0 mmax])
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
granger_paper4_with_stripes_dual.m
|
.m
|
CorticoHippocampal-master/Granger/granger_paper4_with_stripes_dual.m
| 2,389 |
utf_8
|
cb5a5e0f0ad87c2edb4fe666c2c8b88d
|
function granger_paper4_with_stripes_dual(g,g_f,labelconditions,freqrange)
allscreen()
F= [1 2; 1 3; 2 3] ;
lab=cell(6,1);
lab{1}='HPC -> Parietal';
lab{2}='Parietal -> HPC';
lab{3}='HPC -> PFC';
lab{4}='PFC -> HPC';
lab{5}='Parietal -> PFC';
lab{6}='PFC -> Parietal';
%
% k=1; %Condition 1.
for j=1:3
f=F(j,:);
mmax1=max([max(squeeze(g{1}(f(1),f(2),:))) max(squeeze(g{2}(f(1),f(2),:))) ...
max(squeeze(g{3}(f(1),f(2),:))) max(squeeze(g{4}(f(1),f(2),:)))]);
mmax2=max([max(squeeze(g{1}(f(2),f(1),:))) max(squeeze(g{2}(f(2),f(1),:))) ...
max(squeeze(g{3}(f(2),f(1),:))) max(squeeze(g{4}(f(2),f(1),:)))]);
mmax=max([mmax1 mmax2]);
%
subplot(3,2,2*j-1)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(1),f(2),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(1),f(2),:)),'LineWidth',2)
hold on
% plot(g_f, squeeze(g{2}(f(1),f(2),:)),'LineWidth',2)
% plot(g_f, squeeze(g{3}(f(1),f(2),:)),'LineWidth',2)
plot(g_f, squeeze(g{4}(f(1),f(2),:)),'LineWidth',2)
je_base=g{1};
je_plus=g{4};
% Select direction
je_base=squeeze(je_base(f(1),f(2),:));
je_plus=squeeze(je_plus(f(1),f(2),:));
diffo=je_plus-je_base;
maxfreq=find(g_f==300);
[oud]=isoutlier(diffo(1:maxfreq));
ind=find(oud);
Ind=zeros(size(diffo));
Ind(ind)=1;
stripes(Ind,0.2,g_f)
xlim(freqrange)
ylim([0 mmax])
%grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
title(lab{2*j-1})
% legend('Parametric: AR(10)','Non-P:Multitaper')
%if j==1
% legend(labelconditions)
%end
subplot(3,2,2*j)
% plot(granger1.freq, squeeze(granger1.grangerspctrm(f(2),f(1),:)),'Color',[1 0 0])
% hold on
plot(g_f, squeeze(g{1}(f(2),f(1),:)),'LineWidth',2)
hold on
% plot(g_f, squeeze(g{2}(f(2),f(1),:)),'LineWidth',2)
% plot(g_f, squeeze(g{3}(f(2),f(1),:)),'LineWidth',2)
plot(g_f, squeeze(g{4}(f(2),f(1),:)),'LineWidth',2)
je_base=g{1};
je_plus=g{4};
% Select direction
je_base=squeeze(je_base(f(2),f(1),:));
je_plus=squeeze(je_plus(f(2),f(1),:));
diffo=je_plus-je_base;
maxfreq=find(g_f==300);
[oud]=isoutlier(diffo(1:maxfreq));
ind=find(oud);
Ind=zeros(size(diffo));
Ind(ind)=1;
stripes(Ind,0.2,g_f)
xlim(freqrange)
%grid minor
xlabel('Frequency (Hz)')
ylabel('G-causality')
%legend('Parametric: AR(10)','Non-P:Multitaper')
if j==1
legend(labelconditions,'Location','best') %Might have to change to default.
end
title(lab{2*j})
ylim([0 mmax])
end
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
matcorr.m
|
.m
|
CorticoHippocampal-master/ICA/matcorr.m
| 5,853 |
utf_8
|
d0e3089eda2df7656eb20c1f476894f8
|
% matcorr() - Find matching rows in two matrices and their corrs.
% Uses the Hungarian (default), VAM, or maxcorr assignment methods.
% (Follow with matperm() to permute and sign x -> y).
%
% Usage: >> [corr,indx,indy,corrs] = matcorr(x,y,rmmean,method,weighting);
%
% Inputs:
% x = first input matrix
% y = matrix with same number of columns as x
%
% Optional inputs:
% rmmean = When present and non-zero, remove row means prior to correlation
% {default: 0}
% method = Method used to find assignments.
% 0= Hungarian Method - maximize sum of abs corrs {default: 2}
% 1= Vogel's Assignment Method -find pairs in order of max contrast
% 2= Max Abs Corr Method - find pairs in order of max abs corr
% Note that the methods 0 and 1 require matrices to be square.
% weighting = An optional weighting matrix size(weighting) = size(corrs) that
% weights the corrs matrix before pair assignment {def: 0/[]->ones()}
% Outputs:
% corr = a column vector of correlation coefficients between
% best-correlating rows of matrice x and y
% indx = a column vector containing the index of the maximum
% abs-correlated x row in descending order of abs corr
% (no duplications)
% indy = a column vector containing the index of the maximum
% abs-correlated row of y in descending order of abs corr
% (no duplications)
% corrs = an optional square matrix of row-correlation coefficients
% between matrices x and y
%
% Note: outputs are sorted by abs(corr)
%
% Authors: Scott Makeig & Sigurd Enghoff, SCCN/INC/UCSD, La Jolla, 11-30-96
% Copyright (C) 11-30-96 Scott Makeig, SCCN/INC/UCSD, [email protected]
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
% 04-22-99 Re-written using VAM by Sigurd Enghoff, CNL/Salk
% 04-30-99 Added revision of algorthm loop by SE -sm
% 05-25-99 Added Hungarian method assignment by SE
% 06-15-99 Maximum correlation method reinstated by SE
% 08-02-99 Made order of outpus match help msg -sm
% 02-16-00 Fixed order of corr output under VAM added method explanations,
% and returned corr signs in abs max method -sm
% 01-25-02 reformated help & license, added links -ad
% Uses function hungarian.m
function [corr,indx,indy,corrs] = matcorr(x,y,rmmean,method,weighting)
%
if nargin < 2 | nargin > 5
help matcorr
return
end
if nargin < 4
method = 2; % default: Max Abs Corr - select successive best abs(corr) pairs
end
[m,n] = size(x);
[p,q] = size(y);
m = min(m,p);
if m~=n | p~=q
if nargin>3 & method~=2
fprintf('matcorr(): Matrices are not square: using max abs corr method (2).\n');
end
method = 2; % Can accept non-square matrices
end
if n~=q
error('Rows in the two input matrices must be the same length.');
end
if nargin < 3 | isempty(rmmean)
rmmean = 0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if rmmean
x = x - mean(x')'*ones(1,n); % optionally remove means
y = y - mean(y')'*ones(1,n);
end
dx = sum(x'.^2);
dy = sum(y'.^2);
dx(find(dx==0)) = 1;
dy(find(dy==0)) = 1;
corrs = x*y'./sqrt(dx'*dy);
if nargin > 4 && ~isempty(weighting) && norm(weighting) > 0,
if any(size(corrs) ~= size(weighting))
fprintf('matcorr(): weighting matrix size must match that of corrs\n.')
return
else
corrs = corrs.*weighting;
end
end
cc = abs(corrs);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch method
case 0
ass = hungarian(-cc); % Performs Hungarian algorithm matching
idx1 = sub2ind(size(cc),ass,1:m);
[dummy idx2] = sort(-cc(idx1));
corr = corrs(idx1);
corr = corr(idx2)';
indy = [1:m]';
indx = ass(idx2)';
indy = indy(idx2);
case 1 % Implements the VAM assignment method
indx = zeros(m,1);
indy = zeros(m,1);
corr = zeros(m,1);
for i=1:m,
[sx ix] = sort(cc); % Looks for maximum salience along a row/column
[sy iy] = sort(cc'); % rather than maximum correlation.
[sxx ixx] = max(sx(end,:)-sx(end-1,:));
[syy iyy] = max(sy(end,:)-sy(end-1,:));
if sxx == syy
if sxx == 0 & syy == 0
[sxx ixx] = max((sx(end,:)-sx(end-1,:)) .* sx(end,:));
[syy iyy] = max((sy(end,:)-sy(end-1,:)) .* sy(end,:));
else
sxx = sx(end,ixx); % takes care of identical vectors
syy = sy(end,iyy); % and zero vectors
end
end
if sxx > syy
indx(i) = ix(end,ixx);
indy(i) = ixx;
else
indx(i) = iyy;
indy(i) = iy(end,iyy);
end
cc(indx(i),:) = -1;
cc(:,indy(i)) = -1;
end
i = sub2ind(size(corrs),indx,indy);
corr = corrs(i);
[tmp j] = sort(-abs(corr)); % re-sort by abs(correlation)
corr = corr(j);
indx = indx(j);
indy = indy(j);
case 2 % match successive max(abs(corr)) pairs
indx = zeros(size(cc,1),1);
indy = zeros(size(cc,1),1);
corr = zeros(size(cc,1),1);
for i = 1:size(cc,1)
[tmp j] = max(cc(:));
% [corr(i) j] = max(cc(:));
[indx(i) indy(i)] = ind2sub(size(cc),j);
corr(i) = corrs(indx(i),indy(i));
cc(indx(i),:) = -1; % remove from contention
cc(:,indy(i)) = -1;
end
otherwise
error('Unknown method');
end
|
github
|
Aleman-Z/CorticoHippocampal-master
|
matperm.m
|
.m
|
CorticoHippocampal-master/ICA/matperm.m
| 2,919 |
utf_8
|
697c96bef1109a7011a0d4781bfbedc3
|
% matperm() - transpose and sign rows of x to match y (run after matcorr() )
%
% Usage: >> [permx indperm] = matperm(x,y,indx,indy,corr);
%
% Inputs:
% x = first input matrix
% y = matrix with same number of columns as x
% indx = column containing row indices for x (from matcorr())
% indy = column containing row indices for y (from matcorr())
% corr = column of correlations between indexed rows of x,y (from matcorr())
% (used only for its signs, +/-)
% Outputs:
% permx = the matrix x permuted and signed according to (indx, indy,corr)
% to best match y. Rows of 0s added to x to match size of y if nec.
% indperm = permutation index turning x into y;
%
% Authors: Scott Makeig, Sigurd Enghoff & Tzyy-Ping Jung
% SCCN/INC/UCSD, La Jolla, 2000
% Copyright (C) 1996 Scott Makeig, SCCN/INC/UCSD, [email protected]
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
% 04-22-99 Adjusted for fixes and speed by Sigurd Enghoff & Tzyy-Ping Jung
% 01-25-02 Reformated help & license, added links -ad
function [permx,indperm]= matperm(x,y,indx,indy,corr)
[m,n] = size(x);
[p,q] = size(y);
[ix,z] = size(indx);
[iy,z] = size(indy);
oldm = m;
errcode=0;
if ix ~= iy | p ~= iy,
fprintf('matperm: indx and indy must be column vectors, same height as y.\n');
errcode=1
end;
if n~=q,
fprintf('matperm(): two matrices must be same number of columns.\n');
errcode=2;
else
if m<p,
x = [x;zeros(p-m,n)]; % add rows to x to match height of y
p=m;
elseif p<m,
y = [y;zeros(m-p,n)]; % add rows to y to match height of x
m=p;
end;
end;
if errcode==0,
%
% Return the row permutation of matrix x most correlated with matrix y:
% plus the resulting permutation index
%
indperm = [1:length(indx)]'; % column vector [1 2 ...nrows]
permx = x(indx,:);
indperm = indperm(indx,:);
ydni(indy) = 1:length(indy);
permx = permx(ydni,:);% put x in y row-order
indperm = indperm(ydni,:);
permx = permx.*(sgn(corr(ydni))*ones(1,size(permx,2)));
% make x signs agree with y
permx = permx(1:oldm,:); % throw out bottom rows if
% they were added to match y
indperm = indperm(1:oldm,:);
end;
return
function vals=sgn(data)
vals = 2*(data>=0)-1;
return
|
github
|
minjiang/transferlearning-master
|
MyTJM.m
|
.m
|
transferlearning-master/code/MyTJM.m
| 3,517 |
utf_8
|
ce3d34bcb6ed86fc570f1f4f818ff2aa
|
function [acc,acc_list,A] = MyTJM(X_src,Y_src,X_tar,Y_tar,options)
% Inputs:
%%% X_src :source feature matrix, ns * m
%%% Y_src :source label vector, ns * 1
%%% X_tar :target feature matrix, nt * m
%%% Y_tar :target label vector, nt * 1
%%% options:option struct
% Outputs:
%%% acc :final accuracy using knn, float
%%% acc_list:list of all accuracies during iterations
%%% A :final adaptation matrix, (ns + nt) * (ns + nt)
%% Set options
lambda = options.lambda; %% lambda for the regularization
dim = options.dim; %% dim is the dimension after adaptation, dim <= m
kernel_type = options.kernel_type; %% kernel_type is the kernel name, primal|linear|rbf
gamma = options.gamma; %% gamma is the bandwidth of rbf kernel
T = options.T; %% iteration number
fprintf('TJM: dim=%d lambda=%f\n',dim,lambda);
% Set predefined variables
X = [X_src',X_tar'];
X = X*diag(sparse(1./sqrt(sum(X.^2))));
ns = size(X_src,1);
nt = size(X_tar,1);
n = ns+nt;
% Construct kernel matrix
K = kernel_tjm(kernel_type,X,[],gamma);
% Construct centering matrix
H = eye(n)-1/(n)*ones(n,n);
% Construct MMD matrix
e = [1/ns*ones(ns,1);-1/nt*ones(nt,1)];
C = length(unique(Y_src));
M = e*e' * C;
Cls = [];
% Transfer Joint Matching: JTM
G = speye(n);
acc_list = [];
for t = 1:T
%%% Mc [If want to add conditional distribution]
N = 0;
if ~isempty(Cls) && length(Cls)==nt
for c = reshape(unique(Y_src),1,C)
e = zeros(n,1);
e(Y_src==c) = 1 / length(find(Y_src==c));
e(ns+find(Cls==c)) = -1 / length(find(Cls==c));
e(isinf(e)) = 0;
N = N + e*e';
end
end
M = (1 - mu) * M + mu * N;
M = M/norm(M,'fro');
[A,~] = eigs(K*M*K'+lambda*G,K*H*K',dim,'SM');
% [A,~] = eigs(X*M*X'+lambda*G,X*H*X',k,'SM');
G(1:ns,1:ns) = diag(sparse(1./(sqrt(sum(A(1:ns,:).^2,2)+eps))));
Z = A'*K;
Z = Z*diag(sparse(1./sqrt(sum(Z.^2))));
Zs = Z(:,1:ns)';
Zt = Z(:,ns+1:n)';
knn_model = fitcknn(Zs,Y_src,'NumNeighbors',1);
Cls = knn_model.predict(Zt);
acc = sum(Cls==Y_tar)/nt;
acc_list = [acc_list;acc(1)];
fprintf('[%d] acc=%f\n',t,full(acc(1)));
end
fprintf('Algorithm JTM terminated!!!\n\n');
end
% With Fast Computation of the RBF kernel matrix
% To speed up the computation, we exploit a decomposition of the Euclidean distance (norm)
%
% Inputs:
% ker: 'linear','rbf','sam'
% X: data matrix (features * samples)
% gamma: bandwidth of the RBF/SAM kernel
% Output:
% K: kernel matrix
function K = kernel_tjm(ker,X,X2,gamma)
switch ker
case 'linear'
if isempty(X2)
K = X'*X;
else
K = X'*X2;
end
case 'rbf'
n1sq = sum(X.^2,1);
n1 = size(X,2);
if isempty(X2)
D = (ones(n1,1)*n1sq)' + ones(n1,1)*n1sq -2*X'*X;
else
n2sq = sum(X2.^2,1);
n2 = size(X2,2);
D = (ones(n2,1)*n1sq)' + ones(n1,1)*n2sq -2*X'*X2;
end
K = exp(-gamma*D);
case 'sam'
if isempty(X2)
D = X'*X;
else
D = X'*X2;
end
K = exp(-gamma*acos(D).^2);
otherwise
error(['Unsupported kernel ' ker])
end
end
|
github
|
minjiang/transferlearning-master
|
MyJGSA.m
|
.m
|
transferlearning-master/code/MyJGSA.m
| 6,642 |
utf_8
|
09a8f009556a3e0b09d10483558976ec
|
function [acc,acc_list,A,B] = MyJGSA(X_src,Y_src,X_tar,Y_tar,options)
%% Joint Geometrical and Statistic Adaptation
% Inputs:
%%% X_src :source feature matrix, ns * m
%%% Y_src :source label vector, ns * 1
%%% X_tar :target feature matrix, nt * m
%%% Y_tar :target label vector, nt * 1
%%% options:option struct
% Outputs:
%%% acc :final accuracy using knn, float
%%% acc_list:list of all accuracies during iterations
%%% A :final adaptation matrix for source domain, m * dim
%%% B :final adaptation matrix for target domain, m * dim
alpha = options.alpha;
mu = options.mu;
beta = options.beta;
gamma = options.gamma;
kernel_type = options.kernel_type;
dim = options.dim;
T = options.T;
X_src = X_src';
X_tar = X_tar';
m = size(X_src,1);
ns = size(X_src,2);
nt = size(X_tar,2);
class_set = unique(Y_src);
C = length(class_set);
acc_list = [];
Y_tar_pseudo = [];
if strcmp(kernel_type,'primal')
[Sw, Sb] = scatter_matrix(X_src',Y_src);
P = zeros(2 * m,2 * m);
P(1:m,1:m) = Sb;
Q = Sw;
for t = 1 : T
[Ms,Mt,Mst,Mts] = construct_mmd(ns,nt,Y_src,Y_tar_pseudo,C);
Ts = X_src * Ms * X_src';
Tt = X_tar * Mt * X_tar';
Tst = X_src * Mst * X_tar';
Tts = X_tar * Mts * X_src';
Ht = eye(nt) - 1 / nt * ones(nt,nt);
X = [zeros(m,ns),zeros(m,nt);zeros(m,ns),X_tar];
H = [zeros(ns,ns),zeros(ns,nt);zeros(nt,ns),Ht];
Smax = mu * X * H * X' + beta * P;
Smin = [Ts+alpha*eye(m)+beta*Q, Tst-alpha*eye(m) ; ...
Tts-alpha*eye(m), Tt+(alpha+mu)*eye(m)];
mm = 1e-9*eye(2*m);
[W,~] = eigs(Smax,Smin + mm,dim,'LM');
As = W(1:m,:);
At = W(m+1:end,:);
Zs = (As' * X_src)';
Zt = (At' * X_tar)';
if T > 1
knn_model = fitcknn(Zs,Y_src,'NumNeighbors',1);
Y_tar_pseudo = knn_model.predict(Zt);
acc = length(find(Y_tar_pseudo == Y_tar)) / length(Y_tar);
fprintf('acc of iter %d: %0.4f\n',t, acc);
acc_list = [acc_list;acc];
end
end
else
Xst = [X_src,X_tar];
nst = size(Xst,2);
[Ks, Kt, Kst] = constructKernel(X_src,X_tar,kernel_type,gamma);
[Sw, Sb] = scatter_matrix(Ks,Y_src);
P = zeros(2 * nst,2 * nst);
P(1:nst,1:nst) = Sb;
Q = Sw;
for t = 1:T
% Construct MMD matrix
[Ms, Mt, Mst, Mts] = construct_mmd(ns,nt,Y_src,Y_tar_pseudo,C);
Ts = Ks'*Ms*Ks;
Tt = Kt'*Mt*Kt;
Tst = Ks'*Mst*Kt;
Tts = Kt'*Mts*Ks;
K = [zeros(ns,nst), zeros(ns,nst); zeros(nt,nst), Kt];
Smax = mu*K'*K+beta*P;
Smin = [Ts+alpha*Kst+beta*Q, Tst-alpha*Kst;...
Tts-alpha*Kst, Tt+mu*Kst+alpha*Kst];
[W,~] = eigs(Smax, Smin+1e-9*eye(2*nst), dim, 'LM');
W = real(W);
As = W(1:nst, :);
At = W(nst+1:end, :);
Zs = (As'*Ks')';
Zt = (At'*Kt')';
if T > 1
knn_model = fitcknn(Zs,Y_src,'NumNeighbors',1);
Y_tar_pseudo = knn_model.predict(Zt);
acc = length(find(Y_tar_pseudo == Y_tar)) / length(Y_tar);
fprintf('acc of iter %d: %0.4f\n',t, full(acc));
acc_list = [acc_list;acc];
end
end
end
A = As;
B = At;
end
function [Sw,Sb] = scatter_matrix(X,Y)
%% Within and between class Scatter matrix
%% Inputs:
%%% X: data matrix, length * dim
%%% Y: label vector, length * 1
% Outputs:
%%% Sw: With-in class matrix, dim * dim
%%% Sb: Between class matrix, dim * dim
X = X';
dim = size(X,1);
class_set = unique(Y);
C = length(class_set);
mean_total = mean(X,2);
Sw = zeros(dim,dim);
Sb = zeros(dim,dim);
for i = 1 : C
Xi = X(:,Y == class_set(i));
mean_class_i = mean(Xi,2);
Hi = eye(size(Xi,2)) - 1/(size(Xi,2)) * ones(size(Xi,2),size(Xi,2));
Sw = Sw + Xi * Hi * Xi';
Sb = Sb + size(Xi,2) * (mean_class_i - mean_total) * (mean_class_i - mean_total)';
end
end
function [Ms,Mt,Mst,Mts] = construct_mmd(ns,nt,Y_src,Y_tar_pseudo,C)
es = 1 / ns * ones(ns,1);
et = -1 / nt * ones(nt,1);
e = [es;et];
M = e * e' * C;
Ms = es * es' * C;
Mt = et * et' * C;
Mst = es * et' * C;
Mts = et * es' * C;
if ~isempty(Y_tar_pseudo) && length(Y_tar_pseudo) == nt
for c = reshape(unique(Y_src),1,C)
es = zeros(ns,1);
et = zeros(nt,1);
es(Y_src == c) = 1 / length(find(Y_src == c));
et(Y_tar_pseudo == c) = -1 / length(find(Y_tar_pseudo == c));
es(isinf(es)) = 0;
et(isinf(et)) = 0;
Ms = Ms + es * es';
Mt = Mt + et * et';
Mst = Mst + es * et';
Mts = Mts + et * es';
end
end
Ms = Ms / norm(M,'fro');
Mt = Mt / norm(M,'fro');
Mst = Mst / norm(M,'fro');
Mts = Mts / norm(M,'fro');
end
function [Ks, Kt, Kst] = constructKernel(Xs,Xt,ker,gamma)
Xst = [Xs, Xt];
ns = size(Xs,2);
nt = size(Xt,2);
nst = size(Xst,2);
Kst0 = km_kernel(Xst',Xst',ker,gamma);
Ks0 = km_kernel(Xs',Xst',ker,gamma);
Kt0 = km_kernel(Xt',Xst',ker,gamma);
oneNst = ones(nst,nst)/nst;
oneN=ones(ns,nst)/nst;
oneMtrN=ones(nt,nst)/nst;
Ks=Ks0-oneN*Kst0-Ks0*oneNst+oneN*Kst0*oneNst;
Kt=Kt0-oneMtrN*Kst0-Kt0*oneNst+oneMtrN*Kst0*oneNst;
Kst=Kst0-oneNst*Kst0-Kst0*oneNst+oneNst*Kst0*oneNst;
end
function K = km_kernel(X1,X2,ktype,kpar)
% KM_KERNEL calculates the kernel matrix between two data sets.
% Input: - X1, X2: data matrices in row format (data as rows)
% - ktype: string representing kernel type
% - kpar: vector containing the kernel parameters
% Output: - K: kernel matrix
% USAGE: K = km_kernel(X1,X2,ktype,kpar)
%
% Author: Steven Van Vaerenbergh (steven *at* gtas.dicom.unican.es), 2012.
%
% This file is part of the Kernel Methods Toolbox for MATLAB.
% https://github.com/steven2358/kmbox
switch ktype
case 'gauss' % Gaussian kernel
sgm = kpar; % kernel width
dim1 = size(X1,1);
dim2 = size(X2,1);
norms1 = sum(X1.^2,2);
norms2 = sum(X2.^2,2);
mat1 = repmat(norms1,1,dim2);
mat2 = repmat(norms2',dim1,1);
distmat = mat1 + mat2 - 2*X1*X2'; % full distance matrix
sgm = sgm / mean(mean(distmat)); % added by jing 24/09/2016, median-distance
K = exp(-distmat/(2*sgm^2));
case 'gauss-diag' % only diagonal of Gaussian kernel
sgm = kpar; % kernel width
K = exp(-sum((X1-X2).^2,2)/(2*sgm^2));
case 'poly' % polynomial kernel
% p = kpar(1); % polynome order
% c = kpar(2); % additive constant
p = kpar; % jing
c = 1; % jing
K = (X1*X2' + c).^p;
case 'linear' % linear kernel
K = X1*X2';
otherwise % default case
error ('unknown kernel type')
end
end
|
github
|
minjiang/transferlearning-master
|
MyJDA.m
|
.m
|
transferlearning-master/code/MyJDA.m
| 4,118 |
utf_8
|
54f4173e19b0dbf7b2572a964a6a3277
|
function [acc,acc_ite,A] = MyJDA(X_src,Y_src,X_tar,Y_tar,options)
% Inputs:
%%% X_src :source feature matrix, ns * m
%%% Y_src :source label vector, ns * 1
%%% X_tar :target feature matrix, nt * m
%%% Y_tar :target label vector, nt * 1
%%% options:option struct
% Outputs:
%%% acc :final accuracy using knn, float
%%% acc_ite:list of all accuracies during iterations
%%% A :final adaptation matrix, (ns + nt) * (ns + nt)
%% Set options
lambda = options.lambda; %% lambda for the regularization
dim = options.dim; %% dim is the dimension after adaptation, dim <= m
kernel_type = options.kernel_type; %% kernel_type is the kernel name, primal|linear|rbf
gamma = options.gamma; %% gamma is the bandwidth of rbf kernel
T = options.T; %% iteration number
acc_ite = [];
Y_tar_pseudo = [];
%% Iteration
for i = 1 : T
[Z,A] = JDA_core(X_src,Y_src,X_tar,Y_tar_pseudo,options);
%normalization for better classification performance
Z = Z*diag(sparse(1./sqrt(sum(Z.^2))));
Zs = Z(:,1:size(X_src,1));
Zt = Z(:,size(X_src,1)+1:end);
knn_model = fitcknn(Zs',Y_src,'NumNeighbors',1);
Y_tar_pseudo = knn_model.predict(Zt');
acc = length(find(Y_tar_pseudo==Y_tar))/length(Y_tar);
fprintf('JDA+NN=%0.4f\n',acc);
acc_ite = [acc_ite;acc];
end
end
function [Z,A] = JDA_core(X_src,Y_src,X_tar,Y_tar_pseudo,options)
%% Set options
lambda = options.lambda; %% lambda for the regularization
dim = options.dim; %% dim is the dimension after adaptation, dim <= m
kernel_type = options.kernel_type; %% kernel_type is the kernel name, primal|linear|rbf
gamma = options.gamma; %% gamma is the bandwidth of rbf kernel
%% Construct MMD matrix
X = [X_src',X_tar'];
X = X*diag(sparse(1./sqrt(sum(X.^2))));
[m,n] = size(X);
ns = size(X_src,1);
nt = size(X_tar,1);
e = [1/ns*ones(ns,1);-1/nt*ones(nt,1)];
C = length(unique(Y_src));
%%% M0
M = e * e' * C; %multiply C for better normalization
%%% Mc
N = 0;
if ~isempty(Y_tar_pseudo) && length(Y_tar_pseudo)==nt
for c = reshape(unique(Y_src),1,C)
e = zeros(n,1);
e(Y_src==c) = 1 / length(find(Y_src==c));
e(ns+find(Y_tar_pseudo==c)) = -1 / length(find(Y_tar_pseudo==c));
e(isinf(e)) = 0;
N = N + e*e';
end
end
M = M + N;
M = M / norm(M,'fro');
%% Centering matrix H
H = eye(n) - 1/n * ones(n,n);
%% Calculation
if strcmp(kernel_type,'primal')
[A,~] = eigs(X*M*X'+lambda*eye(m),X*H*X',dim,'SM');
Z = A'*X;
else
K = kernel_jda(kernel_type,X,[],gamma);
[A,~] = eigs(K*M*K'+lambda*eye(n),K*H*K',dim,'SM');
Z = A'*K;
end
end
% With Fast Computation of the RBF kernel matrix
% To speed up the computation, we exploit a decomposition of the Euclidean distance (norm)
%
% Inputs:
% ker: 'linear','rbf','sam'
% X: data matrix (features * samples)
% gamma: bandwidth of the RBF/SAM kernel
% Output:
% K: kernel matrix
%
% Gustavo Camps-Valls
% 2006(c)
% Jordi ([email protected]), 2007
% 2007-11: if/then -> switch, and fixed RBF kernel
% Modified by Mingsheng Long
% 2013(c)
% Mingsheng Long ([email protected]), 2013
function K = kernel_jda(ker,X,X2,gamma)
switch ker
case 'linear'
if isempty(X2)
K = X'*X;
else
K = X'*X2;
end
case 'rbf'
n1sq = sum(X.^2,1);
n1 = size(X,2);
if isempty(X2)
D = (ones(n1,1)*n1sq)' + ones(n1,1)*n1sq -2*X'*X;
else
n2sq = sum(X2.^2,1);
n2 = size(X2,2);
D = (ones(n2,1)*n1sq)' + ones(n1,1)*n2sq -2*X'*X2;
end
K = exp(-gamma*D);
case 'sam'
if isempty(X2)
D = X'*X;
else
D = X'*X2;
end
K = exp(-gamma*acos(D).^2);
otherwise
error(['Unsupported kernel ' ker])
end
end
|
github
|
minjiang/transferlearning-master
|
MyGFK.m
|
.m
|
transferlearning-master/code/MyGFK.m
| 2,152 |
utf_8
|
a01af2b801cc7b96695684ce8e803547
|
function [acc,G] = MyGFK(X_src,Y_src,X_tar,Y_tar,dim)
% Inputs:
%%% X_src :source feature matrix, ns * m
%%% Y_src :source label vector, ns * 1
%%% X_tar :target feature matrix, nt * m
%%% Y_tar :target label vector, nt * 1
% Outputs:
%%% acc :accuracy after GFK and 1NN
%%% G :geodesic flow kernel matrix
Ps = pca(X_src);
Pt = pca(X_tar);
G = GFK_core([Ps,null(Ps')], Pt(:,1:dim));
[~, acc] = my_kernel_knn(G, X_src, Y_src, X_tar, Y_tar);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [prediction,accuracy] = my_kernel_knn(M, Xr, Yr, Xt, Yt)
dist = repmat(diag(Xr*M*Xr'),1,length(Yt)) ...
+ repmat(diag(Xt*M*Xt')',length(Yr),1)...
- 2*Xr*M*Xt';
[~, minIDX] = min(dist);
prediction = Yr(minIDX);
accuracy = sum( prediction==Yt ) / length(Yt);
end
function G = GFK_core(Q,Pt)
% Input: Q = [Ps, null(Ps')], where Ps is the source subspace, column-wise orthonormal
% Pt: target subsapce, column-wise orthonormal, D-by-d, d < 0.5*D
% Output: G = \int_{0}^1 \Phi(t)\Phi(t)' dt
% ref: Geodesic Flow Kernel for Unsupervised Domain Adaptation.
% B. Gong, Y. Shi, F. Sha, and K. Grauman.
% Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Providence, RI, June 2012.
% Contact: Boqing Gong ([email protected])
N = size(Q,2); %
dim = size(Pt,2);
% compute the principal angles
QPt = Q' * Pt;
[V1,V2,V,Gam,Sig] = gsvd(QPt(1:dim,:), QPt(dim+1:end,:));
V2 = -V2;
theta = real(acos(diag(Gam))); % theta is real in theory. Imaginary part is due to the computation issue.
% compute the geodesic flow kernel
eps = 1e-20;
B1 = 0.5.*diag(1+sin(2*theta)./2./max(theta,eps));
B2 = 0.5.*diag((-1+cos(2*theta))./2./max(theta,eps));
B3 = B2;
B4 = 0.5.*diag(1-sin(2*theta)./2./max(theta,eps));
G = Q * [V1, zeros(dim,N-dim); zeros(N-dim,dim), V2] ...
* [B1,B2,zeros(dim,N-2*dim);B3,B4,zeros(dim,N-2*dim);zeros(N-2*dim,N)]...
* [V1, zeros(dim,N-dim); zeros(N-dim,dim), V2]' * Q';
end
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.