필터 지우기
필터 지우기

moving average of unevenly spaced time data

조회 수: 15 (최근 30일)
Research
Research 2018년 2월 19일
댓글: Julie van der Hoop 2019년 4월 1일
Hello,
I have the following data, and need to average the signal data as per defined window size. Any help?
signal= [0.1 0.2 0.15 0.3]; % volt reading
time_signal = [3.5 5.5 6.5 10.5];% seconds after event, the time when signal was recorded
time_regular = [ *1 2 3 4* 5 6 7 8 *9 10 11 12 13*]; time in seconds
Window_size is 4, 4 and 5. I want to average the signal data that falls within first 4 seconds, then next 4 seconds and finally in next 5 seconds. I highlighted the window sizes in time_regular array.
The answer is 0.1, 0.175 and 0.3. The calculation is done as follows. In first 4 seconds there is only one signal data point that falls within first 4 seconds, therefore first value is 0.1. In next 4 seconds, there are two signal data points (0.2 and 0.15), therefore the average of these two points is 0.175. In next 5 seconds, there is only one signal data point (0.3), therefore the average is 0.3. I can do this using for loop, but I have 100s of window sizes and big data.
Any matlab function can do this trick?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2018년 2월 19일
편집: Andrei Bobrov 2018년 2월 19일
t = randi([3 5],6,1); % your time intervals in seconds
n = cumsum(t);
s = rand(n(end),1);
s = s.*(s < .3); % your signal
ii = zeros(n(end),1);
ii(n - t + 1) = 1;
s(s == 0) = nan;
out = accumarray(cumsum(ii),s,[],@(x)mean(x,'omitnan'));
  댓글 수: 4
Andrei Bobrov
Andrei Bobrov 2018년 2월 19일
Other varint here 't' with don't integers
t = cumsum(.6*rand(40,1) + .5); % time
s = .3*rand(40,1) + .4;
s = s.*(s > .5); % your signal
k = randi([3 6],6,1);
tt = k/sum(k);
ii = [0;cumsum(t(end)*tt)]; % time-intervals boundaries
jj = discretize(t,ii);
s(s == 0) = nan;
out = accumarray(jj(:),s,[],@(x)mean(x,'omitnan'));
Julie van der Hoop
Julie van der Hoop 2019년 4월 1일
Can I ask why the k is it setting unequal time bins? Isn't the goal to have equal time bins across the series (i.e., compute over 4 seconds)?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by