How to find local maximums

I am using a pulse sensor to replicate a heartbeat sound. To do so I am storing samples to an Array which I will use later to find its corresponding pitch. So far I get the highest max or global maxima but I need to also find the other local maximas near. I will attach an image of more or less what I am seeing and what exactly is getting sampled and stored into the array. The samples are the dots but x200+ more and the three lines are basically the maximas I need to retrieve.

#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft
#include <FFT.h> // include the library

void setup()
{
  Serial.begin(9600);  // for debugging
  ADCSRA = 0xe5; // set the adc to free running mode
  ADMUX = 0x40; // use adc0
  DIDR0 = 0x01; // turn off the digital input for adc0
}
void loop()
{
    int i;
    for (i = 0 ; i < 256 ; i ++) { // save 256 samples
      while(!(ADCSRA & 0x10)); // wait for adc to be ready
      ADCSRA = 0xf5; // restart adc
      byte m = ADCL; // fetch adc data
      byte j = ADCH;
      int k = (j << 8) | m; // form into an int
      k -= 0x0200; // form into a signed int
      k <<= 6; // form into a 16b signed int
      fft_input[i] = k; // put real data into even bins
      //fft_input[i+1] = 0; // set odd bins to 0
      delay(5);  // dt = 5ms
    } // close for
    
    int max_v = 0;
    int max_i = 0;
    
    for ( int i = 0; i < 256; i++ )
    {
     if ( fft_input[i] > max_v )
      {
       max_v = fft_input[i];
       max_i = i;             
      }          
   }// End for

  Serial.println(max_v);
  delay(100);
}

Screen Shot 2017-10-18 at 8.45.15 PM.png

Google "peak detection algorithms" for lots of ideas. Your simple approach won't work for noisy data.

Note: if you ever do use the FFT algorithm, it is a serious mistake to comment out this line.

      //fft_input[i+1] = 0; // set odd bins to 0

Assuming your signal is perfectly clean and well-behaved

for (x=1, x< array_length-1; x++) {
    if ((array[x-1] < array[x])  &&  (array[x+1]<array[x])) {
       // local maximum
    };
     if ((array[x-1] > array[x])  &&  (array[x+1]>array[x])) {
       // local minimum
    };
   
}

but more likely

delta=0.1; // adjust as necessary
for (x=1, x< array_length-1; x++) {
    if ((array[x]-array[x-1] >delta )  &&  (array[x]-array[x+1] >delta) {
       // local maximum
    };
    if ((array[x]-array[x-1] >-delta )  &&  (array[x]-array[x+1] >-delta) {
       // local minimum
    };
}

I need to find the other local maximums like in the image I attached not just the one max..

rogernm001:
I need to find the other local maximums like in the image I attached not just the one max..

What was the result of following the advice given to you in reply #1?