I am working on finding the peaks in ECGs. I have a couple of hundred of 1 hour readings but the problem is that some of them have them peaks inverted (so they are negative). The goal is to be able to find the peaks without having to visually inspect the files to determine if they are reversed or not. I want to find a way to either: i) to determine if the ECG is inverted. If it is inverted I can use -ecg and then find peaks or ii) find a way to determine peaks regardless if they are positive or negative.
I have already tried to use the 'skewness' to determine if the peaks are positive of or negative but I still get positive values in ECGs that I know are inverted so it does not work well for my data. I can not upload the data but here is a code that might help:
fs=1000;
t=[0:1/fs:3000];
x=zeros(length(t),1);
for i=1:5
x=x+i*sin(2*pi*2*i*t');
end
plot(t,x)
[peak loc]=findpeaks(x,'MinPeakProminence',12);
hold on
plot(t(loc), x(loc),'*r')
xlim([0 20])
hold off