Azzera filtri
Azzera filtri

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

5 visualizzazioni (ultimi 30 giorni)
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 Commenti
Inês Silva
Inês Silva il 19 Gen 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

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 19 Gen 2023
Spostato: Walter Roberson il 22 Gen 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 Commento
Inês Silva
Inês Silva il 20 Gen 2023
Spostato: Walter Roberson il 22 Gen 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.

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by