function [peaks,mn,r] = PeakDetection3(ref,fs,h,th,fmax,goodint) % My changes to this code: adding the intmax input which checks if any % interval of the input signal has anomalies. If yes, that part is not counted % when calculating the th*max(r) margin. % peaks = PeakDetection3(x,fs,h,th,fmax), % R-peak detector based on a matched filter % % inputs: % x: vector of input data % fs: sampling rate % h: template waveform % th: detection threshold % fmax: maximum expected frequency of the R-peaks % % output: % peaks: vector of R-peak impulse train % % % Open Source ECG Toolbox, version 2.0, March 2008 % Released under the GNU General Public License % Copyright (C) 2008 Reza Sameni % Sharif University of Technology, Tehran, Iran -- GIPSA-Lab, INPG, Grenoble, France % reza.sameni@gmail.com % This program is free software; you can redistribute it and/or modify it % under the terms of the GNU General Public License as published by the % Free Software Foundation; either version 2 of the License, or (at your % option) any later version. % This program is distributed in the hope that it will be useful, but % WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General % Public License for more details. if nargin==6 nblocks=length(goodint); else goodint=1; nblocks=1; end N = length(ref); blocksize=N/nblocks; goodind=zeros(1,N); for i=1:nblocks goodind((i-1)*blocksize+1:i*blocksize)=goodint(i)*ones(1,blocksize); end L = length(h); h = h(end:-1:1); w = floor(L/2); r = filter(h,1,[ref zeros(1,w-1)]); r = r(w:N+w-1); r(r