Having trouble to calculate the area under curve for each peaks and display the area under curve in graph?

1 view (last 30 days)
Keshasni Earichappan on 10 Aug 2021
Commented: Star Strider on 11 Aug 2021
Hi there.I am new to mathlab and having trouble to calculate the area under curve for each peaks and display the area under curve in graph? i have attached the file over here.Hope someone can help me. thanks in advance.
Keshasni Earichappan on 10 Aug 2021
Hi Scott MacKenzie.Thank you for answering.The 'peak' i mentioned is a SIGNAL PEAK(SP) .Basically, i need to know how to calculate the area under curve for each muscle contractions( MC[V] ) and plot them as a graph.

Star Strider on 10 Aug 2021
It depends entirely on what the definition of ‘peak’ is, and if the data first need to be detrended.
T1 = 90483×2 table
TIME MC[v] ____ ______ NaN 1.8297 0 1.8289 10 1.8297 20 1.8297 30 1.8305 40 1.8289 50 1.8297 60 1.8313 70 1.8305 80 1.8281 90 1.8297 100 1.8305 110 1.8305 120 1.8297 130 1.8297 140 1.8305
t = T1.TIME;
v = T1.('MC[v]');
Ts = mean(diff(t),'omitnan');
Fs = 1/Ts;
Fn = Fs/2;
figure
plot(t, v)
grid
xlabel('t')
ylabel('v')
title('Original Data') vfilt = highpass(v, 1E-4, Fs, 'ImpulseResponse','iir');
zxi = find(diff(sign(vfilt)));
for k = 1:numel(zxi)
idxrng = max(1, zxi(k)-1) : min(numel(v),zxi(k)+1);
tzc(k) = interp1(vfilt(idxrng),t(idxrng),0);
end
tzc = unique(tzc);
for k = 1:numel(tzc)-1
Lv = (t>=tzc(k) & t<=tzc(k+1));
tv{k} = t(Lv);
vv{k} = vfilt(Lv);
if (numel(vv{k}) > 1)
Area(k) = trapz(tv{k},vv{k});
else
Area(k) = 0;
end
tvm(k) = mean(tv{k});
maxvv = max(vv{k});
if (~isempty(maxvv))
pkv(k) = maxvv;
else
pkv(k) = NaN;
end
end
figure
plot(t, vfilt)
hold on
plot(tzc, zeros(size(tzc)), 'xr')
hold off
grid
xlabel('t')
ylabel('v')
title('Original Data (Detrended)')
legend('Data', 'Zero-Crossings', 'Location','best') % text(tvm,pkv, compose('\\leftarrow %.3f',Area), 'Horiz','center', 'Vert','bottom', 'Rotation',90)
.
Star Strider on 11 Aug 2021
As always, my pleasure!
.