-
Notifications
You must be signed in to change notification settings - Fork 3
/
lowFreqPropagationPattern.m
116 lines (100 loc) · 3.76 KB
/
lowFreqPropagationPattern.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
function [delaysMean_ms,medianCC,h,hCbar,delaysAll_ms,allCCFiltered,allCC]=lowFreqPropagationPattern(M,Fs,ch,En,varargin)
% [delaysMean_ms,medianCC,h,delaysAll_ms,allCCFiltered,allCC]=lowFreqPropagationPattern(M,Fs,ch,En,varargin)
% Function purpose : Calculated and plots cross correlation based propagation
%
% Function recives : M - activity matrix [nCh,nTrials,nSamples]
% Fs - sampling frequency
% ch - the channel numbers in M
% En - channel layout
% varargin:
% h=[];
% plotResults=1;
% plotSingleTraces=0;
% lowpassCutoff=5;
%
% Function give back : delaysMean_ms,medianCC,h,delaysAll_ms,allCCFiltered,allCC
%
% Last updated : 24/05/14
h=[];
plotResults=1;
plotSingleTraces=0;
lowpassCutoff=5;
plotColorBar=true;
markerSizeAvg=50;
markerSizeAll=15;
minMaxDelay=[];
%print out default arguments and values if no inputs are given
if nargin==0
defaultArguments=who;
for i=1:numel(defaultArguments)
eval(['defaultArgumentValue=' defaultArguments{i} ';']);
disp([defaultArguments{i} ' = ' num2str(defaultArgumentValue)]);
end
return;
end
%Collects all options
for i=1:2:length(varargin)
eval([varargin{i} '=' 'varargin{i+1};'])
end
[nCh,nTrials,nSamples]=size(M);
F=filterData;
F.samplingFrequency=Fs;
F.lowPassCutoff=lowpassCutoff;
F=F.designLowPass;
allCC=cell(1,nTrials);
delaysAll_ms=cell(1,nTrials);
allCCFiltered=zeros(nTrials,nCh,2*nSamples-1);
hCbar=[];hCBall=[];
hWB = waitbar(0,'Please wait...');
for j=1:nTrials
waitbar(j/nTrials);
%p=find(x==j);
X=zeros(nCh,1,nSamples*2-1);
mResponse=squeeze(mean(M(:,j,:),1))';
for k=1:nCh
X(k,1,:)=xcorr(M(k,j,:),mResponse,'coeff');
end
allCC{j}=X;
allCCFiltered(j,:,:)=squeeze(F.getFilteredData(X));
[~,pDelays]=max(squeeze(allCCFiltered(j,:,:))');
delaysAll_ms{j}=pDelays*(1/Fs)*1000;
delaysAll_ms{j}=delaysAll_ms{j}-mean(delaysAll_ms{j});
end
medianCC=squeeze( nanmedian(allCCFiltered,1) );
[~,pDelays]=max( medianCC ,[],2 );
delaysMean_ms=pDelays*(1/Fs)*1000;
delaysMean_ms=delaysMean_ms-mean(delaysMean_ms);
close(hWB);
if plotResults
if isempty(h)
F=figure('Position',[620 485 519 383]);
h=axes;
else
axes(h);
end
if isempty(minMaxDelay)
minMaxDelay=[median(delaysMean_ms)-3*mad(delaysMean_ms,1) median(delaysMean_ms)+3*mad(delaysMean_ms,1)];
end
[hCbar]=IntensityPhysicalSpacePlot(ch,delaysMean_ms,En,...
'plotElectrodeNumbers',0,'plotGridLines',0,'plotColorBar',1,'markerSize',markerSizeAvg,'h',h,'Ilim',minMaxDelay);
if plotSingleTraces
F=figure('Position',[36 84 1528 836]);
allDelaysArray=cell2mat(delaysAll_ms);
if isempty(minMaxDelay)
minMaxDelay=[median(allDelaysArray)-3*mad(allDelaysArray,1) median(allDelaysArray)+3*mad(allDelaysArray,1)];
end
m=12;
n=20;
for i=1:min(m*n-2,nTrials)
hAll=subaxis(12,20,i,'Spacing',0.002,'Padding',0.002,'Margin',0.002);
IntensityPhysicalSpacePlot(ch,delaysAll_ms{i},En,'plotElectrodeNumbers',0,'plotGridLines',0,'plotColorBar',0,'markerSize',markerSizeAll,'h',hAll,'Ilim',minMaxDelay);
set(h,'Box','off','Visible','off');
end
hAll=subaxis(12,20,m*n-1,'Spacing',0.002,'Padding',0.002,'Margin',0.002);
hCBall=IntensityPhysicalSpacePlot(ch,delaysAll_ms{i},En,'plotElectrodeNumbers',0,'plotGridLines',0,'plotColorBar',1,'markerSize',markerSizeAll,'h',hAll,'Ilim',minMaxDelay);
set(h,'Box','off','Visible','off');
end
if ~plotColorBar
delete([hCbar hCBall]);
end
end