Error of array value in loop( for for while)
이전 댓글 표시
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
KALYAN ACHARJYA
2018년 5월 20일
if OK/problem, let me know?
Cristina Soltoianu
2018년 5월 20일
KALYAN ACHARJYA
2018년 5월 20일
I am sure while condition problem solved, which line the error?
Cristina Soltoianu
2018년 5월 20일
KALYAN ACHARJYA
2018년 5월 20일
send me ppg.mat
Cristina Soltoianu
2018년 5월 20일
KALYAN ACHARJYA
2018년 5월 20일
편집: KALYAN ACHARJYA
2018년 5월 20일
I have edited the answer and provided code below. Now No error.
KALYAN ACHARJYA
2018년 5월 20일
Done??
Cristina Soltoianu
2018년 5월 20일
KALYAN ACHARJYA
2018년 5월 20일
편집: KALYAN ACHARJYA
2018년 5월 20일
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
2018년 5월 20일
편집: KALYAN ACHARJYA
2018년 5월 20일
I have answered as per your question.I have another assignment now. More help needed later, I wl help you.
Cristina Soltoianu
2018년 5월 20일
KALYAN ACHARJYA
2018년 5월 20일
편집: KALYAN ACHARJYA
2018년 5월 20일
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
Cristina Soltoianu
2018년 5월 20일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Spectral Estimation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!