Is it possible to use the trapz function to calculate the integrated value for each point of a data set?

조회 수: 4 (최근 30일)
I have a column of data that plots a sin wave. I want to know the area under the curve at a given point or of a set number of samples, for example, a time vector.
This data is plotted against time with every 100 data points representing one second.
Is it possible to calculate the area under the curve for every 100 points? I want to end up with a sin wave with the integrated values i.e. how the area under the curve changes over time.
Is this possible? or is there another/better way to do this?
Thank you in advance

답변 (1개)

Star Strider
Star Strider 2018년 7월 12일
I am not certain how you are generating your signal.
One option is to use the reshape (link) function with your signal:
t = linspace(0, 2*pi, 10000);
s = sin(t);
sr = reshape(s(:), 100, []);
int_sr = trapz(sr);
  댓글 수: 2
C Smyth
C Smyth 2018년 7월 12일
The signal is an impedance breathing signal recorded from a person at 100 Hz. The length of the signal is 6787.
Star Strider
Star Strider 2018년 7월 12일
Try this:
Fs = 100; % Sampling Frequency (Hz)
N = 6767; % Number Of Samples
t = linspace(0, N, N)/Fs; % Time Vector
s = sin(2*pi*t/75); % Signal
L = numel(s); % Signal Length
sr = reshape(s(1:fix(L/Fs)*Fs)', 100, []); % Reshape Signal Vector
int_sr = trapz(sr);
figure(1)
plot(t, s*100)
hold on
stairs(t(1:Fs:end-Fs), int_sr)
hold off

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

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by