Hello Mates,
I'm looking for a better way to detect peaks in a signal sample
The signal is a sinusoidal from VR sensor and tone ring wheel with 40 to 140 teeth, the output frequency is from 40 to 200Hz, this signal is then rectified (80 to 400Hz) and sampled in the uC ADC, 12bits, 0 to 5V.
The sample rate is adjusted so 1.2 revolutions of the tone ring can be captured. Usually the tone ring has 100 teeth and the algorithm finds 239 to 240 Peaks, which is correct
The current algorithm is pretty simple it basically looks for a number of consecutive signal samples which are bigger than the previous, if not the increments the "fall" counter, when the fall counter is a given number (8 by now) is the peak is saved to a array. As the sample rate is now 20 times the non rectified frequency the number 8 for the fall counter works just fine.
The thing is: this works but, I feel I need to make it better, I'd like to have this fall number self adjusted or to find a better and proven peak detection algorithm
Anyway, I'd like some suggestions from you guys
///////// SEARCH FOR SIGNAL PEAKS /////////
for(point=0; point<samples; point++)
{
if(buffer[point] > buffer[point-1])
{
fall = 0;
pointBuffer = point;
}
else
{
fall++;
if(fall == FALLS) //This FALLS constant is set to 8, I'd like it to be adjustable
{
if (peaks < expectedPeaks && firstPeak)
{//Make sure the array wont be overwritten
peakArray[peaks] = buffer[pointBuffer]; //Salva posição do pico
timeArray[peaks] = pointBuffer; //Salva tempo do pico na posição
peaks++;
}
firstPeak = 1; //Set first peak has passed already, save later peaks
if (peaks >= expectedPeaks)
{//Check for excessive readings
eturn(EXCESSIVE_PEAKS);
}
}
}
}