function [out,avglist] = seasrem(data,period)

if period > length(data)/2
    disp(['period must be not bigger than ' num2str(floor(length(data)/2))])
    break;
end;
avglist =[];
fit = zeros(1,length(data));
for i=1:period
    ind=[i:period:length(data)];
    ind = ind(find(data(ind)~=0));
    curravg=mean(data(ind));
    avglist = [avglist curravg];
    fit(ind)=curravg;
    out(ind)=data(ind)-curravg;
end;
%figure;
%plot(data);
%hold on;
%plot(out,'r');
%plot(fit,'green');
%legend('orig. data','season removed','fit');
%hold off;