added the same algorithm in the middle part when it searches in smaller intervals, so it takes the mean out of two max values

For the next thing i should be able to remove the outlayers (noise) and
set them to 0