The code works but the values don't match and I can't find the error

1 次查看(过去 30 天)
The code is the following and its objective is to obtain the coordenates of peaks od the signal FINAL whose graphic is attached.
However the values don't match and I can't find the problem .
Can someone help?
clear
clc
ID = 1;
sinal = read_ecg_txt (ID);
Unrecognized function or variable 'read_ecg_txt'.
filtrado = remove_noise(sinal,101);
FINAL = Remove_noise2(filtrado,20);
k = 500;
limiar = 300;
L = length(FINAL);
Picos = [];
a = (k-1)/2;
t = 1;
for i = 1:k:L
if i<(ceil(a))
for q = 1:k
maximo = 0;
if FINAL(q) > maximo
maximo = FINAL(q);
M = q;
end
end
Picos(t,1) = maximo;
Picos(t,2) = M;
t = t + 1;
elseif i>(L-(floor(a)))
for q = (L - k):L
maximo = 0;
if FINAL(q) > maximo
maximo = FINAL(q);
M = q;
end
end
Picos(t,1) = maximo;
Picos(t,2) = M;
t = t + 1;
else
for q = (i-(ceil(a))):(i + (floor(a)))
maximo = 0;
if FINAL(q) > maximo
maximo = FINAL(q);
M = q;
end
end
Picos(t,1) = maximo;
Picos(t,2) = M;
t = t + 1;
end
end
m = 1;
Peaks = [];
for p = 1:(t-1)
if Picos(p,1) > limiar
Peaks(m,1) = Picos(p,1);
Peaks(m,2) = Picos(p,2);
m = m + 1;
end
end
  2 个评论
Inês Silva
Inês Silva 2023-1-19
Also the variables ID, k and limiar are supposed to be inputs , for rigth now I'm just having them as fixed values since is easier to try and find the problem that way

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2023-1-19
移动:Walter Roberson 2023-1-22
read_ecg_txt() remove_noise() Remove_noise2() are missing
for q = 1:k
maximo = 0;
if FINAL(q) > maximo
maximo = FINAL(q);
M = q;
end
Resetting maximo = 0 each iteration of the loop is suspicious.
Consider using
[maximo, M] = max(FINAL(1:k));
with no loop.
  1 个评论
Inês Silva
Inês Silva 2023-1-20
移动:Walter Roberson 2023-1-22
But thank you , because of your comment about the fact that the maximum was resetting with ever loop interation, which was something I hadn't realised , I managed to find and fix the problem.

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by