Separate inhale and exhale duration

조회 수: 1 (최근 30일)
Majd AG
Majd AG 2020년 4월 12일
답변: Peter Perkins 2020년 4월 14일
Hello all,
using NI myRIO I obtained an array of intersection points between a signal and a threshold, every two values represent the rise and fall of an inhale and exhale, repectively.
I want to subtract each two values and store them in new arrays, inhale time, exhale time and breath time.
Now i know there's a problem in the loops I made but i don't know how to fix them, please help me. I'm getting the same values of duration, maybe the j is not updating
the attached picture is the signal where the values were obtained from.
breath=[903, 1979, 2313, 3550, 3870, 4947, 5232, 6517, 6867, 7818, 8181, 9512];
count=length(breath)/2 ; %count peaks (inhales and exhales)
%Find duration of inhale & exhale
INduration=zeros(1,count/2);
for k=1:count/2 %durations of inhale
for j=1:4:length(breath)-4
INduration(k)= breath(j+1)-breath(j);
end
end
EXduration=zeros(1,count/2);
for n=1:count/2 %durations of exhale
for j=3:4:length(breath)-4
EXduration(n)= breath(j+1)-breath(j);
end
end
BRduration=zeros(1,count/2);
for r=1:count/2 %durations of whole breath
for j=1:4:length(breath)-4
BRduration(r)= breath(j+3)-breath(j);
end
end
  댓글 수: 2
Image Analyst
Image Analyst 2020년 4월 12일
Set a breakpoint on the lines inside the for j loop, and see if the program stops there and if indeed j is changing? I think you'll see it does change
Majd AG
Majd AG 2020년 4월 12일
Thank you for answering, I tried displaying the j inside the first loop and it alternates between two values 1&5 three times, what does that mean?

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

답변 (1개)

Peter Perkins
Peter Perkins 2020년 4월 14일
You don't need any loops.
Your picture doesn't seem to match your description, but if each sret of four values corresponds to inhale start, inhale stop, exhale start, exhale stop, then do this:
>> breath = seconds([903, 1979, 2313, 3550, 3870, 4947, 5232, 6517, 6867, 7818, 8181, 9512])
breath =
1×12 duration array
903 sec 1979 sec 2313 sec 3550 sec 3870 sec 4947 sec 5232 sec 6517 sec 6867 sec 7818 sec 8181 sec 9512 sec
>> inhale = reshape(breath([1 2 5 6 9 10]),[2 3])
inhale =
2×3 duration array
903 sec 3870 sec 6867 sec
1979 sec 4947 sec 7818 sec
>> inhaleDuration = diff(inhale)
inhaleDuration =
1×3 duration array
1076 sec 1077 sec 951 sec
and similarly for the others.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by