fix the indices of the matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
I really need help to fix the indices of the for loop to run the QRS detection.
I updated the file, this code run with the file ech_60hz_200 that I downl;oad from bio bank, but it cannot run with the code ecg_sbj1 that I recorded in the lab room. it returned 'Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.' Please help me fix this indices in the for loop to run the code
close all;clear;clc;
load('ecg_sbj1.mat');
sig=ecg;
N=length(sig);
fs=200;
t=[0:N-1]/fs;
title('Original Signal')
b=1/32*[1 0 0 0 0 0 -2 0 0 0 0 0 1];
a=[1 -2 1];
sigL=filter(b,a,sig);
b=[-1/32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1/32];
a=[1 -1];
sigH=filter(b,a,sigL);
b=[1/4 1/8 0 -1/8 -1/4];
a=[1];
sigD=filter(b,a,sigH);
sigD2=sigD.^2;
signorm=sigD2/max(abs(sigD2));
h=ones(1,31)/31;
sigAV=conv(signorm,h);
sigAV=sigAV(15+[1:N]);
sigAV=sigAV/max(abs(sigAV));
treshold=mean(sigAV);
P_G= (sigAV>0.01);
difsig=diff(P_G);
left=find(difsig==1);
raight=find(difsig==-1);
left=left-(6+16);
raight=raight-(6+16);
for i=1:length(left);
[R_A(i) R_t(i)]=max(sigL(left(i):raight(i)));
R_t(i)=R_t(i)-1+left(i) %add offset
[Q_A(i) Q_t(i)]=min(sigL(left(i):R_t(i)));
Q_t(i)=Q_t(i)-1+left(i)
[S_A(i) S_t(i)]=min(sigL(left(i):raight(i)));
S_t(i)=S_t(i)-1+left(i)
[P_A(i) P_t(i)]=max(sigL(left(i):Q_t(i)));
P_t(i)=P_t(i)-1+left(i)
[T_A(i) T_t(i)]=max(sigL(S_t(i):raight(i)));
T_t(i)=T_t(i)-1+left(i)+47
end
figure;plot(t,sigL,t(Q_t),Q_A,'*g',t(S_t),S_A,'^k',t(R_t),R_A,'ob',t(P_t),P_A,'+b',t(T_t),T_A,'+r');
for i=1:((length(P_t))-1)
HRV=P_t(i+1)-P_t(i)
end
댓글 수: 2
답변 (2개)
Walter Roberson
2022년 3월 21일
In each case your left values are greater than your corresponding right values, so left(i):right(i) is always empty.
댓글 수: 2
Walter Roberson
2022년 3월 21일
Immediately before your
for i=1:length(left);
statement, put in
disp([left, right])
You will see that in every case, the value in the left column is greater than the value in the right column. You use those values as the start and stop indices left(i):right(i) but with left being greater than right, that is empty. Computing with empty gives you empty, so the right hand side of the computation is empty. You are trying to store that emptiness into a scalar location, which is a size mismatch.
You are assuming that difsig==1 always occurs before difsig==-1 but what if that is not the case?? What if the signal zags first instead of zigging first?
VBBV
2022년 3월 21일
close all;clear;clc;
load('ecg_sbj1.mat')
sig=ecg
N=length(sig);
fs=200;
t=[0:N-1]/fs
b=1/32*[1 0 0 0 0 0 -2 0 0 0 0 0 1];
a=[1 -2 1];
sigL=filter(b,a,sig)
b=[-1/32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1/32]
a=[1 -1];
sigH=filter(b,a,sigL);
b=[1/4 1/8 0 -1/8 -1/4];
a=[1];
sigD=filter(b,a,sigH)
sigD2=sigD.^2;
signorm=sigD2/max(abs(sigD2));
h=ones(1,31)/31;
sigAV=conv(signorm,h);
sigAV=sigAV(15+[1:N]);
sigAV=sigAV/max(abs(sigAV));
treshold=mean(sigAV);
P_G= (sigAV>0.01);
difsig=diff(P_G);
left=find(difsig==1);
raight=find(difsig==-1);
left=left-(6+16)
raight=raight-(6+16)
max(left)
max(raight)
min(left)
min(raight)
for i=1:length(left);
if raight(i) < left(i)
[R_A(i) R_t(i)]=max(sigL(raight(i):left(i)));
R_t(i)=R_t(i)-1+left(i); %add offset
else
[R_A(i) R_t(i)]=max(sigL(left(i):raight(i)));
R_t(i)=R_t(i)-1+left(i); %add offset
end
if left(i) < R_t(i)
[Q_A(i) Q_t(i)]=min(sigL(left(i):R_t(i)));
Q_t(i)=Q_t(i)-1+left(i);
else
[Q_A(i) Q_t(i)]=min(sigL(R_t(i):left(i)));
Q_t(i)=Q_t(i)-1+left(i);
end
if raight(i) < left(i)
[S_A(i) S_t(i)]=min(sigL(raight(i):left(i)));
S_t(i)=S_t(i)-1+left(i);
else
[S_A(i) S_t(i)]=min(sigL(left(i):raight(i)));
S_t(i)=S_t(i)-1+left(i);
end
if left(i) < Q_t(i)
[P_A(i) P_t(i)]=max(sigL(left(i):Q_t(i)));
P_t(i)=P_t(i)-1+left(i);
else
[P_A(i) P_t(i)]=max(sigL(Q_t(i):left(i)));
P_t(i)=P_t(i)-1+left(i);
end
if S_t(i) < raight(i)
[T_A(i) T_t(i)]=max(sigL(S_t(i):raight(i)));
T_t(i)=T_t(i)-1+left(i)+47;
else
[T_A(i) T_t(i)]=max(sigL(raight(i):S_t(i)));
T_t(i)=T_t(i)-1+left(i)+47;
end
end
% compare two plots differently
subplot(211)
plot(t(1:length(Q_t)),Q_A,'*g',t(1:length(S_t)),S_A,'^k',t(1:length(R_t)),R_A,'ob',t(1:length(P_t)),P_A,'+b',t(1:length(T_t)),T_A,'+r');
subplot(212)
plot(t,sigL)
% title('Original Signal')
for i=1:((length(P_t))-1)
HRV=P_t(i+1)-P_t(i);
end
You need to use a condition to segregate data in lower to higher order in data arrays for which you add offsets .
참고 항목
카테고리
Help Center 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!