我们使用matlab来分析我们心脏病患者的hrv结果。我们能够得到我们需要的波形但是它在代码行67中显示错误。请帮助。
x1 = load('ecg3.dat');
x2=x1; fs = 1000; % Sampling rate
N = length (x2); % Silength
t = [0:N-1]/fs; % tiidx
figure(1)
subplot(2,1,1)
plot(t,x1)
xlabel('second');ylabel('Volts');title('Input ECG Signal')
% Cancellation DC drift and normalization
x1 = x1 - mean (x1 ); % cancel DC conponents
x1 = x1/ max( abs(x1 )); % normalize to one
subplot(4,1,2)
plot(t,x1)
xlabel('second');ylabel('Volts');title(' ECG Signal after cancellation DC drift and
normalization')
% Low Pass Filtering
b=[1 0 0 0 0 0 -2 0 0 0 0 0 1]; a=[1 -2 1];
h_LP=filter(b,a,[1 zeros(1,12)]); % transfer function of LPF
x2 = conv (x1 ,h_LP);
x2 = x2 (6+[1: N]); %cancel delay
x2 = x2/ max( abs(x2 )); % normalize , for convenience .
subplot(4,1,3)
plot([0:length(x2)-1]/fs,x2)
xlabel('second');ylabel('Volts');title(' ECG Signal after LPF')
xlim([0 max(t)])
% High Pass Filtering
b = [-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 -32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1];
a = [1 -1];
h_HP=filter(b,a,[1 zeros(1,32)]); % impulse response of HPF
x3 = conv (x2 ,h_HP);
x3 = x3/ max( abs(x3 ));
subplot(4,1,4)
plot([0:length(x3)-1]/fs,x3)
xlabel('second');ylabel('Volts');title(' ECG Signal after HPF')**LINE67**
xlim([0 max(t)])
% Derivative Filter
% Make impulse response
h = [-1 -2 0 2 1]/8;
% Apply filter
x4 = conv (x3 ,h);
x4 = x4 (2+[1: N]);
x4 = x4/ max( abs(x4 ));
figure(2)
subplot(4,1,1)
plot([0:length(x4)-1]/fs,x4)
xlabel('second');ylabel('Volts');title(' ECG Signal after Derivative')
% Squaring
x5 = x4 .^2;
x5 = x5/ max( abs(x5 ));
subplot(4,1,2)
plot([0:length(x5)-1]/fs,x5)
xlabel('second');ylabel('Volts');title(' ECG Signal Squarting')
% Moving Window Integration
% Make impulse response
h = ones (1 ,31)/31;
Delay = 15; % Delay in samples
% Apply filter
x6 = conv (x5 ,h);
x6 = x6 (15+[1: N]);
x6 = x6/ max( abs(x6 ));
subplot(4,1,3)
plot([0:length(x6)-1]/fs,x6)
xlabel('second');ylabel('Volts');title(' ECG Signal after Averaging')
% Find QRS Points Which it is different than Pan-Tompkins algorithm
max_h = max(x6);
thresh = mean (x6);
poss_reg =(x6>thresh*max_h)';
left = find(diff([0 poss_reg'])==1);
right = find(diff([poss_reg' 0])==-1);
left=left-(6+15); % cancel delay because of LP and HP
right=right-(6+15);% cancel delay because of LP and HP
left=abs(left);
right=abs(right);
for i=1:length(left)
[R_value(i) R_loc(i)] = max( x1(left(i):right(i)) );
R_loc(i) = R_loc(i)-1+left(i); % add offset
[Q_value(i) Q_loc(i)] = min( x1(left(i):R_loc(i)) );
Q_loc(i) = Q_loc(i)-1+left(i); % add offset
[S_value(i) S_loc(i)] = min( x1(left(i):right(i)) );
S_loc(i) = S_loc(i)-1+left(i); % add offset
end
subplot(4,1,4)
plot (t,x1,t(R_loc) ,R_value , 'r^')
% there is no selective wave
Q_loc=Q_loc(find(Q_loc~=0));
R_loc=R_loc(find(R_loc~=0));
S_loc=S_loc(find(S_loc~=0));
values=x2(R_loc);
% 1 beat/sec x 60 sec/min = 60 beats/min.
%%R-R interval using diffrence operation method
tiscl=t(2)-t(1);
px=diff(R_loc);
d_tms=find(diff(R_loc)>200);
d_men=mean(px(d_tms));
beat=d_men*tiscl;
heart_rate=1/beat*60;
fprintf('%2.1f seconds/beat\n',beat);
rs=sprintf('Heart Rate= %2.1f beats per minit \n',heart_rate);
**
???使用==>错误horzcat
CAT arguments dimensions are not consistent. Error in ==> Untitled at 67 left = find(diff([0 poss_reg']) ==1);
**
这是收到的错误信息是在子图(4,1,4),不知道如何纠正这一点 错误。因为我们的项目暂停,所以请帮忙。
答案 0 :(得分:0)
错误消息与"无关。子图(4,1,4)"。 [0 poss_reg']
是造成错误的原因。 horzcat
表示"水平连接",这是您尝试在那里做的事情。但是,poss_reg'
可能是一个列。因此,您无法将其水平连接为零。 (有关详细信息,请参阅help horzcat
。)
如果您不确定是否要使用行或列向量,则可以使用(:)强制列方向并vertcat
:
[0; poss_reg(:)]
更一般地说,您应该使用dbstop if error
或其他MATLAB调试工具,并在发生错误时检查变量的大小和类型。
答案 1 :(得分:0)
尝试:
left = find(diff([0; poss_reg],1,1)==1); % remember to zero pad at start
right = find(diff([poss_reg; 0],1,1)==-1); % remember to zero pad at end
祝你好运!