# generating ultrasonic sound in matlab

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.
• Maybe ultrasound doesn't have a repellent effect on mosquitos because they're generating it on a computer that can't reproduce ultrasound. :D – 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)$.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 1, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.6528693437576294, "perplexity": 669.9861943438946}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-39/segments/1568514573439.64/warc/CC-MAIN-20190919040032-20190919062032-00042.warc.gz"}