Skip to content

Commit acd7212

Browse files
committed
Functions comment edited to conform to FileExchange style.
1 parent 43a63bf commit acd7212

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+13489
-11213
lines changed

README.md

+36-36
Large diffs are not rendered by default.

core/A_to_f.m

+30-31
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
1-
%% A_to_f
2-
% Calculates A(f), A in the frequency domain.
1+
function AL = A_to_f(A, nf)
2+
%A_to_f Calculates A(f), A in the frequency domain.
33
%
4-
%% Syntax:
4+
% Syntax:
55
% AL = A_to_f(A, nf)
66
%
7-
%% Input arguments:
7+
% Input arguments:
88
% A - (nChannels x nChannels x p) Recurrence matrix,
99
% where nChannels is the number of signals, and p the model
1010
% order.
1111
% nf - frequency resolution
1212
%
13-
%% Output argument:
13+
% Output argument:
1414
% AL - (nf, nChannels, nChannels) A(f)
1515

1616
% (C) Koichi Sameshima & Luiz A. Baccalá, 2022.
1717
% See file license.txt in installation directory for licensing terms.
1818

19-
function AL = A_to_f(A, nf)
2019

21-
[nChannels, ~, p] = size(A); % Dummy variable ~ is equivalent to nChannels
22-
Jimag = sqrt(-1);
20+
[nChannels, ~, p] = size(A); % Dummy variable ~ is equivalent to nChannels
21+
Jimag = sqrt(-1);
2322

24-
% Variable 'exponents' is an array of FFT exponents, on all frequency range for
25-
% each lag.
26-
exponents = reshape((-Jimag*pi*kron(0:(nf-1),(1:p))/nf),p,nf).';
23+
% Variable 'exponents' is an array of FFT exponents, on all frequency
24+
% range for each lag.
25+
exponents = reshape((-Jimag*pi*kron(0:(nf-1),(1:p))/nf),p,nf).';
2726

28-
% Af multiplies the exp(ar) by the matrix A, for all frequencies, the reshape
29-
% and transpose functions are tricks to make the vector calculation possible.
27+
% Af multiplies the exp(ar) by the matrix A, for all frequencies, the reshape
28+
% and transpose functions are tricks to make the vector calculation possible.
3029

31-
Areshaped = reshape(A, nChannels,nChannels,1,p);
30+
Areshaped = reshape(A, nChannels,nChannels,1,p);
3231

33-
Af = zeros(nChannels,nChannels,nf,p);
34-
for kk = 1:nf
35-
Af(:,:,kk,:) = Areshaped;
36-
end
32+
Af = zeros(nChannels,nChannels,nf,p);
33+
for kk = 1:nf
34+
Af(:,:,kk,:) = Areshaped;
35+
end
3736

38-
for i = 1:nChannels
39-
for k = 1:nChannels
40-
Af(i,k,:,:) = reshape(Af(i,k,:,:),nf,p).*exp(exponents);
37+
for i = 1:nChannels
38+
for k = 1:nChannels
39+
Af(i,k,:,:) = reshape(Af(i,k,:,:),nf,p).*exp(exponents);
40+
end
4141
end
42-
end
4342

44-
Af = permute(Af, [3,1,2,4]);
43+
Af = permute(Af, [3,1,2,4]);
4544

46-
AL=zeros(nf,nChannels,nChannels);
45+
AL=zeros(nf,nChannels,nChannels);
4746

48-
for kk = 1:nf
49-
temp = zeros(nChannels,nChannels);
50-
for k = 1:p
51-
temp = temp+reshape(Af(kk,:,:,k),nChannels,nChannels);
47+
for kk = 1:nf
48+
temp = zeros(nChannels,nChannels);
49+
for k = 1:p
50+
temp = temp+reshape(Af(kk,:,:,k),nChannels,nChannels);
51+
end
52+
temp = eye(nChannels)-temp;
53+
AL(kk,:,:) = reshape(temp,1,nChannels,nChannels);
5254
end
53-
temp = eye(nChannels)-temp;
54-
AL(kk,:,:) = reshape(temp,1,nChannels,nChannels);
55-
end

core/arfitcaps.m

