1
$\begingroup$

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) $$

enter image description here

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

enter image description here

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

enter image description here enter image description here

$\endgroup$
7
  • 2
    $\begingroup$ One way is to square the signal and then use filters to get rid of the extra (undesired) harmonics. $\endgroup$
    – MBaz
    Aug 30 '16 at 12:52
  • 2
    $\begingroup$ Is it for audio purposes? One way is to double the sampling frequency while keeping the old sample values but it stretches the signal. $\endgroup$ Aug 30 '16 at 12:59
  • 1
    $\begingroup$ @axsvl77 Something like that. If you want to keep the original sampling frequency you can resample. $\endgroup$ Aug 30 '16 at 13:33
  • 2
    $\begingroup$ @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. $\endgroup$
    – Jason R
    Aug 30 '16 at 13:39
  • 1
    $\begingroup$ The system to produce that output, needs to be non-linear. I do not think using something linear you can do that frequency scaling. $\endgroup$
    – MimSaad
    Aug 30 '16 at 13:53
2
$\begingroup$

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

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$ Aug 30 '16 at 17:59
  • $\begingroup$ @robertbristow-johnson: that clearly works as long as the OP is fine with duration of the file getting cut it half $\endgroup$
    – Hilmar
    Aug 30 '16 at 22:58
1
$\begingroup$

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/

$\endgroup$

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.