Tracking frequency contours when dominant frequency jumps across harmonics
Posted on February 23, 2018
When tracking dominant frequency in order to obtain a frequency contour most algorithms rely on getting the highest amplitude frequency (i.e. dominant frequency) at each time window. This method, however, can be problematic when the highest amplitude is found at different harmonics in different time windows. Here, I demonstrate how this issue can be overcome using the new warbleR function track_harm.
First install and/or load warbleR developmental version (if there is an older warbleR version installed it has to be removed first):
Now let’s simulate a song with “jumping” dominant frequency using the (also new) sim_songs function (the sim_songs function was fully explained in a previous post). To accomplish this we simulate 2 songs that both start and end at the same frequency (4 kHz). We skip the gap (i.e. silence) at the end of the first song and at the beginning of the second one, so when with paste them together the sound looks like a continuous frequency trace (a single song):
But first let’s define some parameters needed for simulations and spectrograms:
Now simulate the two song segments independently:
Note that the amplitude values were flipped (amps = rev(amps)) in the second simulation so the highest amplitude is in the last harmonic. Also, the fade-out was set to 0 (fout) in the first simulation while the fade-in (fin) was 0 in the second. A seed is used so the same song will be generated every time. If seed = NULL (as by default) then a different song will produced each time.
We can put together this 2 song segments in a single wave object using seewave’spastew function:
There it is. A song in which the dominant frequency jumps from the first harmonic to the fourth one.
If we used seewave’sdfreq function to get the frequency contour we will see that the contour will also jump from the first to the fourth harmonic:
the red dots highlight the resulting frequency contour.
Now let’s try with track_harms:
The frequency contour is now accurately tracked despite the dominant frequency jumping across harmonics. trac_harms takes exactly the same arguments than seewave’sdfreq function, so it can be simply replaced in existing code.
Now we can try it on a real song. This is an element from a fairy-wren song:
This is the frequency contour using the regular dfreq function: