# Is there a way to double all frequencies?

Let's imagine I have an input signal that looks like this:

$$f(t)=\sin\Big(2\pi(2)t\Big)+\sin\Big(2\pi(3)t\Big)+\sin\Big(2\pi(5)t\Big)$$

And I want an output signal that scales each frequency proportionally by some factor. Here, I scale everything by a factor of '2':

Is there a way to do this? The frequency domains look like this:

• One way is to square the signal and then use filters to get rid of the extra (undesired) harmonics.
– MBaz
Aug 30 '16 at 12:52
• Is it for audio purposes? One way is to double the sampling frequency while keeping the old sample values but it stretches the signal. Aug 30 '16 at 12:59
• @axsvl77 Something like that. If you want to keep the original sampling frequency you can resample. Aug 30 '16 at 13:33
• @axsvl77: To visualize what Olli suggested, imagine recording a tape, then playing it back at twice the normal rate. The result is that all frequencies would be doubled. However, time would also be compressed by a factor of two, which you may not want. Aug 30 '16 at 13:39
• The system to produce that output, needs to be non-linear. I do not think using something linear you can do that frequency scaling. Aug 30 '16 at 13:53

That's typically referred to as "pitch shifting" and it's typically a combination of re-sampling and time stretch/compression. Re-sampling is straight forward but time stretch/compression is a bit more tricky and the best methods depends on the application requirements, the characteristics of the signal and the amount of stretch/compression you'll need. See http://blogs.zynaptiq.com/bernsee/time-pitch-overview/ and https://en.wikipedia.org/wiki/Audio_time-scale/pitch_modification to get started

• if it's not real time, the OP can take the sound file and simply modify the sample rate of it. if the data remains unchanged, but the sample rate is reduced from 96 kHz to 48 kHz, the pitch will go up an octave and all frequencies will double. Aug 30 '16 at 17:59
• @robertbristow-johnson: that clearly works as long as the OP is fine with duration of the file getting cut it half Aug 30 '16 at 22:58

Below is a link to a simple and valuable tutorial function in C by Stephan M. Bernsee, called smbPitchShift.cpp, which can raise or lower the pitch of a musical signal.

I was able to also use it to slow-down or speed-up music without changing its pitch. If you want to instead do a time-stretch without altering the original pitch, you may have to apply Re-Sampling.

Looks like Bernsee has created some changes to his code since the version linked at GitHub. His newer code is available for download from his website -- it may increase the range of shifting from his original specification. I tweaked his original code so that I could pitch shift up by 8x.

https://github.com/AndyA/BatPhone/blob/master/pitchshift.c

http://blogs.zynaptiq.com/bernsee/time-pitch-overview/