function avg = doodsonX0(dat)
%
%doodsonX0(data)
% 
% Running Avgerage on data of using Doodson X0 filter.
% Filter weights are designed to remove the main tidal
% consituents of hourly data. Filter is 39 points long
% and so both the first and last 19 points of 'avg' are
% made into NaNs.
%
% Filter found here: http://www.pol.ac.uk/ntslf/acclaimdata/gloup/doodson_X0.html

X0 = [1 0 1 0 0 1 0 1 1 0 2 0 1 1 0 2 1 1 2 0 2 1 1 2 0 1 1 0 2 0 1 1 0 1 0 0 1 0 1]'/30;

% calculate average
avg = conv2(dat, X0, 'same');
avg(1:19) = NaN; avg(end-18:end) = NaN;
