function aBin = avgBinWin(folder,frequency,siz)

fnames = dir([folder '/*.20*']);
numFiles = length(fnames);
N = frequency*24;
f1 = fnames(1).name;
avgFldr = [folder '/' num2str(frequency) '_day_averages'];
eval(['mkdir ' avgFldr]);
tot = [];

w = genHamming(N)';
wSum = sum(w);

for ii = 1 : siz(1)
    for jj = 1 : siz(2)
        
        ww(ii,jj,1:N) = w;
        
    end
end

for ii = 1 : numFiles % each file is 1 hr apart
    fnam = [folder '/' fnames(ii).name];
    fld = readbin(fnam,siz);
    
    s = size(tot);
    
    if ii > 2 && s(3) >= frequency*24
        tot = circshift(tot,[0 0 1]);
        tot(:,:,1) = fld;
    else
        tot = cat(3,tot,fld);
    end
    
    if mod(ii,12) == 0 && ii >= N
        
        avgBin = sum(ww.*tot,3)./wSum;
        
        fileName = [avgFldr '/' num2str(frequency) 'day_' f1];
        writebin(fileName,avgBin);
        
        f1 = fnames(ii+1).name;
        
    end
    
end

end