function clip_seg = cntrclip(segments, k, silence)
%central clipping function
%function clip_seg = cntrclip(segments, k, silence)
%input  - matrix of samples
%output - matrix of center clipped samples

len = length(segments(:, 1));
[m n] = size(segments);
if m == len, rows = n;
else rows = m; end
han = hann(len);
clip_seg = zeros(len, rows);
if k ~= 0    
for i = 3:rows
level = k * min([max(abs(segments(:, i-2))) max(abs(segments(:, i)))]);
buff = segments(:, i-1);
buff(level < segments(:, i-1)) = 1;
buff(-level > segments(:, i-1)) = -1;
buff(level > abs(segments(:, i-1))) = 0;
if (level < silence), buff = zeros(len, 1);end
clip_seg(1:len, i-1) = han .* buff;
end
end