function [tpk,pk,tpk2,pk2]=pkFind(t,p,thresh,thresh2,MPP,MPD)


if exist('MPD','var')
    [pks,locs] = findpeaks(p,'MinPeakProminence',MPP,'MinPeakDistance',MPD);
    findpeaks(p,'MinPeakProminence',MPP,'MinPeakDistance',MPD);
elseif exist('MPP','var')
    [pks,locs] = findpeaks(p,'MinPeakProminence',MPP);
    findpeaks(p,'MinPeakProminence',MPP);
else
    [pks,locs] = findpeaks(p);
end

ind=find(pks>thresh);

tpk=t(locs(ind));
pk=pks(ind);

ind=find(and(pks<=thresh,pks>thresh2));
tpk2=t(locs(ind));
pk2=pks(ind);





