OSCR

Insular routing to orbitofrontal cortex enables breathing awareness.

Code ↔ Paper

2 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 2 matches
  1. [1] § MATERIALS AND METHODS › Granger causality ↔ computeCGCvar3.m, lines 53–96 · score 0.67 · Zero padding, frequency resolution, NW, multitaper, tapers, Hz
  2. [2] § MATERIALS AND METHODS › Granger causality ↔ compute_allnpCGCvar3.m, lines 37–80 · score 0.67 · Zero padding, frequency resolution, NW, multitaper, tapers, Hz

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

MATLAB · 631 lines · 21 KB · MIT · 1 match

  1. function [M] = computeCGCvar3(X,fs,para)
  2. %Usage: [M] = computevarCGC(X,fs,para);
  3. %This routine computes conditional Granger causality (CGC),
  4. % coherence (coherence) and power (power)
  5. % given the trivariate data (var3) X in the form of time x trial x channel.
  6. % If para.p and para.freq (model order (p) and frequencies (freq)) are supplied, then it
  7. % uses the VAR parametric method. If para is empty or nargin<3, it uses the
  8. % nonparametric approach.
  9. %-------------------------------------------------------------------------------------------------
  10. %Inputs: X = trivariate data in the form of 3D matrix for time. trial. channel.
  11. % fs = data sampling rate in Hz
  12. % para.freq = frequencies at which GC is computed, eg. para.freq = 0:0.1:fs/2;
  13. % para.p = model order (e.g. 3), or
  14. %Outputs: M.freq = freq, M.gc = conditional Granger causality (i to j conditional on k),
  15. % e.g., 1 to 2 conditional on 3
  16. %M.coh = coherence, M.pow = power spectral density, M.freq = f, M.fs = fs;
  17. %-------------------------------------------------------------------------------------------------
  18. %Ref : M. Dhamala, et al. NeuroImage and PRL (2008). Written by M. Dhamala
  19. %Revised by M. Dhamala on March, 2018
  20. %-------------------------------------------------------------------------------------------------
  21. [Nt, Ntr,Nc] = size(X); %Nt = number of timepoints, Ntr = trials, Nc = channels
  22. if nargin<3
  23. para = [];
  24. end
  25. if nargin<3||isempty(para)==1 %nonparametric approach
  26. fRes = fs/Nt;
  27. [S,freq]= sig2mTspect_nv(X,fs,fRes);
  28. spectra = permute(S,[3 1 2]);coherence = S2coh(spectra);
  29. for ichan = 1: Nc
  30. power(:,ichan) = 2*spectra(:,ichan,ichan);%one-sided power
  31. end
  32. cgc = getCGC(S,fs,freq);
  33. else % parametric approach
  34. x = reshape(X,Nt*Ntr,Nc); x = x'; % x in the form of channel. (time x trials)
  35. p = para.p; freq = para.freq;
  36. [A, Z]=armorf(x,Ntr,Nt,p); %parameters by autoregressive fitting
  37. [S,H] = AZ2spectra(A,Z,p,freq,fs);
  38. spectra = permute(S,[3 1 2]);coherence = S2coh(spectra);
  39. for ichan = 1: Nc
  40. power(:,ichan) = 2*spectra(:,ichan,ichan);%one-sided power
  41. end
  42. cgc = getCGC(S,fs,freq);
  43. end
  44. M.freq = freq; M.pow = power;
  45. M.coh = coherence; M.gc=cgc;
  46. M.fs = fs;
  47. end
  48. %----------------------------------sig2mTspect_nv.m------------------------------------------
  49. function [S,f]= sig2mTspect_nv(X,fs,fRes);
  50. %Usage: [S, f] = sig2mTspect_nv(X,fs,fRes);
  51. %This function computes auto- & cross- spectra by using multitapers
  52. %Inputs: X is multichannel data (a 3D-matrix in the form of time x trial x channel)
  53. % fs = sampling rate in Hz
  54. % nv stands for 'not vectorized program'
  55. % fRes = desired (lower) frequency resolution (e.g. 1), achieved with zero-padding
  56. % default frequency resolution is fs/datalength
  57. %Outputs: S = 3D matrix: m by m spectral matrix at each frequency point of f
  58. %Note: One can change nw (half the number of tapers) below and see the effect
  59. %Written and revised by M. Dhamala
  60. [N,Ntr,m] = size(X); % N = timepoints, Ntr = trials, m = channels
  61. if nargin<3|fRes>fs/N,
  62. npad = 0; fRes = fs/N;
  63. end
  64. fRes0 = fs/N;
  65. if (nargin==3) & (fRes<=fs/N),
  66. npad = round((fs/fRes-N)/2); %These many zeros will be padded on each side of the data
  67. end
  68. f = fs*(0:fix((N+2*npad)/2))/(N+2*npad);% upto Nyquist-f
  69. nw = 2; % number of tapers = 2*nw .......good nw are 1.5, 2, 3, 4, 5, 6, or 7...
  70. [tapers,v] = dpss(N+2*npad, nw);
  71. S = zeros(m,m,N+2*npad);
  72. for itrial = 1: Ntr,
  73. for ii = 1: m, Xft(:,:,ii) = mtfft(squeeze(X(:,itrial,ii)),tapers,fs,npad); end
  74. for ii = 1:m,
  75. for jj = 1:m,
  76. s(ii,jj,:) = squeeze(mean(Xft(:,:,ii).*conj(Xft(:,:,jj)),2));
  77. %averaging over tapers
  78. end
  79. end
  80. S = S + s;
  81. end
  82. S = S/Ntr; %averaging over trials
  83. S = S(:,:,1:fix(end/2)+1)/fs;%half part of two-sided spectra
  84. S = S*fRes0/fRes;%multiplying by a factor to adjust distribution of power from zero-padding
  85. end
  86. %-------------------------------------------------------------------------------------
  87. function xf = mtfft(data,tapers,fs,npad);
  88. %Usage: xf = mtfft(data,tapers,fs,npad);
  89. %Written by M. Dhamala
  90. x0 = zeros(npad,size(data,2));
  91. data = cat(1,x0,data); data= cat(1,data,x0);
  92. data = data(:,ones(1,size(tapers,2)));
  93. data = data.*tapers;xf = fft(data,[],1);
  94. end
  95. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-------------------------------------------------------
  96. % Functions below : armorf.m, AZ2spectra.m, spectrum.m
  97. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-------------------------------------------------------
  98. %---------------------------------------------------------------------
  99. function varargout = armorf(x,ntrls,npts,p)
  100. % Script performs AR parameter estimation via LWR method by Morf modified.
  101. % X is a matrix whose every row is one variable's time series
  102. % ntrls is the number of realizations, npts is the length of every realization
  103. % If the time series are stationary long, just let ntrls=1, npts=length(x)
  104. %
  105. % A = ARMORF(X,NR,NL,ORDER) returns the polynomial coefficients A corresponding to
  106. % the AR model estimate of matrix X using Morf's method.
  107. % ORDER is the order of the AR model.
  108. %
  109. % [A,E] = ARMORF(...) returns the final prediction error E (the variance
  110. % estimate of the white noise input to the AR model).
  111. %
  112. % [A,E,K] = ARMORF(...) returns the vector K of reflection coefficients (parcor coefficients).
  113. %
  114. % Ref: M. Morf, etal, Recursive Multichannel Maximum Entropy Spectral Estimation,
  115. % IEEE trans. GeoSci. Elec., 1978, Vol.GE-16, No.2, pp85-94.
  116. % S. Haykin, Nonlinear Methods of Spectral Analysis, 2nd Ed.
  117. % Springer-Verlag, 1983, Chapter 2
  118. %
  119. % finished on Aug.9, 2002 by Yonghong Chen
  120. % bug fixes and revised on April, 2005 by Rajasimhan
  121. % Initialization
  122. [L,N]=size(x);
  123. R0=zeros(L,L);
  124. R0f=R0;
  125. R0b=R0;
  126. pf=R0;
  127. pb=R0;
  128. pfb=R0;
  129. ap(:,:,1)=R0;
  130. bp(:,:,1)=R0;
  131. En=R0;
  132. for i=1:ntrls
  133. En=En+x(:,(i-1)*npts+1:i*npts)*x(:,(i-1)*npts+1:i*npts)';
  134. ap(:,:,1)=ap(:,:,1)+x(:,(i-1)*npts+2:i*npts)*x(:,(i-1)*npts+2:i*npts)';
  135. bp(:,:,1)=bp(:,:,1)+x(:,(i-1)*npts+1:i*npts-1)*x(:,(i-1)*npts+1:i*npts-1)';
  136. end
  137. ap(:,:,1) = inv((chol(ap(:,:,1)/ntrls*(npts-1)))');
  138. bp(:,:,1) = inv((chol(bp(:,:,1)/ntrls*(npts-1)))');
  139. for i=1:ntrls
  140. efp = ap(:,:,1)*x(:,(i-1)*npts+2:i*npts);
  141. ebp = bp(:,:,1)*x(:,(i-1)*npts+1:i*npts-1);
  142. pf = pf + efp*efp';
  143. pb = pb + ebp*ebp';
  144. pfb = pfb + efp*ebp';
  145. end
  146. En = chol(En/N)'; % Covariance of the noise
  147. % Initial output variables
  148. coeff = [];% Coefficient matrices of the AR model
  149. kr=[]; % reflection coefficients
  150. for m=1:p
  151. % Calculate the next order reflection (parcor) coefficient
  152. ck = inv((chol(pf))')*pfb*inv(chol(pb));
  153. kr=[kr,ck];
  154. % Update the forward and backward prediction errors
  155. ef = eye(L)- ck*ck';
  156. eb = eye(L)- ck'*ck;
  157. % Update the prediction error
  158. En = En*chol(ef)';
  159. E = (ef+eb)./2;
  160. % Update the coefficients of the forward and backward prediction errors
  161. ap(:,:,m+1) = zeros(L);
  162. bp(:,:,m+1) = zeros(L);
  163. pf = zeros(L);
  164. pb = zeros(L);
  165. pfb = zeros(L);
  166. for i=1:m+1
  167. a(:,:,i) = inv((chol(ef))')*(ap(:,:,i)-ck*bp(:,:,m+2-i));
  168. b(:,:,i) = inv((chol(eb))')*(bp(:,:,i)-ck'*ap(:,:,m+2-i));
  169. end
  170. for k=1:ntrls
  171. efp = zeros(L,npts-m-1);
  172. ebp = zeros(L,npts-m-1);
  173. for i=1:m+1
  174. k1=m+2-i+(k-1)*npts+1;
  175. k2=npts-i+1+(k-1)*npts;
  176. efp = efp+a(:,:,i)*x(:,k1:k2);
  177. ebp = ebp+b(:,:,m+2-i)*x(:,k1-1:k2-1);
  178. end
  179. pf = pf + efp*efp';
  180. pb = pb + ebp*ebp';
  181. pfb = pfb + efp*ebp';
  182. end
  183. ap = a;
  184. bp = b;
  185. end
  186. for j=1:p
  187. coeff = [coeff,inv(a(:,:,1))*a(:,:,j+1)];
  188. end
  189. varargout{1} = coeff;
  190. if nargout >= 2
  191. varargout{2} = En*En';
  192. end
  193. if nargout >= 3
  194. varargout{3} = kr;
  195. end
  196. end
  197. %-------------------------------armorf.m-------------------------------------------------------
  198. function varargout = armorf0(x,Nr,Nl,p);
  199. %ARMORF AR parameter estimation via LWR method by Morf modified.
  200. % x is a matrix whose every row is one variable's time series
  201. % Nr is the number of realizations, Nl is the length of every realization
  202. % If the time series are stationary long, just let Nr=1, Nl=length(x)
  203. % p is the order of AR model
  204. %
  205. % A = ARMORF(X,NR,NL,P) returns the polynomial coefficients A corresponding to
  206. % the AR model estimate of matrix X using Morf's method.
  207. %
  208. % [A,E] = ARMORF(...) returns the final prediction error E (the
  209. % covariance matrix of the white noise of the AR model).
  210. %
  211. % [A,E,K] = ARMORF(...) returns the vector K of reflection
  212. % coefficients (parcor coefficients).
  213. %
  214. % Ref: M. Morf, etal, Recursive Multichannel Maximum Entropy Spectral Estimation,
  215. % IEEE trans. GeoSci. Elec., 1978, Vol.GE-16, No.2, pp85-94.
  216. % S. Haykin, Nonlinear Methods of Spectral Analysis, 2nd Ed.
  217. % Springer-Verlag, 1983, Chapter 2
  218. % Initialization
  219. [L,N]=size(x);
  220. R0=zeros(L,L);
  221. R0f=R0;
  222. R0b=R0;
  223. pf=R0;
  224. pb=R0;
  225. pfb=R0;
  226. ap(:,:,1)=R0;
  227. bp(:,:,1)=R0;
  228. En=R0;
  229. for i=1:Nr
  230. En=En+x(:,(i-1)*Nl+1:i*Nl)*x(:,(i-1)*Nl+1:i*Nl)';
  231. ap(:,:,1)=ap(:,:,1)+x(:,(i-1)*Nl+2:i*Nl)*x(:,(i-1)*Nl+2:i*Nl)';
  232. bp(:,:,1)=bp(:,:,1)+x(:,(i-1)*Nl+1:i*Nl-1)*x(:,(i-1)*Nl+1:i*Nl-1)';
  233. end
  234. ap(:,:,1) = inv((chol(ap(:,:,1)/Nr*(Nl-1)))');
  235. bp(:,:,1) = inv((chol(bp(:,:,1)/Nr*(Nl-1)))');
  236. for i=1:Nr
  237. efp = ap(:,:,1)*x(:,(i-1)*Nl+2:i*Nl);
  238. ebp = bp(:,:,1)*x(:,(i-1)*Nl+1:i*Nl-1);
  239. pf = pf + efp*efp';
  240. pb = pb + ebp*ebp';
  241. pfb = pfb + efp*ebp';
  242. end
  243. En = chol(En/N)'; % Covariance of the noise
  244. % Initial output variables
  245. coeff = [];% Coefficient matrices of the AR model
  246. kr=[]; % reflection coefficients
  247. for m=1:p
  248. % Calculate the next order reflection (parcor) coefficient
  249. ck = inv((chol(pf))')*pfb*inv(chol(pb));
  250. kr=[kr,ck];
  251. % Update the forward and backward prediction errors
  252. ef = eye(L)- ck*ck';
  253. eb = eye(L)- ck'*ck;
  254. % Update the prediction error
  255. En = En*chol(ef)';
  256. E = (ef+eb)./2;
  257. % Update the coefficients of the forward and backward prediction errors
  258. ap(:,:,m+1) = zeros(L);
  259. bp(:,:,m+1) = zeros(L);
  260. pf = zeros(L);
  261. pb = zeros(L);
  262. pfb = zeros(L);
  263. for i=1:m+1
  264. a(:,:,i) = inv((chol(ef))')*(ap(:,:,i)-ck*bp(:,:,m+2-i));
  265. b(:,:,i) = inv((chol(eb))')*(bp(:,:,i)-ck'*ap(:,:,m+2-i));
  266. end
  267. for k=1:Nr
  268. efp = zeros(L,Nl-m-1);
  269. ebp = zeros(L,Nl-m-1);
  270. for i=1:m+1
  271. k1=m+2-i+(k-1)*Nl+1;
  272. k2=Nl-i+1+(k-1)*Nl;
  273. efp = efp+a(:,:,i)*x(:,k1:k2);
  274. ebp = ebp+b(:,:,m+2-i)*x(:,k1-1:k2-1);
  275. end
  276. pf = pf + efp*efp';
  277. pb = pb + ebp*ebp';
  278. pfb = pfb + efp*ebp';
  279. end
  280. ap = a;
  281. bp = b;
  282. end
  283. for j=1:p
  284. coeff = [coeff,inv(a(:,:,1))*a(:,:,j+1)];
  285. end
  286. varargout{1} = coeff;
  287. if nargout >= 2
  288. varargout{2} = En*En';
  289. end
  290. if nargout >= 3
  291. varargout{3} = kr;
  292. end
  293. end
  294. %----------------------------- AZ2spectra.m --------------------------------
  295. function [S,H] = AZ2spectra(A,Z,p,freq,fs);
  296. f_ind = 0;
  297. for f = freq,
  298. f_ind = f_ind+1;
  299. [Stmp,Htmp] = spectrum(A,Z,p,f,fs);
  300. H(:,:,f_ind) = Htmp;
  301. S(:,:,f_ind) = Stmp; %auto-& cross-spectra
  302. end
  303. for ind = 1:size(Z,1),
  304. S(ind,ind,:) = real(S(ind,ind,:)); %avoiding numerical errors
  305. end
  306. end
  307. %------------------------------spectrum.m-----------------------------------
  308. function [S,H] = spectrum(A,Z,M,f,fs);
  309. % Get the coherence spectrum
  310. N = size(Z,1);
  311. H = eye(N,N); % identity matrix
  312. for m = 1 : M
  313. H = H + A(:,(m-1)*N+1:m*N)*exp(-i*m*2*pi*f/fs);
  314. % Multiply f in the exponent by sampling interval (=1/fs). See Shiavi
  315. end
  316. H = inv(H);
  317. S = H*Z*H'/fs;
  318. % One has to multiply HZH' by sampling interval (=1/fs)
  319. %to get the properly normalized spectral density. See Shiavi.
  320. %To get 1-sided power spectrum, multiply S by 2.
  321. end
  322. %%%%%%%%%-------------------------S2coh.m ------------------------
  323. function coh = S2coh(S);
  324. %Input: S auto-& cross pectra in the form: frequency. channel. channel
  325. %Output: coh (Coherence) in the form: frequency. channel. channel
  326. %Written by M. Dhamala
  327. Nc = size(S,2);
  328. for ii = 1: Nc,
  329. for jj = 1: Nc,
  330. coh(:,ii,jj) = real(abs(S(:,ii,jj)).^2./(S(:,ii,ii).*S(:,jj,jj)));
  331. end
  332. end
  333. end
  334. %----------------------- compute CGC given the spectra----------------------
  335. function causality = getCGC(S,fs,freq);
  336. %Input: S auto-& cross pectra in the form: frequency. channel. channel
  337. %Output: causality in the form: frequency. channel. channel
  338. %Written and revised by M. Dhamala
  339. [H0, SIGMA0] = wilson_sf(S, fs); Nc = size(S,1);
  340. for y = 1:Nc
  341. y_omit = [1:y-1 y+1:Nc];
  342. [tmpHred0, tmpSIGMAred0] = wilson_sf(S(y_omit,y_omit,:), fs);
  343. Hred0 = zeros(Nc,Nc,length(freq));
  344. SIGMAred0 = zeros(Nc,Nc);
  345. Hred0(y_omit,y_omit,:) = tmpHred0;
  346. SIGMAred0(y_omit,y_omit) = tmpSIGMAred0;
  347. for x = 1:Nc
  348. if x~=y
  349. z = 1:Nc;
  350. z([x y]) = [];
  351. %-- FULL model ----------------
  352. xyz = [x y z];
  353. SIGMA = SIGMA0(xyz,xyz);
  354. H = H0(xyz,xyz,:);
  355. b1 = 1;
  356. b2 = b1+1;
  357. b3 = (b2+1):length(xyz);
  358. b = [numel(b1) numel(b2) numel(b3)];
  359. tmp1 = -SIGMA(b2,b1)/SIGMA(b1,b1);
  360. tmp2 = -SIGMA(b3,b1)/SIGMA(b1,b1);
  361. tmp3 = -(SIGMA(b3,b2)+tmp2*SIGMA(b1,b2))/(SIGMA(b2,b2)+tmp1*SIGMA(b1,b2));
  362. p1_1 = [eye(b(1)) zeros(b(1),b(2)) zeros(b(1),b(3));
  363. tmp1 eye(b(2)) zeros(b(2),b(3));
  364. tmp2 zeros(b(3),b(2)) eye(b(3))];
  365. p1_2 = [eye(b(1)) zeros(b(1),b(2)) zeros(b(1),b(3));
  366. zeros(b(2),b(1)) eye(b(2)) zeros(b(2),b(3));
  367. zeros(b(3),b(1)) tmp3 eye(b(3))];
  368. P1 = p1_2*p1_1;
  369. %-- REDUCED model --------------
  370. xz = [x z];
  371. SIGMAred = SIGMAred0(xz,xz);
  372. Hred = Hred0(xz,xz,:);
  373. bx1 = 1;
  374. bx2 = (bx1+1):length(xz);
  375. bx = [numel(bx1) numel(bx2)];
  376. P2 = [eye(bx(1)) zeros(bx(1),bx(2));
  377. -SIGMAred(bx2,bx1)/SIGMAred(bx1,bx1) eye(bx(2))];
  378. %-- conditional GC -------------
  379. for kk = 1:size(S,3)
  380. HH = H(:,:,kk)/P1;
  381. B = P2/Hred(:,:,kk);
  382. BB = [B(bx1,bx1) zeros(b(1),b(2)) B(bx1,bx2);
  383. zeros(b(2),b(1)) eye(b(2)) zeros(b(2),b(3));
  384. B(bx2,bx1) zeros(b(3),b(2)) B(bx2,bx2)];
  385. FF = BB*HH;
  386. numer = abs(det(SIGMAred(bx1,bx1)));
  387. denom = abs(det(FF(b1,b1)*SIGMA(b1,b1)*conj(FF(b1,b1))));
  388. causality(kk,y,x) = log(numer./denom);
  389. end
  390. elseif x==y
  391. causality(:,y,x) = 0;
  392. end
  393. end
  394. end
  395. end
  396. %--------------------------------------------------------------------------------
  397. %% wilson's method of spectral factorization
  398. %-------------------------------------------------------------------------------
  399. % [H Z, ps, ps0, converged] = wilson_sf(S, fs, tol)
  400. % Performs a numerical inner-outer factorization of a spectral matrix, using
  401. % Wilsons method. This implementation here is a slight modification of the
  402. % original implemention by M. Dhamala ([email hidden]) & G. Rangarajan
  403. % ([email hidden]), UF, Aug 3-4, 2006.
  404. %
  405. % modified by S K Mody ([email hidden]), 22.Sept.2016
  406. %revised by M. Dhamala, Oct, 2016
  407. % REF:
  408. % The Factorization of Matricial Spectral Densities, SIAM J. Appl. Math,
  409. % Vol. 23, No. 4, pgs 420-426 December 1972 by G T Wilson).
  410. %
  411. % ARGS:
  412. % S:
  413. % Spectral matrix function. This should be specified as a (k x k x m)
  414. % array for the frequencies in the closed range [0, 0.5], divided
  415. % into equal intervals. The spectrum for negative frequencies is assumed
  416. % to be symmetric, ie:-
  417. % S(-f) = transpose(S(f))
  418. %
  419. % fs:
  420. % Sampling rate. This is required for normalization.
  421. % ***IMPORTANT: Please ensure that the spectral matrix input, S, has
  422. % been normalized by the same value of fs, otherwise the the output
  423. % Z will be off by a factor.
  424. %
  425. % tol [default: 1e-9]:
  426. % The tolerance with which to check for convergence. Iterations stop
  427. % either when the number of iterations reaches a prespecified maximum
  428. % or when all of the following conditions are satisfied:-
  429. % |(ps0 - ps0_prev)./ps0_prev| < tol
  430. % |(ps - ps_prev)./ps_prev| < tol
  431. % |(S - ps*ps')./S| < tol
  432. % where |.| is the max norm.
  433. %
  434. % OUTPUT:
  435. % H, Z:
  436. % H is complex array of the same size as S, and Z is real symmetric
  437. % positive definite matrix such that for each i:
  438. % S(:,:,i) = H(:,:,i)*Z*H(:,:,i)'
  439. %
  440. % ps, ps0:
  441. % (k x k x m) complex array. Theoretically Ps is a function defined on
  442. % the on the boundary of the unit circle in the complex plane, such that:
  443. % S(:,:,i) = ps(:,:,i)*ps(:,:,i)'
  444. % Theoretically, Ps has a holomorphic extension in the complex plane to
  445. % all |z| < 1.). ps0 is the upper triangular matrix that is the value of
  446. % ps at the origin. Z is related to ps0 by:
  447. % Z = ps0*ps0'
  448. %
  449. % converged:
  450. % Boolean value indicating whether the iteration converged to within the
  451. % specified tolerance.
  452. %
  453. % relerr:
  454. % The relative Cauchy error of the convergence of the spectrum or Ps.
  455. %
  456. function [H, Z, ps, ps0, converged, relerr] = wilson_sf(S, fs, tol)
  457. if (nargin < 3) || isempty(tol), tol = 1e-9; end
  458. assert(isscalar(fs) && (fs > 0), ...
  459. 'fs must be a positive scalar value representing the sampling rate. ');
  460. [k, ~, N] = size(S);
  461. Sarr = cat(3, S, conj(S(:, :, N-1:-1:2)));
  462. ps0 = ps0_initial__(Sarr);
  463. ps = repmat(ps0, [1,1,N]);
  464. ps = cat(3, ps, conj(ps(:,:,N-1:-1:2)));
  465. M = size(Sarr, 3);
  466. I = eye(k);
  467. maxiter = min( 500, floor(sqrt(10/tol)) );
  468. U = zeros(size(Sarr));
  469. for j = 1 : M
  470. U(:,:,j) = chol(Sarr(:,:,j));
  471. end
  472. niter = 0;
  473. converged = false;
  474. g = zeros(k,k,M);
  475. while ( (niter < maxiter) && ~converged )
  476. for i = 1 : M
  477. % Equivalent to:
  478. % g(:,:,i) = ps(:,:,i)\Sarr(:,:,i)/ps(:,:,i)' + I;
  479. V = ps(:,:,i)\U(:,:,i)';
  480. g(:,:,i) = V*V' + I;
  481. end
  482. [gp, gp0] = PlusOperator(g);
  483. T = -tril(gp0, -1);
  484. T = T - T';
  485. ps_prev = ps;
  486. for i = 1 : M,
  487. ps(:,:,i) = ps(:,:,i)*(gp(:,:,i) + T);
  488. end
  489. ps0_prev = ps0;
  490. ps0 = ps0*(gp0 + T);
  491. % Relative cauchy error. Check on S is expensive, so check Ps0 first, then Ps and only then S.
  492. [converged relerr] = check_converged_ps__(ps, ps_prev, ps0, ps0_prev, tol);
  493. if converged
  494. % Uncomment this next line to check for relative cauchy error in spectrum.
  495. %[converged relerr] = check_converged_S__(Sarr, ps, tol);
  496. end
  497. niter = niter + 1;
  498. end
  499. H = zeros(k,k,N);
  500. for i = 1 : N
  501. H(:,:,i) = ps(:,:,i)/ps0;
  502. end
  503. ps = sqrt(fs)*ps(:,:,1:N);
  504. ps0 = sqrt(fs)*ps0;
  505. Z = ps0*ps0';
  506. end
  507. function ps0 = ps0_initial__(Sarr)
  508. [k, ~, M] = size(Sarr);
  509. % perform ifft to obtain gammas.
  510. Sarr = reshape(Sarr, [k*k, M]);
  511. gamma = ifft(transpose(Sarr));
  512. gamma0 = gamma(1,:);
  513. gamma0 = reshape(gamma0, [k k]);
  514. % Remove any assymetry due to rounding error.
  515. % This also will zero out any imaginary values
  516. % on the diagonal - real diagonals are required for cholesky.
  517. gamma0 = real((gamma0 + gamma0')/2);
  518. ps0 = chol(gamma0);
  519. end
  520. %% This function is for [ ]+operation
  521. function [gp, gp0] = PlusOperator(g)
  522. [k, ~, M] = size(g);
  523. N = ceil( (M+1)/2 );
  524. g = reshape(g, [k*k, M]);
  525. gammma = real(ifft(transpose(g)));
  526. gammma = reshape(transpose(gammma), [k,k,M]);
  527. % Take half of the zero lag
  528. gammma(:,:,1) = 0.5*gammma(:,:,1);
  529. gp0 = gammma(:,:,1);
  530. % Zero out negative powers.
  531. gammma(:, :, N+1:end) = 0;
  532. % Reconstitute
  533. gammma = reshape(gammma, [k*k, M]);
  534. gp = fft(transpose(gammma));
  535. gp = reshape(transpose(gp), [k,k,M]);
  536. end
  537. %%
  538. function [converged_ps relerr] = check_converged_ps__(ps, ps_prev, ps0, ps0_prev, tol)
  539. [converged_ps relerr] = CheckRelErr__(ps0, ps0_prev, tol);
  540. if converged_ps
  541. [converged_ps RelErr2] = CheckRelErr__(ps, ps_prev, tol);
  542. relerr = max(relerr, RelErr2);
  543. end
  544. end
  545. %%
  546. function [converged_S relerr] = check_converged_S__(S, ps, tol)
  547. FX = zeros(size(ps));
  548. parfor j = 1 : size(ps,3)
  549. FX(:,:,j) = ps(:,:,j)*ps(:,:,j)';
  550. end
  551. [converged_S relerr] = CheckRelErr__(FX, S, tol);
  552. end
  553. %%
  554. function [ok, relerr] = CheckRelErr__(A,B,reltol)
  555. D = abs(B - A);
  556. A = abs(A);
  557. A(A <= 2*eps) = 1; % Minimum detectable difference between
  558. % x and a value close to x is O(x)*eps.
  559. E = D./A;
  560. relerr = max(E(:));
  561. ok = (relerr <= reltol);
  562. end
  563. %%

computeCGCvar3.m at commit 474faac, under MIT · at the source

Overview

Authors: Joshua Y Assi1, Stephan Bickel1,2,3, Harly E Greenberg4, Ashesh D Mehta1,2, Thomas Similowski5,6, José L Herrero1,2
  1. Department of Bioelectronic Medicine, Feinstein Institutes for Medical Research, Manhasset, NY 11030, USA
  2. Departments of Neurology and Neurosurgery, Zucker School of Medicine at Hofstra Northwell, Hempstead, NY 11549, USA
  3. Center for Biomedical Imaging and Neuromodulation, Nathan Kline Institute, Orangeburg, NY 10962, USA
  4. Division of Pulmonary, Critical Care and Sleep Medicine, Department of Medicine, Zucker School of Medicine, Northwell Health, New Hyde Park, NY 11040, USA
  5. INSERM, UMRS1158 Neurophysiologie Respiratoire Expérimentale et Clinique, Sorbonne Université, Paris F-75005, France
  6. Groupe Hospitalier Universitaire APHP–Sorbonne Université, Hôpital Pitié–Salpêtrière, Département R3S, AP-HP, Paris F-75013, France
Journal: Science advances, volume 12, issue 31, article eaeb3326
Dates: received 8 August 2025; accepted 25 June 2026; published online 29 July 2026; in print July 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1126/sciadv.aeb3326 · PMID 42525758 · PMCID PMC13418533 · OpenAlex W4413923034
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: human (organism), systems (subfield)
Methods: Spectral & time-frequency, Preprocessing, Connectivity, Statistics, Physiology & signal measures
MeSH: Awareness*, Insular Cortex*, Prefrontal Cortex*, Respiration*, Adult, Brain Mapping, Female, Humans, Magnetic Resonance Imaging, Male (* major topic)
Topic: Neuroscience of respiration and sleep (Endocrine and Autonomic Systems, Neuroscience), according to OpenAlex
Funding: NIMH NIH HHS (P50 MH109429); NHLBI NIH HHS (R01 HL163578)
Citations: not cited yet (Europe PMC); 71 references in the paper

Abstract

How does the human brain detect and respond to disruptions in breathing? While animal studies have advanced our understanding of respiratory control, breathing distress in humans remains difficult to treat. It often arises not only from pulmonary lesions or brainstem dysfunction but also from how higher brain regions interpret breathing signals shaped by emotion and experience. We recorded intracranial cortical activity in neurosurgical patients during an interoceptive task involving transient breathing challenges. Conscious detection of these disruptions was predicted by early responses in the anterior insula, which routed signals to orbitofrontal and premotor cortices for appraisal and compensation. These cortical regions preferentially encoded inspiratory effort or airflow, revealing signal-specific processing that echoes functional segregation in brainstem centers. The present findings identify a dynamic insular-frontal circuit for sensing and adapting to respiratory challenges, offering insight into the neural basis of breathing awareness and its disruption in disease.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

Its files are read in the Code ↔ Paper reader above, with 2 matches between paragraphs and lines of code.

Zenodo 20596487

License: CC-BY-4.0
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Size: 1 file
Software Heritage: not checked
Found in: “Data, code, and materials availability:”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
  • 27 September 2026: the link answers (HTTP 200)

hualouliang/Granger_Geweke_Causality

License: MIT
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: 474faac6fffbd4ea8f00e76f40ac3d0b99d90a4f, 21 March 2019
Languages: MATLAB (4)
Size: 8 files, 4 scripts
Software Heritage: not archived
Found in: “Data, code, and materials availability:”
Holds: README, license file
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Tools: Signal Processing Toolbox (2 files)
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
6 files

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 4 scripts, each with its path and the digest of its content;
  • 2 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data, code, and materials availability

All data and code needed to evaluate and reproduce the results in this paper are present in the paper, the Supplementary Materials, and the Zenodo repository (DOI: 10.5281/zenodo.20596487 (http://dx.doi.org/10.5281/zenodo.20596487)), which contains the processed datasets and MATLAB code used to generate the main and supplementary figures. Raw intracranial EEG recordings are not publicly available because they contain potentially identifiable human participant data and are subject to Institutional Review Board restrictions. Deidentified raw intracranial EEG data supporting the findings of this study are available upon reasonable request through the Institute of Bioelectronic Medicine at Northwell Health (), subject to applicable regulatory and institutional requirements. Spectral GC analyses used publicly available code from the Granger-Geweke causality repository (https://github.com/hualouliang/Granger_Geweke_Causality), which provides analysis software only and does not contain data generated in this study. No new materials were generated in this study.

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 27 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 6 authors, 10 MeSH terms, 2 funders, 66 references.

Cite

This paper

Assi, J. Y., Bickel, S., Greenberg, H. E., Mehta, A. D., Similowski, T., & Herrero, J. L. (2026). Insular routing to orbitofrontal cortex enables breathing awareness. Science advances, 12(31), eaeb3326. https://doi.org/10.1126/sciadv.aeb3326

BibTeX

@article{assi2026insular,
author = {Assi, Joshua Y and Bickel, Stephan and Greenberg, Harly E and Mehta, Ashesh D and Similowski, Thomas and Herrero, José L},
title = {{Insular routing to orbitofrontal cortex enables breathing awareness}},
journal = {Science advances},
year = {2026},
month = jul,
volume = {12},
number = {31},
pages = {eaeb3326},
publisher = {American Association for the Advancement of Science},
issn = {2375-2548},
doi = {10.1126/sciadv.aeb3326},
url = {https://doi.org/10.1126/sciadv.aeb3326},
pmid = {42525758},
pmcid = {PMC13418533}
}

RIS

TY - JOUR
AU - Assi, Joshua Y
AU - Bickel, Stephan
AU - Greenberg, Harly E
AU - Mehta, Ashesh D
AU - Similowski, Thomas
AU - Herrero, José L
TI - Insular routing to orbitofrontal cortex enables breathing awareness
T2 - Science advances
J2 - Sci Adv
PY - 2026
DA - 2026/07/29
VL - 12
IS - 31
SP - eaeb3326
SN - 2375-2548
PB - American Association for the Advancement of Science
DO - 10.1126/sciadv.aeb3326
UR - https://doi.org/10.1126/sciadv.aeb3326
LA - en
ER -

CSL-JSON

{
"id": "10.1126/sciadv.aeb3326",
"type": "article-journal",
"title": "Insular routing to orbitofrontal cortex enables breathing awareness",
"container-title": "Science advances",
"author": [
{
"family": "Assi",
"given": "Joshua Y"
},
{
"family": "Bickel",
"given": "Stephan"
},
{
"family": "Greenberg",
"given": "Harly E"
},
{
"family": "Mehta",
"given": "Ashesh D"
},
{
"family": "Similowski",
"given": "Thomas"
},
{
"family": "Herrero",
"given": "José L"
}
],
"container-title-short": "Sci Adv",
"volume": "12",
"issue": "31",
"page": "eaeb3326",
"DOI": "10.1126/sciadv.aeb3326",
"PMID": "42525758",
"PMCID": "PMC13418533",
"ISSN": "2375-2548",
"publisher": "American Association for the Advancement of Science",
"URL": "https://doi.org/10.1126/sciadv.aeb3326",
"language": "en",
"issued": {
"date-parts": [
[
2026,
7,
29
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41467-026-73828-0 [code]
Human forebrain neural synchronization and entrainment to breathing during wakefulness, sleep, and external mechanical ventilation.
Journal: Nature communications
In common: Signal Processing Toolbox, 8 references
[2] doi:10.1162/imag.a.1227 [code]
Large language models reveal the neural tracking of linguistic context in attended and unattended multi-talker speech.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: 2 authors
[3] doi:10.1073/pnas.2603853123 [code]
A nose-to-brain circuit underlies anxiety regulation by nasal afferent frequency in mice.
Journal: Proceedings of the National Academy of Sciences of the United States of America
In common: Signal Processing Toolbox, systems, 4 references
[4] doi:10.1038/s41467-026-71604-8 [code]
Respiration as a dynamic modulator of sensory sampling.
Journal: Nature communications
In common: Signal Processing Toolbox, 4 references
[5] doi:10.1038/s41467-026-73106-z [code]
Respiratory pauses highlight sleep architecture in mice.
Journal: Nature communications
In common: Signal Processing Toolbox, 4 references
[6] doi:10.1038/s41467-026-75359-0 [code]
Neural mechanisms of time-forward predictions for naturalistic auditory tone sequences.
Journal: Nature communications
In common: Signal Processing Toolbox, 4 references
[7] doi:10.1093/nc/niag046 [code]
Awareness of being: a computational neurophenomenological model of mindfulness, mind-wandering, and meta-attentional control.
Journal: Neuroscience of consciousness
In common: 4 references
[8] doi:10.1371/journal.pbio.3003818 [code]
Human neuronal firing varies with the frequency of local field potential oscillations.
Journal: PLoS biology
In common: Signal Processing Toolbox, systems, 3 references
[9] doi:10.1371/journal.pbio.3003982 [code]
No evidence for modulation of the readiness potential by respiratory phase during natural breathing.
Journal: PLoS biology
In common: Signal Processing Toolbox, 3 references
[10] doi:10.1038/s41591-026-04498-0
A neuroprosthesis for restoring hand movement and sensation in a person with complete tetraplegia.
Journal: Nature medicine
In common: author Stephan Bickel

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.