How to find peaks & eliminate flat tops

You have developed (or found) a complex program for peak detection which apparently does not work as desired.
Have you either a link for this or can you explain in words the technique you are attempting to use to do the peak detection.

I agree with the idea already expressed that a ready developed algorithm would be the easiest approach, but this denies you the learning effect of the selection of an appropriate method and coding it.

As a base line, this very simple sketch (untested) detects peaks and would work with the sample data you have given. It makes no attempt to determine a trend in the input stream so may yield false peaks.

// peak detection without filtering/smoothing

void setup()
{
  Serial.begin(9600);  // for debugging 
}

void loop() {
  static int sampleLast = 0 ;
  int sampleCurrent = analogRead( A0 ) ;
  if ( sampleCurrent < sampleLast ) {
     Serial.print( millis() ) ;
     Serial.print( "   " ) ;
     Serial.println( sampleLast ) ;
  }
  sampleLast = sampleCurrent ;
  delay(10) ;
}