From 035b4f3eff77bddf0b557b5362bd768aef596b37 Mon Sep 17 00:00:00 2001 From: Tien Dung Nguyen Date: Thu, 21 Mar 2024 11:04:15 +0100 Subject: [PATCH] remove tde on freq bands for now --- roi_tde.m | 13 ++++++++----- simulations/sim_tde_bispec.m | 27 ++++++++++++++------------- test_tde.m => test_pipes/test_tde.m | 9 +++++---- 3 files changed, 27 insertions(+), 22 deletions(-) rename test_tde.m => test_pipes/test_tde.m (88%) diff --git a/roi_tde.m b/roi_tde.m index 2f28307..4281119 100644 --- a/roi_tde.m +++ b/roi_tde.m @@ -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 @@ -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 \ No newline at end of file diff --git a/simulations/sim_tde_bispec.m b/simulations/sim_tde_bispec.m index da63533..c3837d2 100644 --- a/simulations/sim_tde_bispec.m +++ b/simulations/sim_tde_bispec.m @@ -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); @@ -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.') diff --git a/test_tde.m b/test_pipes/test_tde.m similarity index 88% rename from test_tde.m rename to test_pipes/test_tde.m index b72bf26..cd4517b 100644 --- a/test_tde.m +++ b/test_pipes/test_tde.m @@ -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'); \ No newline at end of file +% % frequency band +% pop_roi_connectplot(EEG2, 'measure', 'tde'); +% pop_roi_connectplot(EEG2, 'measure', 'tde_anti'); \ No newline at end of file