D = load('cu01m.mat');
EKG = D.val;
figure
plot(EKG)
grid
xlim([0 1000])
Fs = 250;
Fn = Fs/2;
Ts = 1/Fs;
t = linspace(0, numel(EKG), numel(EKG))/Fs;
Wp = [2 90]/Fn;
Ws = [1 100]/Fn;
Rp = 1;
Rs = 50;
[n,Wp] = ellipord(Wp, Ws, Rp, Rs);
[z,p,k] = ellip(n, Rp, Rs, Wp,'bandpass');
[sos,g] = zp2sos(z,p,k);
figure
freqz(sos,2^16,Fs)
filtered_EKG = filtfilt(sos,g,EKG);
[lmn,npr] = islocalmin(filtered_EKG, 'MinProminence',100);
lnix = find(lmn);
prqs = npr(lnix);
[lmx,xpr] = islocalmax(filtered_EKG, 'MinProminence',500);
lxix = find(lmx);
prr = xpr(lxix);
figure
plot(t, EKG)
grid
xlim([0 5])
figure
plot(t, filtered_EKG)
grid
xlim([0 5])
figure
plot(t, filtered_EKG)
hold on
plot(t(lxix), filtered_EKG(lxix), 'r^')
plot(t(lnix), filtered_EKG(lnix), 'gv')
hold off
grid
xlim([0 5])
figure
plot(t, EKG)
hold on
plot(t(lxix), EKG(lxix), 'r^')
plot(t(lnix), EKG(lnix), 'gv')
hold off
grid
legend('EKG', 'R', 'Q S')
xlim([0 5])
Best Answer