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);
}
