I am working for my class project on making animal repellent , I need to know how I could go about taking a normal audio file and shift its frequency/Pitch very high to make it an ultrasonic sound.


To answer the "how to shift the frequency of an audio signal up" bit:

  • You could multiply the signal by a sine wave at a high frequency. This would shift and mirror the whole spectrum of the original signal into the high frequencies (multiplication by a sine in the time domain = convolution by a pair of symmetric Dirac in the frequency domain) - the mirror image could then be removed by high-pass filtering. Limitation: this would not preserve integer ratios between harmonics. For example, a harmonic mixture with partials at 100, 200 and 300 Hz would have partials at 1100, 1200 and 1300 Hz if shifted by 1kHz - and the integer ratio between harmonics is lost, making the resulting audio signal "metallic" or "dissonant" - at least to human hearing's perception criteria!.
  • You could simply play back the original data at a higher sample rate. Limitation: multiplying the sample rate will also reduce the duration of the original data.
  • Actual musical pitch-shifting is done with techniques such as the phase vocoder (Short-Term Fourier Transform).

However, you probably don't need to bother with any of these methods because:

  • There is no need to shift an existing audio signal - given that the content of the original signal is of little relevance and will be degraded in one way or the other by the transposition process, why not directly generating a tone at the required frequency to start with?
  • Keep in mind that whatever you do, the converters and transducers that come with a computer cannot reproduce ultrasounds (they have a cutoff at the upper limit of the human hearing range, about 20kHz).
  • The evidence that ultrasounds have a repellent effect on mosquitoes is very shallow.
  • $\begingroup$ Maybe ultrasound doesn't have a repellent effect on mosquitos because they're generating it on a computer that can't reproduce ultrasound. :D $\endgroup$ – endolith May 1 '13 at 15:49

A frequency shift by $f_0$ can be realised by amplitude modulation which involves multiplying the input signal $x(t)$ with a carrrier $\cos(2\pi f_0t)$, i. e. $$ y(t) = x(t) \cos(2\pi f_0t) $$ When implementing this in the discrete domain (e.g. in Matlab) the sampling frequency $f_\mathrm{s,in}$ of the input signal has generally to be increased. Assume $x(t)$ has a cut off frequency (alias bandwidth) of $f_\mathrm{c}$. Then the frequency shifted signal $y(t)$ has a cut off frequency of $f_\mathrm{c}+f_0$. Consequently, the sampling frequency $f_\mathrm{s,out}$ of $y(t)$ must fulfill $f_\mathrm{s,out} \geq 2(f_\mathrm{c}+f_0)$ (sampling theorem).

I suggest the following steps to implement it in Matlab ($n$ is the discrete time):

  • Create an upsampled version $\tilde x_n$ of the input sequence $x_n$, so that its sampling frequency $f_\mathrm{s,out}$ fulfills the above condition. Use the Matlab function upsample. If you don't know $f_\mathrm{c}$ assume $f_\mathrm{c}=f_\mathrm{s,in}/2$.
  • Create the discrete-time carrier signal $\cos(2\pi F_0n)$ with $F_0 = f_0/f_\mathrm{s,out}$. It must have the same lenght as $\tilde x_n$.
  • Compute $y_n = x_n \cos(2\pi F_0n)$.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.