# Is there an easier way to analyze periodic spikes?

I want to measure the speed of my pickup truck’s engine. I made an inductive pickup that I wrapped around the ignition coil’s wire and recorded a few minutes of it idling. That gives me a spike twice every time my engine rotates. I had hoped to get Audacity to count the spikes for me, but I can’t find a technique in ‘plot spectrum’ or elsewhere that does that. It doesn’t even detect the frequency of the pulses as a frequency, just the frequency content of the spikes themselves. So I have to squint and count by hand. This is not a big deal, but I hoped for something more convenient and accurate.

Audacity 2.1.2, built from source 2017 February 10, Slackware, Kernel 4.9.9, wxWidgets 3.0.2, other packages updated daily.

That gives me a spike twice every time my engine rotates.

You have a two cylinder pickup? I guess you could have six coils.

You can get there from time. Measure the time between two spikes and divide that into 1.

.001 seconds into 1 is a thousand cycles, 1KHz. Pick the time between the first and fifth spike and divide by 5 to get better time accuracy.

Koz

If you post a short sample in WAV format, we may be able to offer better suggestions (see here for how to post an audio sample: https://forum.audacityteam.org/t/how-to-post-an-audio-sample/29851/1)

I have a 4-cylinder engine with 1 ignition coil that fires every half-rotation.

I asked in this forum so that I wouldn’t have to count by inspection.

I read the FAQs first; I always do.

I eventually figured it out by excerpting a single second and raising ‘Size’ in ‘Spectrum Analysis’ to 4096. This revealed 43 Hz as the most-common frequency, followed
by its harmonics; I counted 43 spikes in the 1-second sample. 1290 rpm sounds about right.

I take it ‘Size’ is a divisor; when I tried 65536 Audacity complained of too little data.

On that recording the fundamental frequency is ~37Hz …

The seventh harmonic is 292Hz , so the fundamental is 36.5Hz

Counting the peaks with Nyquist gives the same answer:

``````;version 4

(setf threshold 0.8)  ;count click each time we cross this level
(setf step 180)       ;follow waveform in steps of this number of samples

;; Use only the left channel of stereo tracks
(if (arrayp *track*)
(setf *track* (aref *track* 0)))

(let ((sig (snd-avg *track* step step op-peak))
(dur (get-duration 1))
(count 0))
(do ((val (snd-fetch sig)(snd-fetch sig))
(low t))
((not val) (/ count dur))
(cond
((and low (> val threshold))
(setf low nil)
(setf count (1+ count)))
((< val threshold)
(setf low t)))))
``````

With this solution, the “step” setting is important.
Zooming in on the track we can see that there are gaps of around 400 samples length between spikes, but the spikes themselves have “gaps” of around 70 samples duration. To count the spikes accurately we need to smooth the waveform so that the “gaps” are ignored, but the spaces between spikes remain. To do this I chose to smooth the track in steps of 180 samples, but anything between about 100 and 300 should work.