MATLAB Answers

Separate inhale and exhale duration

4 ビュー (過去 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.

  0 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by