Hello everyone! I am trying to make a code that would calculate BPM from PPG. the original signal has artifacts from poor handling of the sensor so i am also trying to get rid of enormous peaks that are present. I have encountered an odd error when using 'while' in a 'for' loop. DeltaT must be a vector, without while it recognizes it but douse not stop after reaching max length of the input. Once i put while in the loop, the resulting deltaT is still a vector but has the value of the last calculation. i fail to see what is my mistake. please help me to solve this interesting problem. Kind regards!
n=load('ppg.mat');
ppg=n.data(:,2);
t=(0:(length(ppg)-1));
f_s=1000;
N=length(ppg);
T=[0:N-1]/f_s; %time period(total sample/Fs )
w=50/(f_s/2);
q=34;
bw=w/q;
[b,a]=iirnotch(w,bw); % notch filter implementation
ppg_f=filter(b,a,ppg);
N1=length(ppg_f);
t1=[0:N1-1]/f_s;
% figure
% plot(ppg_f,'r');
% xlabel('time')
% ylabel('amplitude')
t = 1:length(ppg_f);
[~,locs_Rwave] = findpeaks(ppg_f,'MinPeakHeight',0.4,...
'MinPeakDistance',600);
% Remove Edge Wave Data
locs_Rwave(locs_Rwave < 150 | locs_Rwave > (length(ppg_f) - 150)) = [];
x=locs_Rwave.';
frecventainstantanee=ones(1,length(x));
timpobataie=ones(1,length(x)-1);
deltaT=ones(1,length(x)-1);
r=length(x);
for(o=1:r)
for(j=1:r)
while(o<r )
deltaT(j)=x(o+1)-x(o);
o=o+1;
j=j+1;
end
end
end
end

14 Kommentare

KALYAN ACHARJYA
KALYAN ACHARJYA am 20 Mai 2018
if OK/problem, let me know?
Hi, again. I appreciate your willingness to help me, although i still get an error message saying ”Index exceeds matrix dimensions”
KALYAN ACHARJYA
KALYAN ACHARJYA am 20 Mai 2018
I am sure while condition problem solved, which line the error?
this is the error message that pops out:
Index exceeds matrix dimensions.
Error in dinacqcopy (line 42)
deltaT(j)=x(o+1)-x(o);
my guess is that the loop douse not stop at (r-1). I have tried to set it at r-2, but the same message is showing. What a kerfuffle.
KALYAN ACHARJYA
KALYAN ACHARJYA am 20 Mai 2018
send me ppg.mat
I have attached it on the original question, but i will attach it again here.
Thank you for your time and effort
KALYAN ACHARJYA
KALYAN ACHARJYA am 20 Mai 2018
Bearbeitet: KALYAN ACHARJYA am 20 Mai 2018
I have edited the answer and provided code below. Now No error.
KALYAN ACHARJYA
KALYAN ACHARJYA am 20 Mai 2018
Done??
The code works, no error displayed. But if you check the variables,in the array deltaT all values are equal, which is the value of the last calculation done in the loop, where it should have different values. I am sorry to impose.
KALYAN ACHARJYA
KALYAN ACHARJYA am 20 Mai 2018
Bearbeitet: KALYAN ACHARJYA am 20 Mai 2018

definitely, you get the same value. see deltaT(j) expression, both having o

    % code
  deltaT(j)=x(o+1)-x(o); 

when j for loop exucated, it go to next o value, again insite loop run from j=1 to r-1 or r

one 'o' should be j, then only you will get different vales in same line like I have tried following and got the different results, wheather it technically correct or not, I dont know-

    % code
  deltaT(j)=x(o+1)-x(j)
KALYAN ACHARJYA
KALYAN ACHARJYA am 20 Mai 2018
Bearbeitet: KALYAN ACHARJYA am 20 Mai 2018
I have answered as per your question.I have another assignment now. More help needed later, I wl help you.
Thank you. For now I have accepted your answer and voted. Hope to hear from you again.
Good luck!
KALYAN ACHARJYA
KALYAN ACHARJYA am 20 Mai 2018
Bearbeitet: KALYAN ACHARJYA am 20 Mai 2018
I have mentioned the solution how you get the different values in above comment. Check it, but I don't know the technically correct result or not. Mail
I will work on it again tomorrow. for now i am only happy that I got rid of the error and display of different values. I will let you know!
It's been a pleasure!

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 20 Mai 2018
Bearbeitet: KALYAN ACHARJYA am 20 Mai 2018

1 Stimme

clc;
clear all;
close all;
n=load('ppg.mat');
ppg=n.data(:,2);
t=(0:(length(ppg)-1));
f_s=1000;
N=length(ppg);
T=[0:N-1]/f_s; %time period(total sample/Fs )
w=50/(f_s/2);
q=34;
bw=w/q;
[b,a]=iirnotch(w,bw); % notch filter implementation
ppg_f=filter(b,a,ppg);
N1=length(ppg_f);
t1=[0:N1-1]/f_s;
% figure
% plot(ppg_f,'r');
% xlabel('time')
% ylabel('amplitude')
t = 1:length(ppg_f);
[~,locs_Rwave] = findpeaks(ppg_f,'MinPeakHeight',0.4,'MinPeakDistance',600);
% Remove Edge Wave Data
locs_Rwave(locs_Rwave < 150 | locs_Rwave > (length(ppg_f) - 150)) = [];
x=locs_Rwave.';
frecventainstantanee=ones(1,length(x));
timpobataie=ones(1,length(x)-1);
deltaT=ones(1,length(x)-1);
r=length(x);
for o=1:r-1
for j=1:r-1
%while(o<r )
deltaT(j)=x(o+1)-x(o);
end
end

1 Kommentar

Thank you very much, KALYAN ACHARJYA, I will try it right away.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by