Calculate mean of an array in time windows.

조회 수: 5(최근 30일)
Joana 2020년 1월 21일
답변: Athul Prakash 2020년 1월 24일
i have EEG data recorded at 1200hz from 5 channels, for 10 repetitions, and i need to calculate mean of each 1s signal in 10 time windows (each of 100ms) as a features. Is thi the right way to do.? Although the features i'm getting isn't right.
for repetition = 1:size(EEG,3) % loop through repetitions
featCnt = 1; % feature counter for generic choice of features or channels
chanCnt = 1;
for channel = 1:length(channels)
for window = 1:10
% calculate mean for current repetition and channel
features(repetition,featCnt) = mean(EEG(repetition)+(1200/10)*(window-1):(EEG(repetition)+(1200/10)*(window+1)-1));
featLabels{featCnt} = sprintf('%s_Mean_%i',chanLabels{chanCnt},window);
featCnt = featCnt + 1; % Count up, for generic choice of feature or channels
chanCnt = chanCnt + 1;


Athul Prakash
Athul Prakash 2020년 1월 24일
I'm not sure how you have arranged your data within the matrix 'EEG' - which dimensions correspond to which attributes?
I noticed that in the following line:
features(repetition,featCnt) = mean(EEG(repetition)+(1200/10)*(window-1):(EEG(repetition)+(1200/10)*(window+1)-1));
you are indexing into EEG using just one variable 'repetition'. But you seem to be looping through dimension-3 of EEG with the same variable - this would produce the wrong result.
I would recommend understanding Matlab's indexing thoroughly before you get working on matrix math such as this. Have a look at this doc:
If you need to brush up on or practice working with loops, indexing etc, Maltab OnRamp is a good place to start.

Community Treasure Hunt

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

Start Hunting!

Translated by