function [data] = CoherentDec(data, coh_avgs)
%-------------------------------%
% Perform Coherent Decimation   %
%-------------------------------%
% By: William Blake
% Date: 5/20/2009

siz = size(data);
if siz(1) == 1
    new_len     = floor(siz(2)/coh_avgs);
    nearest_len = floor(siz(2)/coh_avgs)*coh_avgs;
    data        = mean(reshape(data(1:nearest_len),coh_avgs,new_len));
elseif siz(2) == 1
    new_len     = floor(siz(1)/coh_avgs);
    nearest_len = floor(siz(1)/coh_avgs)*coh_avgs;
    data        = mean(reshape(data(1:nearest_len),new_len,coh_avgs));
else
    new_len     = floor(siz(2)/coh_avgs);
    nearest_len = floor(siz(2)/coh_avgs)*coh_avgs;
    data        = reshape(mean(reshape(data(:,1:nearest_len), ...
                         [siz(1) coh_avgs new_len]),2),[siz(1) new_len]);
end
