function [ChunkBeatVec] = genOTHRchunks(ecgSig, Rpeaks, VM)

RpeaksChunk = Rpeaks.*VM;
totalBeats = sum(RpeaksChunk);
rind = find(RpeaksChunk == 1);

diffR = diff(rind);

%% diff greater than 250

rind1 = rind;

id1 = find(rind<66);
id2 = find(rind+100>length(ecgSig));
remId = unique([id1; id2]);
rind1(remId) = [];

beatVec = [];
for ind = 1:length(rind1)
    bv = ecgSig(rind1(ind)-65:rind1(ind)+100);
    beatVec(:,ind) = bv;%resample(bv, 200, length(bv));
end

ChunkBeatVec = [];
if(numel(beatVec)~=0)
    L = size(beatVec,2);
    if(L>30)
        ChunkBeatVec(:,1) =  median(beatVec(:,1:round(3*L/7)),2);
        ChunkBeatVec(:,2) =  median(beatVec(:,round(2*L/7):round(5*L/7)),2);
        ChunkBeatVec(:,3) =  median(beatVec(:,round(4*L/7):L),2);
    elseif(L>8)
        ChunkBeatVec(:,1) = median(beatVec,2);
    end
end
end