How to determine ime between pulses that exceed a threshold

Audio software developers forum.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
ride4funfl
Posts: 2
Joined: Mon Nov 24, 2014 5:18 pm
Operating System: Please select

How to determine ime between pulses that exceed a threshold

Post by ride4funfl » Mon Nov 24, 2014 5:40 pm

I am creating a sound sample that generated by a breaking a beam of light (a photogate system). The sample is generally low noise centered around 0db and a pulse (or close grouping of multiple pulses of various amplitudes) when light beam is broken. The pulse general varies based on the light intensity. I want to find the wall clock time between the subsequent pulses. I reworked the Find Peak Finder plug-in and the Beat Finder plug-in with some success. Does anyone know of a plug-in that might be close to the analysis I am looking for?

For example, on first pulse start timer and ignore samples for certain amount of time. Then find next pulse to stop timer and label pulse with time lag between previous pulse and this one. Repeat basic process for all other pulses. At each pulse I'd like ot label with local time, elapse time since previous pulse (or since start time), and pulse amplitude.

steve
Site Admin
Posts: 48333
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: How to determine ime between pulses that exceed a thresh

Post by steve » Mon Nov 24, 2014 5:54 pm

ride4funfl wrote:I reworked the Find Peak Finder plug-in and the Beat Finder plug-in with some success. Does anyone know of a plug-in that might be close to the analysis I am looking for?
"Sound Finder" and "Beat Finder" are both close - how far did you get modifying them? What doesn't work?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

ride4funfl
Posts: 2
Joined: Mon Nov 24, 2014 5:18 pm
Operating System: Please select

Re: How to determine ime between pulses that exceed a thresh

Post by ride4funfl » Tue Nov 25, 2014 12:52 am

For peak finder I do not always get the peaks. It seems I need all peaks that exceed a threshold not just all equal to max but I also need to ignore for a window of time after a peak is sceen.

Code: Select all

;nyquist plug-in
;version 4
;type analyze
;name "Scrambler..."
;action "Analysing the audio ..."
;control equal-levels "Place labels at" choice "first peak only,all equally loud peaks" 1  
;control minimum-distance "Minimum Distance:[samples]" int "" 1000 1 5000

; no garbage collector messages please
(setf *gc-flag* nil)

(if (< minimum-distance 1)
    (setf minimum-distance 1)
  (setf minimum-distance (truncate minimum-distance)))

(defun make-peak-waveform (sound) 
  (if (arrayp sound) 
      (snd-maxv (snd-abs (aref s 0)) (snd-abs (aref s 1)))
    (snd-abs sound)))

(defun add-label (time text)
  (setq label-list (cons (list time text) label-list)))

(setf label-list nil)
(setf last-peak-time 0.0)

;; The main working part of the program.
(let* ((peak-waveform (make-peak-waveform s))
       (maximum-peak 0.0) (last-peak 0.0))
  (do ((n 0 (1+ n))                                   ; sample counter
       (current-sample (snd-fetch peak-waveform)      ; init-form
                       (setq vowel-sample             ; loop-form
                             (snd-fetch peak-waveform))))
    ; Exit when we run out of samples, return the number of samples (n)
    ((not current-sample) n)
    (cond ((and (= equal-levels 1)
                (= current-sample maximum-peak)
                (> (- n last-peak) minimum-distance))
           (format t "n: ~A, lp: ~A, n-lp: ~A m: ~A~%" n last-peak (- n last-peak) minimum-distance)
           (setf last-peak n)
           (add-label (/ n *sound-srate*) (format nil "local-time: ~A delta-time: ~A" (/ n *sound-srate*) (- (/ n *sound-srate*) last-peak-time)))
		   (setf last-peak-time (/ n *sound-srate*)))
          ((> current-sample maximum-peak)
           (setf maximum-peak current-sample)
           (setf last-peak n)))))

(format t "resulting list: ~S~%" label-list)

; If no peaks were found, return a message
(if (null label-list)
    "No Peaks found."
  label-list)
Attachments
scrmbler003.wav
Sample file capture from photogate system
(993.17 KiB) Downloaded 65 times

Post Reply