+38-40
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
%% ARFITCAPS
2-
% Capsule function to call the arfit.m routine, part of
3-
% "ARfit: Multivariate Autoregressive Model Fitting" package.
1+
function [pf,A,ef] = arfitcaps(u,IP)
2+
%ARFITCAPS Capsule function to call the arfit.m routine, part of
3+
% "ARfit: Multivariate Autoregressive Model Fitting" package.
44
%
5-
%% Syntax:
5+
% Syntax:
66
% [pf,A,ef] = ARFITCAPS(u,IP)
77
%
8-
%% Input Arguments
8+
% Input Arguments:
99
% u: time series
1010
% IP: VAR model order
1111
%
12-
%% Output Arguments
12+
% Output Arguments:
1313
% pf: covariance matrix provided by ARFIT routine
1414
% A: AR estimate matrix provided by ARFIT routine
1515
% ef: forward residuals provided by ARRES routine
1616
%
17-
%% Description:
18-
% ARFITCAPS is capsule that calls arfit.m and arres.m routines, part of
19-
% Autoregressive Model Fitting" package, which implements algorithms
20-
% as described in the following articles:
17+
% Description:
18+
% ARFITCAPS is capsule that calls arfit.m and arres.m routines, part of
19+
% Autoregressive Model Fitting" package, which implements algorithms
20+
% as described in the following articles:
2121
%
2222
% [1] Neumaier A & Schneider T, 2001. Estimation of parameters and
2323
% eigenmodes of multivariate autoregressive models. ACM Trans Math
@@ -33,10 +33,11 @@
3333
% not tested)
3434
% https://www.mathworks.com/matlabcentral/fileexchange/174-arfit,
3535
%
36-
% and, before using it, verify the license terms, it seems to be a copyrighted
36+
% and, before using it, verify the license terms. It seems to be a copyrighted
3737
% material by the Association for Computing Machinery, Inc.
3838
%
39-
%% Note: As described by the authors, acf.m in ARfit needs Signal Processing
39+
% Notes:
40+
% As described by the authors, acf.m in ARfit needs Signal Processing
4041
% Toolbox (TM), as it requires XCORR, a cross-correlation function estimator.
4142
%
4243
% ARfit availability was checked on August 13, 2015, and August 27, 2021. KS
@@ -45,40 +46,37 @@
4546
% www.gps.caltech.edu/~tapio/arfit/index.html,
4647
% which is now obsolete.
4748
%
48-
%% See also: ARFIT, MVAR, MCARNS, MCARVM, CMLSM
49+
% See also: ARFIT, MVAR, MCARNS, MCARVM, CMLSM
4950

5051
% (C) Koichi Sameshima & Luiz A. Baccalá, 2022.
5152
% See file license.txt in installation directory for licensing terms.
5253

53-
%%
54-
55-
function [pf,A,ef] = arfitcaps(u,IP)
56-
57-
if ~exist('arfit.m','file')
58-
help arfitcaps
59-
error('ARfit.m not found. Get the ARfit package from Tapio Schneider''s web site.')
60-
end;
54+
% Check for the existence of ARfit Package
55+
if ~exist('arfit.m','file')
56+
help arfitcaps
57+
error('ARfit.m not found. Get the ARfit package from Tapio Schneider''s web site.')
58+
end;
6159

62-
v = u';
63-
[w, Au, C, sbc, fpe, th] = arfit(v,IP,IP);
64-
pf = C;
60+
v = u';
61+
[w, Au, C, sbc, fpe, th] = arfit(v,IP,IP);
62+
pf = C;
6563

66-
if IP >= 20
67-
[siglev,res] = arres(w,Au,v,IP+1);
68-
else
69-
[siglev,res] = arres(w,Au,v);
70-
end;
64+
if IP >= 20
65+
[siglev,res] = arres(w,Au,v,IP+1);
66+
else
67+
[siglev,res] = arres(w,Au,v);
68+
end;
7169

72-
% Variable 'siglev' is not used.
70+
% Variable 'siglev' is not used.
7371

74-
ef = res';
75-
A = zeros(length(w),length(w),IP);
76-
for i = 1:IP
77-
A(:,:,i) = Au(:,(i-1)*length(w)+1:i*length(w));
78-
wu = ceil(length(ef)*rand(size(w)));
79-
if length(ef)<length(v)
80-
ef = [ef ef(:,wu(1))];
81-
else
82-
ef = ef(:,1:length(v));
72+
ef = res';
73+
A = zeros(length(w),length(w),IP);
74+
for i = 1:IP
75+
A(:,:,i) = Au(:,(i-1)*length(w)+1:i*length(w));
76+
wu = ceil(length(ef)*rand(size(w)));
77+
if length(ef)<length(v)
78+
ef = [ef ef(:,wu(1))];
79+
else
80+
ef = ef(:,1:length(v));
81+
end
8382
end
84-
end

