function [filtered_data]=sliding_averaging(data,Fs,time_window,percent,ws,av_time)


lwin=Fs*time_window
numoverlap=lwin*percent;
non_re_use=lwin-numoverlap;
data_mean=[];
data_var=[];
data_prime=NaN*ones(size(data));
u_along_prime=[];
u_cross_prime=[];
std_ualong=[];
std_ucross=[];
mean_ualong_prime=[];
mean_ucross_prime=[];
k = fix((length(data)-numoverlap)/(lwin-numoverlap))
if  nargin < 5
    for i=1:k
        data_mean=[data_mean;nanmean(data(1+(i-1)*non_re_use :(i-1)*non_re_use+lwin))];
        data_var=[data_var;var(data(1+(i-1)*non_re_use :(i-1)*non_re_use+lwin))];
        data_prime(1+(i-1)*non_re_use :(i-1)*non_re_use+lwin)=data(1+(i-1)*non_re_use :(i-1)*non_re_use+lwin)-nanmean(data(1+(i-1)*non_re_use :(i-1)*non_re_use+lwin));
    end
    
    
    
else
    for i=1:k
        temp_wd=data(1+(i-1)*non_re_use :(i-1)*non_re_use+lwin);
        temp_ws=ws(1+(i-1)*non_re_use :(i-1)*non_re_use+lwin);
        [u,v]=wind_decomposition(temp_wd, temp_ws);
        u_mean=nanmean(u);
        v_mean=nanmean(v);
        [temp_mean]=wind_direction_deg(u_mean,v_mean, 1,1);
        data_mean=[data_mean;temp_mean];
        [ualong_inst, ucross_inst]=along_cross(temp_ws,temp_wd,temp_mean);
        u_along_prime=[u_along_prime;(ualong_inst-nanmean(ualong_inst))'];
        u_cross_prime=[u_cross_prime;(ucross_inst-nanmean(ucross_inst))'];
        std_ualong=[std_ualong;nanstd(ualong_inst)];
        std_ucross=[std_ucross;nanstd(ucross_inst)];
        mean_ualong_prime=[mean_ualong_prime;(nanmean((ualong_inst-nanmean(ualong_inst)).^2))'];
        mean_ucross_prime=[mean_ucross_prime;(nanmean((ucross_inst-nanmean(ucross_inst)).^2))'];

    end
end



% filtered_data.mean=data_mean;
% filtered_data.var=data_var;
filtered_data=data_var;
