Signal auto-correlation in matlab (xcorr function)

13 ビュー (過去 30 日間)
Panos Kerezoudis
Panos Kerezoudis 2023 年 4 月 20 日
コメント済み: Panos Kerezoudis 2023 年 4 月 21 日
Hi!
I am working on an EEG-electrophysiology dataset ('csd'). It is structured as a 3D array (channels x time x trials). The dimensions are 16x1527x200.
I am trying to calculate trial-averaged autocorrelation for each channel and I am getting the error message below. I think it has to do with the last part of my loop? The dimensions of the ac0 output (dot products) are 1x201 for some reason, I think the way the function is built, it adds one more column?
Any help would be great!
  2 件のコメント
Mathieu NOE
Mathieu NOE 2023 年 4 月 20 日
if you expect someone to help you , it's good practice to share some code and data
Panos Kerezoudis
Panos Kerezoudis 2023 年 4 月 20 日
Absolutely. The code is below. I cannot share data unfortunately (confidentiality reasons).
% Calculate trial-averaged auto-correlation
nchan = size(csd, 1); % channels
ntrials = size(csd, 3); % trials
nlags = 100; % n of lags
ac = zeros(1, 2*nlags + 1); % initialize auto-correlation vector
for i = 1:nchan % loop over channels
for k = 1:ntrials % loop over trials
x = csd(i, :, k) - mean(csd(i, :, k)); % mean-normalize data
[acO, lags] = xcorr(x, nlags, 'biased'); % biased estimate
ac(i, :) = ac(i, :) + double(acO(i, :)/ntrials); % add to total scaled by 1/k
end
end

サインインしてコメントする。

採用された回答

Chunru
Chunru 2023 年 4 月 21 日
csd = randn(4, 100, 20); % dummy data
% Calculate trial-averaged auto-correlation
nchan = size(csd, 1); % channels
ntrials = size(csd, 3); % trials
nlags = 100; % n of lags
ac = zeros(nchan, 2*nlags + 1); % initialize auto-correlation vector
% ^^^^
for i = 1:nchan % loop over channels
for k = 1:ntrials % loop over trials
x = csd(i, :, k) - mean(csd(i, :, k)); % mean-normalize data
[acO, lags] = xcorr(x, nlags, 'biased'); % biased estimate
ac(i, :) = ac(i, :) + double(acO/ntrials); % add to total scaled by 1/k
% ^^^
end
end
  1 件のコメント
Panos Kerezoudis
Panos Kerezoudis 2023 年 4 月 21 日
it worked, thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEEG/MEG/ECoG についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by