core/asymp_dtf.m

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
%% ASYMP_DTF
2-
% Compute DTF connectivity measures magnitude, from series j-->i, for
3-
% any of three of metrics --- Euclidean, diagonal and information ---
4-
% as well as asymptotic statistics from vector autoregressive (VAR)
5-
% coefficients in the frequency domain.
1+
function c = asymp_dtf(u,A,pf,nFreqs,metric,alpha)
2+
%ASYMP_DTF Compute DTF connectivity measures magnitude, from series j-->i, for
3+
% any of three of metrics --- Euclidean, diagonal and information ---
4+
% as well as asymptotic statistics from vector autoregressive (VAR)
5+
% coefficients in the frequency domain.
66
%
7-
%% Syntax:
7+
% Syntax:
88
% c = ASYMP_DTF(u,A,pf,nFreqs,metric,alpha)
99
%
10-
%% Input Arguments:
10+
% Input Arguments:
1111
% u - multiple row vectors time series
1212
% A - AR estimate matrix obtained via MVAR routine
1313
% pf - covariance matrix provided via MVAR routine
@@ -18,7 +18,7 @@
1818
% alpha - significance level
1919
% if alpha is zero, statistical analysis won't be performed
2020
%
21-
%% Output Arguments:
21+
% Output Arguments:
2222
% c struct variable with following fields:
2323
% |-- .dtf - complex DTF estimates
2424
% |-- .dtf2 - |DTF|^2 estimates
@@ -37,7 +37,7 @@
3737
% or
3838
% c.{dtf,dtf2,pvalues,th,ci1,ci2,metric,alpha,p,patdenr,patdfr,SS,coh2}
3939
%
40-
%% Description:
40+
% Description:
4141
% Compute all three types of DTF --- Granger influentiability measure and
4242
% their allied statistical measures of asymptotic statistics for metric
4343
% option:
@@ -46,10 +46,10 @@
4646
% * 'diag' - Directed Coherence (DC) or gDTF (generalized);
4747
% * 'info' - information DTF.
4848
%
49-
%% Example:
49+
% Example:
5050
%
51-
% Annual sunspot numbers and the melanoma cases (10^5) in the State of
52-
% Connecticuts, USA, from 1936 to 1972, given by
51+
% Annual sunspot numbers and the melanoma cases (10^5) in the State of
52+
% Connecticuts, USA, from 1936 to 1972, given by
5353
%
5454
% u = [ 40 115 100 80 60 40 23 10 10 25 75 145 130 130 80 65 20 ...
5555
% 10 5 10 60 190 180 175 120 50 35 20 10 15 30 60 105 105 ...
@@ -87,7 +87,7 @@
8787
% xplot(c,flgPrinting,fs,fs/2,chLabels,flgColor,flgScale,flgMax, ...
8888
% flgSignifColor);
8989
%
90-
%% References:
90+
% References:
9191
% [1] M.J. Kaminski and K.J. Blinowska. A new method of the description of the
9292
% information flow in the brain structures. Biol Cybern 65:203--210,1991.
9393
% <https://doi.org/10.1007/bf00198091>
@@ -97,14 +97,11 @@
9797
% Bio-Med Eng 63:2450--2460, 2016.
9898
% <https://doi.org/10.1109/TBME.2016.2550199>
9999
%
100-
%% See also: DTF_ALG, ASYMP_PDC, MVAR, MCARNS, MCARVM, CMLSM, ARFIT
100+
% See also: DTF_ALG, ASYMP_PDC, MVAR, MCARNS, MCARVM, CMLSM, ARFIT
101101

102102
% (C) Koichi Sameshima & Luiz A. Baccalá, 2022.
103103
% See file license.txt in installation directory for licensing terms.
104104

105-
%%
106-
107-
function c = asymp_dtf(u,A,pf,nFreqs,metric,alpha)
108105

109106
if ~(nargin == 6)
110107
error('ASYMP_DTF requires six input arguments.')

0 commit comments

Comments
 (0)