how to find area under curve for every 10msec?

1 view (last 30 days)
Keshasni Earichappan on 11 Aug 2021
Edited: Scott MacKenzie on 15 Aug 2021
Hi, i have tried finding area under curve for each parabolic curve or for every 10msec time (as shown in the figure) but i coudn't find it.I only can find the whole area under curve of the graph by using the code as i attached. How to find area under curve for every 10msec time and plot them as a graph.Hope someone can help me with this.Thank you in advance.
t = T1.('TIME'); v = T1.('TORQUE');
plot(t,v)
grid
xlabel('t')
ylabel('v')
title('TORQUE VS TIME')
hold on;
Area=trapz(t,v);
plot(Area)
openfig('torque vs time.fig');

Scott MacKenzie on 13 Aug 2021
Edited: Scott MacKenzie on 15 Aug 2021
Here's solution that shows the slope (derivative) and area (integral) sample-to-sample in the signal. The sample period is 10 ms. For illustration, there are plots for the entire signal and for just the first 300 samples of the signal.
time = M(:,3);
torque = M(:,4);
Ps = mean(diff(time)); % sample period
% slope, sample to sample
s = diff(torque) / Ps; % slope = dy/dz
s = [0 s'];
tiledlayout(3,2);
% all samples
nexttile(1);
plot(time, torque); % signal
title('All samples');
nexttile(3);
plot(time, s); % slope (sample to sample)
title('diff (slope)');
nexttile(5);
tqa1 = (torque(1:end-1) + torque(2:end)) / 2 * Ps; % area under (sample to sample)
tqa1 = [0; tqa1];
plot(time, tqa1);
title('area under (10-ms intervals)');
% 1st 300 samples
m = 300;
nexttile(2);
plot(time(1:m),torque(1:m)); % signal
title('First 300 samples');
nexttile(4);
plot(time(1:m),s(1:m)); % slope (sample to sample)
title('diff (slope)');
nexttile(6);
tqa2 = (torque(1:m-1) + torque(2:m)) / 2 * Ps; % area under (sample to sample)
tqa2 = [0; tqa2];
plot(time(1:m),tqa2);
title('area under (10-ms intervals)');

Community Treasure Hunt

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

Start Hunting!

Translated by