I have been trying to do ECG peak detection using TKEO in matlab and has done the same in matlab and has got results
Heres the code for it
% Passband frequency range in Hz
[b, a] = butter(4, fc/(fs/2), 'bandpass');
ecg_filtered = filter(b, a, ecg);
% Apply TKEO to enhance R-peaks
tkeo = ecg_filtered(2:end-1).^2 - ecg_filtered(1:end-2).*ecg_filtered(3:end);
% Apply moving average filter to smooth the TKEO signal
win_size = round(fs*0.15); % Window size in samples (0.15 seconds)
tkeo_smooth = movmean(tkeo, win_size);
% Find R-peak locations
[r_peaks_tkeo, r_locs_tkeo] = findpeaks(tkeo_smooth, 'MinPeakDistance', 50,'MinPeakHeight',mean(tkeo_smooth)); % 0.2 seconds between R-peaks
r_locs_tkeo_updated = r_locs_tkeo+3;
figure;
plot(t, ecg_filtered);
xlim([0 10])
title('Filtered ECG')
xlabel('Time(Sec)')
ylabel('Amplitude')
But Now I would like to do the same realtime using simulink and arduino.
I have done the filtering using Butterworth filter part in Simulink using Digital filter design block.
But I dont know how to implement the TKEO Block so that I would get R peaks.
Kindly Help Me Out
Thank You in Advance