function [data] = IncoherentDec(data, inc_avgs)
%-------------------------------%
% Perform Incoherent Decimation %
%-------------------------------%
% By: William Blake
% Date: 5/20/2009

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