MATLAB Answers

0

Related to calculate average within particular range of graph

Asked by Preshit Limje on 18 Sep 2019 at 11:26
Latest activity Commented on by Star Strider
on 18 Sep 2019 at 15:17
Hello,
I am new to matlab. I got signals from the sensors for force with respect to time. The values of time and force are stored in respetive columns after importing it in matlab through excel file. Thus, I need to find the average values within particular range of values in graph (highlighted in red colour). Can someone help?
Thanks
Preshit

  0 Comments

Sign in to comment.

1 Answer

Answer by Star Strider
on 18 Sep 2019 at 11:56
 Accepted Answer

Use the negative of your signal (essentially flipping it upside-down) so the sharp dips are now peaks. Then use either findpeaks or islocalmax to isolate the indices of the peaks. Use those indices to calculate the mean between them. (If I had your signal, I could write code specific to your problem. With only a picture, I can only describe the approach.)

  4 Comments

Show 1 older comment
This was slightly more complicated than I originally thought it would be.
The Code —
[num,txt] = xlsread('test 1.xlsx');
time=num(:,1);
Fz=num(:,5);
Fzei = find(Fz > 270); % Edit ‘Fz’ To Eliminate Irrelevant Data
[pks,locs] = findpeaks(-Fz(Fzei), 'MinPeakProminence',100); % Find Sharp Dip Indices
locsi = Fzei(locs); % Map ‘lods’ To Edited Data Indices
for k = 1:numel(locsi)-1
idxrng{k} = (locsi(k)+1):(locsi(k+1)-1);
seg_mean(k) = mean(Fz(idxrng{k}));
end
figure
plot(time,Fz);
hold all
plot(time(locsi), -pks, 'vr')
for k = 1:numel(idxrng)
plot(time(idxrng{k}), ones(size(idxrng{k}))*seg_mean(k), '-r', 'LineWidth',2)
end
hold off
grid
xlabel('Time')
ylabel('F_z')
legend('Data','Valleys','Segment Mean', 'Location', 'NW')
The Plot —
Related to calculate average within particular range of graph - 2019 09 18.png
This appears to give the requestted information. The segment means are in the ‘seg_mean’ vector. Experiment to get other results.
Hello Strider,
Thanks a lot. I much appreciate your help for solving this problem.
As always, my pleasure!

Sign in to comment.