Single Sample Output from Peak-Picking Algorithm

  • Follow


Hi there,

 I am in the process of developing a beat detection algorithm in c++. At
the moment the peak picking algorithm selects all samples higher than a
specified threshold and outputs them as a '1'. However, for purposes of
testing I only want a single sample output of 1, instead of a stream of
samples that are over the threshold, when a peak is detected. 

I know it should be really simple but all the methods I've tried have
given errors. I was wondering if any of you guys might be able to give some
pointers on a solution to the problem.

Here's the code from the process loop: 
 		
while (nSampleFrames-- > 0) {
		
   Float32 inputSample = *sourceP;
   float   EnvIn       = fabs(inputSample);
		
   if (Envelope < EnvIn) {
      Envelope *= ga;
      Envelope += (1-ga)*EnvIn;
   }

   else {
      Envelope *= gr;
      Envelope += (1-gr)*EnvIn;
   }
		
   sourceP += inNumChannels;	
   Float32 outputSample;
			
   if (Envelope > Threshold) {
      outputSample = 1;		
   }
			
   else {
      outputSample = 0;
   }
			
   *destP = outputSample;
   destP += inNumChannels;
}

Thanks in advance,
J


0
Reply white.joe4 (2) 9/17/2009 2:07:36 PM

bool insidePeak = false;

while (nSampleFrames-- > 0) {
   // ...
   if (Envelope > Threshold) {
      outputSample = !insidePeak;
      insidePeak = true;
   }
   else {
      outputSample = 0;
      insidePeak = false;
   }
   
   *destP = outputSample;
   destP += inNumChannels;
}


Martin

-- 
Quidquid latine scriptum est, altum videtur.
0
Reply martin.eisenberg (676) 9/18/2009 10:32:44 AM


>bool insidePeak = false;
>
>while (nSampleFrames-- > 0) {
>   // ...
>   if (Envelope > Threshold) {
>      outputSample = !insidePeak;
>      insidePeak = true;
>   }
>   else {
>      outputSample = 0;
>      insidePeak = false;
>   }
>   
>   *destP = outputSample;
>   destP += inNumChannels;
>}
>
>
>Martin
>
>-- 
>Quidquid latine scriptum est, altum videtur.


Thanks so much Martin!!!

0
Reply white.joe4 (2) 9/18/2009 1:05:32 PM

On Sep 18, 8:05=A0am, "whitej" <white.j...@gmail.com> wrote:
> >bool insidePeak =3D false;
>
> >while (nSampleFrames-- > 0) {
> > =A0 // ...
> > =A0 if (Envelope > Threshold) {
> > =A0 =A0 =A0outputSample =3D !insidePeak;
> > =A0 =A0 =A0insidePeak =3D true;
> > =A0 }
> > =A0 else {
> > =A0 =A0 =A0outputSample =3D 0;
> > =A0 =A0 =A0insidePeak =3D false;
> > =A0 }
>
> > =A0 *destP =3D outputSample;
> > =A0 destP +=3D inNumChannels;
> >}
>
> >Martin
>
> >--
> >Quidquid latine scriptum est, altum videtur.
>
> Thanks so much Martin!!!- Hide quoted text -
>
> - Show quoted text -

If you're truly looking for a peak in the waveform, here's another
method.  Look at the slope of the waveform.  The peak occurs when the
slope reverses direction (sign).  Plus to minus means a positive peak,
while minus to plus means a negative peak.  If there is not a lot of
noise on the signal, the slope is merely X(n) - X(n-1).  If there is,
use some method to negate the effect of the noise then apply the
difference.


Maurice Givens
0
Reply maury001 (237) 9/18/2009 3:44:05 PM

maury001@core.com wrote:
> On Sep 18, 8:05 am, "whitej" <white.j...@gmail.com> wrote:
>>> bool insidePeak = false;
>>> while (nSampleFrames-- > 0) {
>>>   // ...
>>>   if (Envelope > Threshold) {
>>>      outputSample = !insidePeak;
>>>      insidePeak = true;
>>>   }
>>>   else {
>>>      outputSample = 0;
>>>      insidePeak = false;
>>>   }
>>>   *destP = outputSample;
>>>   destP += inNumChannels;
>>> }
>>> Martin
>>> --
>>> Quidquid latine scriptum est, altum videtur.
>> Thanks so much Martin!!!- Hide quoted text -
>>
>> - Show quoted text -
> 
> If you're truly looking for a peak in the waveform, here's another
> method.  Look at the slope of the waveform.  The peak occurs when the
> slope reverses direction (sign).  Plus to minus means a positive peak,
> while minus to plus means a negative peak.  If there is not a lot of
> noise on the signal, the slope is merely X(n) - X(n-1).  If there is,
> use some method to negate the effect of the noise then apply the
> difference.

What does "peak" mean when there are few samples per cycle? A digital 
peak detector for AM rarely represents the envelope well.

Jerry
-- 
Engineering is the art of making what you want from things you can get.
�����������������������������������������������������������������������
0
Reply jya (12866) 9/18/2009 6:08:10 PM

4 Replies
21 Views

(page loaded in 0.08 seconds)


Reply: