Skip to content

Commit

Permalink
remove tde on freq bands for now
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyen-td committed Mar 21, 2024
1 parent 86b4393 commit 035b4f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
13 changes: 8 additions & 5 deletions roi_tde.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
segleng = ndat;
epleng = ndat;
fres = EEG.srate;
frqs = sfreqs(2 * fres, EEG.srate);
frqs = sfreqs(fres, EEG.srate);
maxfreqbins = floor(segleng/2);

% only keeep first PC
Expand Down Expand Up @@ -90,9 +90,12 @@
[T, I] = bispectral_TD_est(B2_xxx, B2_xyx, B2_yyy, tde_method, [], 1);
[aT, aI] = bispectral_TD_est(B2_xxx, B2_xyx - B2_yxx, B2_yyy, tde_method, [], 1); % antisymmetrization
else
fmask = true(1, length(frqs));
fmask(frqs < tde_freqbands(1) | frqs > tde_freqbands(2)) = 0;
[T, I] = bispectral_TD_est(B2_xxx, B2_xyx, B2_yyy, tde_method, fmask(1:end-1), 1);
[aT, aI] = bispectral_TD_est(B2_xxx, B2_xyx - B2_yxx, B2_yyy, tde_method, fmask(1:end-1), 1); % antisymmetrization
error('TDE on frequency bands is not implemented yet.')
% neg_frqs = cat(1, -flip(frqs(2:end)), frqs(1:end-1)); % create new freq vector with negative frequencies
% fmask = false(1, maxfreqbins);
% fmask(find(neg_frqs == tde_freqbands(1)):find(neg_frqs == tde_freqbands(2))) = 1;
% % fmask(find(neg_frqs == -tde_freqbands(2)):find(neg_frqs == -tde_freqbands(1))) = 1;
% [T, I] = bispectral_TD_est(B2_xxx, B2_xyx, B2_yyy, tde_method, fmask(1:end-1), 1);
% [aT, aI] = bispectral_TD_est(B2_xxx, B2_xyx - B2_yxx, B2_yyy, tde_method, fmask(1:end-1), 1); % antisymmetrization
end
end
27 changes: 14 additions & 13 deletions simulations/sim_tde_bispec.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
eeglab
Xraw = mk_series(t+abs(delay), signal_type, 0.7,0);
noiseX = mk_series(t, noise_type, 0.7, 0);
noiseY = mk_series(t, nois50e_type, 0.7, 0);
noiseY = mk_series(t, noise_type, 0.7, 0);

% Combine and segment
[Xlong, Ylong] = combine_sn(Xraw, noiseX, noiseY, delay, srate, snr, theta, beta);
Expand All @@ -42,35 +42,36 @@
segshift = floor(ndat/2);
epleng = ndat;
fres = srate;
frqs = sfreqs(2 * fres, srate);
maxfreqbins = floor(ndat/2);

[B2_xxx] = squeeze(data2bs_univar(Xlong', ndat, segshift, epleng, length(frqs)-1));
[B2_xxx] = squeeze(data2bs_univar(Xlong', ndat, segshift, epleng, maxfreqbins));
para_xyx.chancomb = [1, 2, 1];
[B2_xyx] = data2bs_univar([Xlong', Ylong'], ndat, segshift, epleng, length(frqs)-1, para_xyx);
[B2_yyy] = squeeze(data2bs_univar(Ylong', ndat, segshift, epleng, length(frqs)-1));
[B2_xyx] = data2bs_univar([Xlong', Ylong'], ndat, segshift, epleng, maxfreqbins, para_xyx);
[B2_yyy] = squeeze(data2bs_univar(Ylong', ndat, segshift, epleng, maxfreqbins));

% required for antisymmetrization
para_yxx.chancomb = [2, 1, 1];
[B2_yxx] = data2bs_univar([Xlong', Ylong'], ndat, segshift, epleng, length(frqs)-1, para_yxx);
[B2_yxx] = data2bs_univar([Xlong', Ylong'], ndat, segshift, epleng, maxfreqbins, para_yxx);

[T, I] = bispectral_TD_est(B2_xxx, B2_xyx, B2_yyy, method, [], 1);
[aT, aI] = bispectral_TD_est(B2_xxx, B2_xyx - B2_yxx, B2_yyy, method, [], 1);

% TDE on frequency bands
band = [20 30];
fmask = true(1, length(frqs));
fmask(frqs < band(1) | frqs > band(2)) = 0;
[T_, I_] = bispectral_TD_est(B2_xxx, B2_xyx, B2_yyy, method, fmask(1:end-1), 1);
% % TDE on frequency bands
% frqs = sfreqs(fres, srate);
% neg_frqs = cat(1, -flip(frqs(2:end)), frqs(1:end-1)); % create new freq vector with negative frequencies
% band = [20 30];
% fmask = false(1, maxfreqbins);
% fmask(find(neg_frqs == band(1)):find(neg_frqs == band(2))) = 1; fmask(find(neg_frqs == -band(2)):find(neg_frqs == -band(1))) = 1;
% [T_, I_] = bispectral_TD_est(B2_xxx, B2_xyx, B2_yyy, method, fmask(1:end-1), 1);


%% Plotting
% extract estimated delay/peak
shift = (-seglen+1:seglen-1) / srate;
[peak_val, peak_idx] = max(aT);
[peak_val, peak_idx] = max(T);
est_delay = shift(peak_idx); % in Hz

figure; plot(shift, aT, 'black')
figure; plot(shift, T, 'black')
xline(est_delay, '--r')
xlabel('Time (s)')
ylabel('a.u.')
Expand Down
9 changes: 5 additions & 4 deletions test_tde.m → test_pipes/test_tde.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@
EEG1 = pop_roi_connect(EEG, 'methods', {'TDE'}, 'tde_regions', [roi1_idx roi2_idx], 'tde_method', 1);

%% Test TDE on frequency bands
EEG2 = pop_roi_connect(EEG, 'methods', {'TDE'}, 'tde_regions', [roi1_idx roi2_idx], 'tde_method', 1, 'tde_freqbands', [11 13]);
% not fully implemented yet, needs further testing
% EEG2 = pop_roi_connect(EEG, 'methods', {'TDE'}, 'tde_regions', [roi1_idx roi2_idx], 'tde_method', 1, 'tde_freqbands', [11 13]);

%% Plotting
% broadband
pop_roi_connectplot(EEG1, 'measure', 'tde');
pop_roi_connectplot(EEG1, 'measure', 'tde_anti');

% frequency band
pop_roi_connectplot(EEG2, 'measure', 'tde');
pop_roi_connectplot(EEG2, 'measure', 'tde_anti');
% % frequency band
% pop_roi_connectplot(EEG2, 'measure', 'tde');
% pop_roi_connectplot(EEG2, 'measure', 'tde_anti');

0 comments on commit 035b4f3

Please sign in to comment.