Frequency shift

58 views
Skip to first unread message

Andres Camacho

unread,
Nov 4, 2013, 2:03:48 AM11/4/13
to see...@googlegroups.com
Hello everybody. I want to compare different birdsong syllables using the cov.spectro function. For that I would like to have all sounds in a specific frequency range, or in other words "allign the frequency" (eg. minimum frequency set at 5000Hz for all sounds). This is to avoid low correlation values due to differences in the frequency range of the sounds, and focusing on comparing the "shape" of the sound. Which brings up my question: I would like to know if there is a way of fixing the frequency of a sound to a desired value. I thought about using the synth2 function which allows you to create a new sound based on the original one. I have been able to recover the original sound and shift its frequency. But it would save me a lot of time if I could, instead of "shifting the frequency by 1000Hz", command at WHICH frequency I want the sound to be.  I hope I made myself clear enough.
Thank you in advance for your help 

Jesse Ross

unread,
Nov 4, 2013, 9:17:22 AM11/4/13
to see...@googlegroups.com
Hi Andres,

This is a tough question because there is no single defined "frequency" to most sounds. For instance, if you look at the spectrogram for the orni data used in the example for lfs(), you can see that the energy is distributed at lots of different frequencies, with most of it concentrated between 4 and 6 kHz. There is no well-defined pitch for this sound.

If your sound is tonal, with a reasonably small variation in pitch, you might be able to use dfreq() to extract that pitch programmatically, and use it to automate your calls to lfs(). E.g., say you wanted to take the peewit data, wihch is roughly 1 kHz, and shift it to 2 kHz:

data(peewit)
spectro(peewit)
peewit_pitch = dfreq(peewit)
peewit_2k = lfs(peewit, 22050, (2 - median(peewit_pitch[, 2])) * 1000)
spectro(peewit_2k, 22050)

best,
jesse


On Mon, Nov 4, 2013 at 2:03 AM, Andres Camacho <camach...@gmail.com> wrote:
Hello everybody. I want to compare different birdsong syllables using the cov.spectro function. For that I would like to have all sounds in a specific frequency range, or in other words "allign the frequency" (eg. minimum frequency set at 5000Hz for all sounds). This is to avoid low correlation values due to differences in the frequency range of the sounds, and focusing on comparing the "shape" of the sound. Which brings up my question: I would like to know if there is a way of fixing the frequency of a sound to a desired value. I thought about using the synth2 function which allows you to create a new sound based on the original one. I have been able to recover the original sound and shift its frequency. But it would save me a lot of time if I could, instead of "shifting the frequency by 1000Hz", command at WHICH frequency I want the sound to be.  I hope I made myself clear enough.
Thank you in advance for your help 

--
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/groups/opt_out.

Jesse Ross

unread,
Nov 4, 2013, 10:19:54 AM11/4/13
to see...@googlegroups.com
Reading your question more carefully, I noticed that you were using synth2(), which is an awesome function I hadn't played with! Here's an alternative method using synth2():

data(peewit)
env.peewit <- env(peewit, f=22050, plot=FALSE)
ifreq.peewit <- ifreq(peewit, f=22050, plot=FALSE)$f[,2]
ifreq.peewit.shifted = ifreq.peewit + (3 - mean(ifreq.peewit))
peewit_3k = synth2(env=env.peewit, ifreq=1000 * ifreq.peewit.shifted, f=22050, plot=TRUE)

Note that in either of these approaches, the choice of how to describe the frequency of the original signal is not obvious.  I used median() in the first, and mean() in the second, but those aren't necessarily well motivated :)

best,
jesse

Andres Camacho

unread,
Nov 5, 2013, 1:58:08 AM11/5/13
to see...@googlegroups.com
Hi Jessie, thank you so much for your help, it has been very useful. I was thinking about using the low frequency of the signal as the "defined frequency", and so align all the syllables by aligning their low frequency to a certain value. Of what I have seen so far, using the mean or median frequency works fine. Although when I use the lfs function, the spectrogram returned look so different, like distorted, does the same happen to you?
Again, thank you very much for your help I really appreciate it.
Best,
Andrés   


2013/11/4 Jesse Ross <jr...@cornell.edu>

--
You received this message because you are subscribed to a topic in the Google Groups "seewave" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/seewave/Lbqx_SV22-4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to seewave+u...@googlegroups.com.

Jesse Ross

unread,
Nov 5, 2013, 9:34:17 PM11/5/13
to see...@googlegroups.com
Hi Andrés,

I also see distortion with lfs(). You might be able to mitigate this some by playing with the fft window length.

The ifreq() method seems to work a lot better for tico, but not very well for a sound with harmonics like peewit. Both this technique and the lfs() technique are transforming the sounds to a different domain (spectrogram or Hilbert transform) and losing some information, so it's not surprising that the resulting sounds would have some distortion!

I'm afraid I don't know a way to keep this from happening. I've noticed that artifacts can be introduced when I pitch-shift using other tools such as Audacity, as well.

I wonder if you might be best off avoiding pitch-shifting altogether, treating the spectrograms as matrices directly and calculating the correlation between the spectrograms incorporating both a time shift (as in covspectro) and a frequency shift (as in corspec).

best,
jesse

Andres Camacho

unread,
Nov 6, 2013, 3:28:39 AM11/6/13
to see...@googlegroups.com
Hi Jesse, 
when I use the synth2 function I don't see the distortion, actually the spectrogram at least looks identical.  

After exploring a bit more I think using the median is pretty good because you can set the center of each syllable at a certain frequency. The syllables I'm working with (Timberline wren) are pretty similar to the ones in tico, although the forms are more variable and complex. The great majority of them don't have harmonics, so the ifreq works pretty well.

I've also thought about calculating the correlation incorporating time and frequency shift although I don't have any idea of how to do it in R. The Raven correlator doesn't do frequency shifting, only time. I read in the Avisoft manual that the correlator does both time and frequency shifting, but getting a licence for avisoft, can be expensive and complicated.

Thank you again for your help and feedback I appreciate it very much.
Best,

Andrés 


2013/11/5 Jesse Ross <jr...@cornell.edu>
Reply all
Reply to author
Forward
Message has been deleted
0 new messages