function output=interpolate_with_smoothing(input) 
%input is vector with actual data points as endpoints and interpolated values, which will be smoothed, in between
%called by analyze_sd_over_time

if length(input)<4, error('input too short'),end    % (situations with 0 or 1 intermediate value should not be modified)

interpolated=input(2:end-1);

%excluding the middle
length_interpolated=length(interpolated);
if length_interpolated==2,
    lower_half=2;upper_half=3;
else
	median_length_interpolated=median([1:length_interpolated]);
	lower_half=1+[1:(floor(median_length_interpolated)-1)];
	upper_half=1+[(ceil(median_length_interpolated)+1):length_interpolated];
end

output=input;

m=length(lower_half); n=1;
for iii=lower_half(1):lower_half(end)
    output(iii)=(m*input(1)+n*input(iii))/(m+n);
    m=m-1;n=n+1;
end

p=1;q=length(upper_half);
for jjj=upper_half(1):upper_half(end)
    output(jjj)=(p*input(end)+q*input(jjj))/(p+q);
    p=p+1;q=q-1;
end