function Out = squareproduce(In,height,wwidth)

threshold = height;

risefall = 0;
counter = 1;
width = 0;
for i=1:length(In);
  if (risefall == 0) & (In(i) >= threshold)
    Squares(counter,1) = i;
    risefall = 1;
    width = 0;
  end
  if (risefall == 1) & (In(i) <= threshold) & (width >= wwidth)
    Squares(counter,2) = i;
    risefall = 0;
    counter = counter + 1;
  end
  width = width + 1;
end 

[m,n] = size(Squares);

for i = 1:m
  Squares(i,3) = mean(In(Squares(i,1):Squares(i,2)));
end

Out = zeros(1,length(In));

for i = 1:m
  Out(Squares(i,1):Squares(i,2)) = Squares(i,3);
end




