Borrar filtros
Borrar filtros

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

5 visualizaciones (últimos 30 días)
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 comentarios
Inês Silva
Inês Silva el 19 de En. de 2023
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

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de En. de 2023
Movida: Walter Roberson el 22 de En. de 2023
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 comentario
Inês Silva
Inês Silva el 20 de En. de 2023
Movida: Walter Roberson el 22 de En. de 2023
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Single-Rate Filters en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by