Effacer les filtres
Effacer les filtres

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

5 vues (au cours des 30 derniers jours)
Inês Silva
Inês Silva le 19 Jan 2023
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 commentaires
Inês Silva
Inês Silva le 19 Jan 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
Inês Silva
Inês Silva le 20 Jan 2023
The problem is that I can't use max

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 19 Jan 2023
Déplacé(e) : Walter Roberson le 22 Jan 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 commentaire
Inês Silva
Inês Silva le 20 Jan 2023
Déplacé(e) : Walter Roberson le 22 Jan 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Single-Rate Filters dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by