Hi there, I have an audio signal (speech) sampled at 44.1 kHz and I want to shift its frequency by a fixed amount in Hz. Ie., I want a frequency at 100 Hz to be at 110 Hz, and a frequency at 235 Hz to be at 245 Hz. I tried multiplying the signal with a sine tone but that gives me not one shift by +10Hz but a shift by -10Hz as well. So how should I do that? I suspect it should be easy - maybe I can cancel the -10Hz component somehow, but how? Any code snippets or explanation would be great - I'm new to the DSP world and would like to learn. Thanks! Frank
Shift frequency of an audio signal
Started by ●April 8, 2004
Reply by ●April 8, 20042004-04-08
On 8 Apr 2004 02:33:24 -0700, frank.reich@postino.ch (Frank) wrote:>Hi there, > >I have an audio signal (speech) sampled at 44.1 kHz and I want to >shift its frequency by a fixed amount in Hz. > >Ie., I want a frequency at 100 Hz to be at 110 Hz, and a frequency at >235 Hz to be at 245 Hz. I tried multiplying the signal with a sine >tone but that gives me not one shift by +10Hz but a shift by -10Hz as >well. > >So how should I do that? I suspect it should be easy - maybe I can >cancel the -10Hz component somehow, but how?How about doing a series of consecutive FFTs, shift the bins by 10Hz, and then do an inverse FFT to reconstruct a time sequence? -Robert Scott Ypsilanti, Michigan (Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)
Reply by ●April 8, 20042004-04-08
Frank wrote:> Hi there, > > I have an audio signal (speech) sampled at 44.1 kHz and I want to > shift its frequency by a fixed amount in Hz. > > Ie., I want a frequency at 100 Hz to be at 110 Hz, and a frequency at > 235 Hz to be at 245 Hz. I tried multiplying the signal with a sine > tone but that gives me not one shift by +10Hz but a shift by -10Hz as > well. > > So how should I do that? I suspect it should be easy - maybe I can > cancel the -10Hz component somehow, but how? > > Any code snippets or explanation would be great - I'm new to the DSP > world and would like to learn. > > Thanks! > FrankFrank, When you multiply two frequencies f1 x f2 in the frequency domain you receive f1 + f2, f1 - f2, f2 + f1, and f2 - f1. This is used in modulation and usually one frequency, called the carrier, has a much higher frequency as the modulated base band. This results in the above sum and subtractions not mix. In your case the 'carrier' frequency is in the base band signal, resulting in sum and subtractions to intermix. I guess a frequency approach would be a possibility. Take a FFT, shift your signal in the frequency domain and bring it back to the time domain with an IFFT. Guenter
Reply by ●April 8, 20042004-04-08
On Thu, 8 Apr 2004, Frank wrote:> I have an audio signal (speech) sampled at 44.1 kHz and I want to > shift its frequency by a fixed amount in Hz. > > Ie., I want a frequency at 100 Hz to be at 110 Hz, and a frequency at > 235 Hz to be at 245 Hz. I tried multiplying the signal with a sine > tone but that gives me not one shift by +10Hz but a shift by -10Hz as > well.I'm not one of the professionals here, but i would suggest the following: - treat your real signal as complex signal and remove negative frequencies by bandpass-filtering - shift spectrum by multiplying signal with exp(i*pi*t*m) where m=10/22050 would be the shift - throw away the imaginary signal part> I'm new to the DSP world and would like to learn.Hmm... I doubt if you really want to to this kind of processing. If you want to change the pitch of the speech this is the wrong direction. (shifting the spetrum vs. stretching it)> Thanks! > FrankGhis! Sebastian -- PGP-Key-ID (long): 572B1778A4CA0707
Reply by ●April 8, 20042004-04-08
"Frank" <frank.reich@postino.ch> wrote in message news:a6a3e04a.0404080133.485bdc81@posting.google.com...> Hi there, > > I have an audio signal (speech) sampled at 44.1 kHz and I want to > shift its frequency by a fixed amount in Hz. > > Ie., I want a frequency at 100 Hz to be at 110 Hz, and a frequencyat> 235 Hz to be at 245 Hz. I tried multiplying the signal with a sine > tone but that gives me not one shift by +10Hz but a shift by -10Hzas> well. > > So how should I do that? I suspect it should be easy - maybe I can > cancel the -10Hz component somehow, but how? > > Any code snippets or explanation would be great - I'm new to the DSP > world and would like to learn. > > Thanks! > FrankYou are implementing the trigonometric relationship: sin(w1+w2)t = sin(w1)t * cos(w2)t + cos(w1)t * sin(w2)t Here, sin(w1)t is your audio signal and w2 is the frequency shift you want to implement. In order to get a frequency shift with the unwanted products suppressed, you need to provide cosine as well as sine for the shift frequency, and you also need to implement a wideband 90 degree phase shift for the audio. Do a google search on mixer, image suppression, audio frequency shift, Hilbert transform etc. Regards Ian
Reply by ●April 8, 20042004-04-08
Are you absolutely sure this is what you want to do? You are describing an additive frequency shift, which will alter the harmonic relationships between partials. Thus, if you shift the frequencies an octave apart (100,200) by adding 10 Hz, you end up with an interval (110,210) that is now somewhat less than an octave. In effect you are trasnposing higher partialss by successively smaller intervals. The degree of the effect will also depend on what the staring frequency is. It will typically sound like the warping effect used for disguising a speaker's voice. This is a classic frequency-domain technique in electro-acoustic composition and transformation, while being somewhat unorthodox as a dsp technique. You will find there are many free e/a tools that can do what you ask. One of the best is Csound (sources under the LGPL), which can perform phase vocoder processing in real-time, giving programmatic access to each analysis frame (in the form of amplitude/freq bins); it is then easy to make the additive modification, and then resynthesise using the oscillator bank option (you may get away with the faster FFT resynthesis if the shifts are small). On a fast enough machine, you can do this in real time. On the other hand, if you in fact want to achieve conventional pitch-shifting (preserving ratios of partials), you need to multiply all frequencies by the same constant factor, having previously decided what your transposition ratio is to be - e.g 50 Cents, 3 semitones, etc. The factor 1.0594631 (i.e. 12th root of 2) raises pitch by one equal-termpered semitone. Richard Dobson> Hi there, > > I have an audio signal (speech) sampled at 44.1 kHz and I want to > shift its frequency by a fixed amount in Hz. > > Ie., I want a frequency at 100 Hz to be at 110 Hz, and a frequency at > 235 Hz to be at 245 Hz. I tried multiplying the signal with a sine > tone but that gives me not one shift by +10Hz but a shift by -10Hz as > well. > > So how should I do that? I suspect it should be easy - maybe I can > cancel the -10Hz component somehow, but how? > > Any code snippets or explanation would be great - I'm new to the DSP > world and would like to learn. > > Thanks! > Frank
Reply by ●April 8, 20042004-04-08
Richard Dobson wrote:> Are you absolutely sure this is what you want to do? You are describing > an additive frequency shift, which will alter the harmonic relationships > between partials. Thus, if you shift the frequencies an octave apart > (100,200) by adding 10 Hz, you end up with an interval (110,210) that is > now somewhat less than an octave. In effect you are trasnposing higher > partialss by successively smaller intervals. The degree of the effect > will also depend on what the staring frequency is. It will typically > sound like the warping effect used for disguising a speaker's voice. > > This is a classic frequency-domain technique in electro-acoustic > composition and transformation, while being somewhat unorthodox as a dsp > technique. You will find there are many free e/a tools that can do what > you ask. One of the best is Csound (sources under the LGPL), which can > perform phase vocoder processing in real-time, giving programmatic > access to each analysis frame (in the form of amplitude/freq bins); it > is then easy to make the additive modification, and then resynthesise > using the oscillator bank option (you may get away with the faster FFT > resynthesis if the shifts are small). On a fast enough machine, you can > do this in real time. > > On the other hand, if you in fact want to achieve conventional > pitch-shifting (preserving ratios of partials), you need to multiply all > frequencies by the same constant factor, having previously decided what > your transposition ratio is to be - e.g 50 Cents, 3 semitones, etc. The > factor 1.0594631 (i.e. 12th root of 2) raises pitch by one > equal-termpered semitone. > > > > > Richard DobsonThe OP describes a useful technique for suppressing feedback in a PA system. A small shift (5 Hz is not intrusive for voice, but 10 may be) allows considerably more gain, and really astounding (to me) gain when coupled with an adaptive notch filter. I can think of two ways to do it, and there are probably others. Both use single-sideband techniques. One stays at baseband, directly shifting the original signal to the desired one. Both work in real time. The other avoids the need for a broadband Hilbert transformer to make the original signal analytic. Instead, the original signal is modulated on a much higher carrier, producing upper and lower sidebands, but suppressing the carrier. One of the sidebands is removed with a filter, and the other shifted (with inversion if the lower is chosen) nearly to baseband. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●April 8, 20042004-04-08
Ah right - I hadn't thought of that application. I am aware in a most general way of this technique (never had occasion to use it), but it never occurred to me that it would be an additive shift of N Hz across the spectrum, which would produce the inharmonicity I described. Even a shift of 5Hz at 110 Hz (as per the OP) is far from small - almost a semitone, and I would expect that to be intrusive for anything. A 5hz shift at 1000Hz is a different matter. It is all down to whether or not you are preserving intervals between partials. My understanding is insuffficient to deduce from your recipes which it is, but as I said, I had always assumed it was a full pitch shift (e.g. measured in Cents), so there is no warping of intervals between harmonics. The latter might be tolerable for speech, but would surely be intolerable for instruments. Richard Dobson Jerry Avins wrote:> Richard Dobson wrote:> The OP describes a useful technique for suppressing feedback in a PA > system. A small shift (5 Hz is not intrusive for voice, but 10 may be) > allows considerably more gain, and really astounding (to me) gain when > coupled with an adaptive notch filter. > > I can think of two ways to do it, and there are probably others. Both > use single-sideband techniques. One stays at baseband, directly shifting > the original signal to the desired one. Both work in real time. > > The other avoids the need for a broadband Hilbert transformer to make > the original signal analytic. Instead, the original signal is modulated > on a much higher carrier, producing upper and lower sidebands, but > suppressing the carrier. One of the sidebands is removed with a filter, > and the other shifted (with inversion if the lower is chosen) nearly to > baseband. > > Jerry
Reply by ●April 8, 20042004-04-08
Frank wrote:> Hi there, > > I have an audio signal (speech) sampled at 44.1 kHz and I want to > shift its frequency by a fixed amount in Hz. > > Ie., I want a frequency at 100 Hz to be at 110 Hz, and a frequency at > 235 Hz to be at 245 Hz. I tried multiplying the signal with a sine > tone but that gives me not one shift by +10Hz but a shift by -10Hz as > well. > > So how should I do that? I suspect it should be easy - maybe I can > cancel the -10Hz component somehow, but how? > > Any code snippets or explanation would be great - I'm new to the DSP > world and would like to learn. > > Thanks! > FrankHams do this every day! While listening to Single Side Band signals, as you change the receiver's local oscillator tuning, you can make the voice sound anywhere from to low to comically too high. The ear is quite good at knowing when the voice sounds "natural". To generate an "SSB" signal, multiply (modulate) the speaker's voice band by a higher frequency "carrier". Use a selective filter to select one or the other "sideband". Demodulate (multiply) the SSB signal by a carrier which is the original carrier frequency shifted +- 10Hz. Low pass filter the result, and you will have the original voice band shifted up or down by 10Hz. MikeM
Reply by ●April 8, 20042004-04-08
Hi all (especially Ian), thanks for the comments and ideas. Yes I'm positive that I want a frequency shift - NOT a pitch shift. I've been on dspdimension.com and thats NOT what I want. I cannot do a FFT because that eats too much horsepower and I want to be able to shift the frequency gradually, not discreetely (ie. by 1/10 Hz if possible). So, what you're suggesting boils down to the following: 1. I make the signal analytic, ie. I run the speech signal through a Hilbert transformer and combine it with the original signal into a complex signal. 2. I multiply that by the complex exponential corresponding to the frequency shift 3. I discard the imaginary sequence and take the real part as my output signal. I'm not sure if I got this right, especially (3) which seems to simple to me. Why would I do the complex multiply if I throw away half of the result anyway...? Thanks again for any insight you can provide! --Frank