Method to count pulse rates?

72 views
Skip to first unread message

Adam Stuckert

unread,
Feb 13, 2015, 10:36:16 AM2/13/15
to see...@googlegroups.com
Hi all,

I'm hoping you can help with a small question I have.  I'm new to R, so hopefully this isn't a silly question.  I'm analyzing frog calls, and I'm trying to incorporate some measure of individual pulses within calls.  It would be best if I could use a bit of code to do this automatically, as everything else is automatic (when my computer can handle it that is).  

Any ideas on how to do this? I've attached an oscillogram of a single call to indicate what the pulses look like.  I can upload a .wav later if that helps too.

Thanks in advance!
Adam

PS. Many thanks to Jerome for a great package!
pulses.tiff

Jerome Sueur

unread,
Feb 16, 2015, 6:51:24 AM2/16/15
to see...@googlegroups.com
Dear Adam,

This is not an easy task but this would be very useful indeed...

The idea could be to work on a smoothed version of the Hilbert transform (function env()) and then to adapt the function fpeaks() to time by detecting main peaks of the envelope. Unfortunately I have currently  not the time to do this.

Best regards,

Jerome
--
You received this message because you are subscribed to the Google Groups "seewave" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seewave+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

krzysztof...@inserm.fr

unread,
Feb 17, 2015, 3:19:22 AM2/17/15
to see...@googlegroups.com

Hello Adam,

What exactly do you need to know: just the time of each pulse/peak or its duration as well - the latter is more difficult, more so if starts and ends overlap.

For peak detection (thence timing) there is the package "Peaks" in R which includes Markov smoothing procedures. I may be wrong but I think the main smoothing obtained with the Hilbert transform is just because a window of n samples is used for the transform. From your spectrogram, Markov smoothing over a much shorter window (n < 10) could be simpler and with higher precision,

For determining the beginning and ends (peak width), I was unsuccessful when looking for suitable existing code (R or C++) for noisy data and had to set about it myself (work in progress - sorry!). The simplest, which may be all you need, would be measures of when each pulse passes above/below a given faction of the peak height.I don't know of a package for doing that though.

Krzysz

--
pulses.tiff

Kevin Darras

unread,
Feb 18, 2015, 2:11:13 AM2/18/15
to see...@googlegroups.com
Dear Adam,
I needed to do the same (or something similar): to detect chirps (or pulses) in a particular frequency band. First I filtered the signal to get rid of any extraneous disturbing frequencies, then I ran the following function, adapted from the peaks function:

amppeaks=function(wave, f, threshold=1.2, plot = TRUE
                  , smooth = 3000, col = 2, cex = 1, symbol = ".",clip.value=7.5,...)
{
  input <- inputw(wave = wave, f = f)
  f <- input$f
  smoothenv <- env(input$w,ssmooth=smooth,f,plot=F)
  rm(input)
  loc.max <- which(smoothenv > threshold*mean(smoothenv))
  amp <- smoothenv[loc.max]
  if (is.na(mean(amp))) {clipped=0;amp=0;loc.max=0} else if (mean(amp)<clip.value) {clipped=0} else {clipped=1}
  if (plot) {
    plot(smoothenv~c(1:length(smoothenv)/f), type="h",ylab="amplitude",xlab="time (seconds)")
    text(x = loc.max/f, y = max(smoothenv), labels = symbol, cex = cex, col = col)
  }
  return(data.frame(val = amp, loc = (loc.max/f), clipped = clipped))
}

For the moment the parameters (threshold and smooth) are tuned to my specific problem, but I believe it will work well for your problem too. I rarely had to correct manually. It also detects whether the signal is clipped (clip.value=7.5 worked in my case).
Actually I sent this function to Jérôme but he said a better one written by one of his students would be included later in Seewave.
Best,
Kevin

Jerome Sueur

unread,
Feb 18, 2015, 4:27:39 AM2/18/15
to see...@googlegroups.com
Yes, you are right Kevin but the function is not ready yet...! and I have to say I do not know when it will be ready... I am therefore relieved to know that your function works for your needs and I really hope it can be useful to anyone else as well. Thanks for sharing on the list.

If I am not wrong your function is a threshold function not exactly a peak detection function.

Jerome
--
You received this message because you are subscribed to the Google Groups "seewave" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seewave+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
Muséum national d'Histoire naturelle
Institut Systématique, Evolution, Biodiversité
UMR 7205 CNRS-MNHN-UPMC-EPHE
45 rue Buffon
75005 Paris- France
http://isyeb.mnhn.fr/SUEUR-Jerome
##
International Society of Ecoacoustics
https://sites.google.com/site/ecoacousticssociety/
Reply all
Reply to author
Forward
0 new messages