1

I am a no math guru here, so I want to ask anyone familiar with Digital Signal Processing, what is the best way of detecting real time peaks. I get about 30 frames/values a second and I've tried to implement the slope algorithm for detecting peaks, it worked OK, about 80% of the cases, but its really not good enough :(.

From what I've searched one should use the Fast Fourier Transform, but I have no idea how to get started with it, perhaps I'm missing the general idea of how I should use FFT in this case.

In iOS we have this amazing Accelerate framework that should help me do the FFT stuff but as long as I dont get the general idea its pretty much useless to me.

Can anyone enlighten me somehow by pointing me in the right direction :-) ?

Thanks a lot, and Happy New Year !

Andy
  • 376
  • 4
  • 19
  • 1
    What's your input here, an audio signal? By peak, do you mean a point of maximum volume in this input? – Brad Larson Jan 02 '13 at 17:28
  • Brad, actually you wont believe it :D my input is basically the light value from the iPhone camera, its just a float. And by peak I mean the max value(a beat), I'm writing a heart beat detector (weekend project :] ). The funny thing is that I'm using your GPUImage library which is AWESOME ! :) – Andy Jan 02 '13 at 17:54
  • 2
    FFT will not help you here. – Bjorn Roche Jan 02 '13 at 18:35
  • 1
    @Andy - Dealing with average luminance from the camera can be a little tricky, because I've found that the automatic gain and white balance settings of the iOS cameras tend to adjust things so that the image almost always has a 50% luminance. This might make it harder to pick out peaks and valleys, but a heart beat might be fast enough to outpace the camera gain and exposure adjustments. – Brad Larson Jan 02 '13 at 19:54
  • @BradLarson mmmm, I could change it only to the Red channel, but from what I saw, the values are pretty good. – Andy Jan 02 '13 at 20:13

1 Answers1

2

So you have a float array of camera light values generated every second that contains 30 samples. You want to know what is the peak value per second? Or ever? To calculate the maximum value in a vector using accelerate you can use the vDSP_maxv function.

Or are you trying to detect all of the peaks above a given threshold per second? In that case you can generate a vector containing the threshold value that is the same length as the vector to search peaks. Then you can use the vDSP_vmax function to find all values above this threshold.

If this is not good enough, there are many more sophisticated techniques for finding peaks in time series, some simple ones are discussed here:

Peak Detection in Time Series

I would probably try something like calculating the gradient and looking for 0 crossings with vDSP_nzcros.

Community
  • 1
  • 1
Tark
  • 5,153
  • 3
  • 24
  • 23
  • Yep, I have 30 samples per second, but I'm keeping them in an array and only release the values after I detect one beat, or if no beat was detected I just add the new values at the end of the array, and I delete the old ones(same number of values that where added) from the beginning. Basicaly I have to store enough values in memory as I would need for real time beat detection. I'm going to look into the vDSP_maxv and see what I can figure out there. Thanks ! – Andy Jan 02 '13 at 18:11