hello
my 2 fold suggestion , first is new code according to your expected results , and second is based on sliding averaging - function is in attachement !
enjoy
samples = 1000;
VectorTime = 1 + sin(2*pi*(1:samples)/samples)+ 0.25*rand(1,samples);
buffer = 25;
for ci=1:floor(length(VectorTime)/ buffer)
start_index = 1+(ci-1)*buffer;
stop_index = min(start_index+ buffer,length(VectorTime));
time_index(ci) = round((start_index+stop_index)/2);
frr(ci) =mean(VectorTime(start_index:stop_index))
end
figure(1),
plot((1:samples),VectorTime,'b',time_index,frr,'or');
out = myslidingavg(VectorTime, buffer);
figure(2),
plot((1:samples),VectorTime,'b',(1:samples),out,'r');
Best Answer