0
$\begingroup$

I would like to ask you for help to understand shifting frequency bins in audio pitch shifter. I have two issues that I can’t undersrand:


FIRST QUESTION
At first how to shift frequency bins when pitch factor is not rounded? For example let’s imagine some not typical but easier to explain case:
I have complex numbers array f with freq bins, where each member of array corresponds to one Hertz. So:
f[0] correspond to DC
f[1] correspond to 1Hz,
f[2] corresponds to 2Hz,
f[3] corresponds to 3Hz
and so on.

And I have only one value at freq bin with index 1:

f[1].real = 1;
f[1].imag = 0;

And all the rest members in f array are zero (both real and imag). So it means that my signal in time dmain is just single 1Hz sinusoid with no phase shift and with amplitude equal 1, and can be expressed by: $1 \cdot sin(1\cdot x)$
(Of course apmlitude depends on fft size, but the point is frequency so for simplify let's assume amlitude is 1 in that case).

And now let's assume I want to make pitch shifting with factor 1.75 to achieve one 1.75 Hz sinusoid expressed by: $1 \cdot sin(1.75 \cdot x)$

But I don’t have in my f array the member which correspond to 1.75 Hz. So I thought I should spread it on two bins with appropriate ratio. Let me illustrate it:
enter image description here

So after such pitch shift there are:

f[1].real = 0.25;
f[1].imag = 0;
f[2].real = 0.75;
f[2].imag = 0;

But in that case it looks like I have two sinusoids, first 1Hz and amplitude 0.25, and second 2Hz and amplitude 0.75. And it could be expressed by:
$0.25 \cdot sin(1 \cdot x) + 0.75 \cdot sin(2 \cdot x)$

So I've plot it on Desmos, to compare with desired $1 \cdot sin (1.75 \cdot x) And definitely they are not even similar.

So it looks like I do something wrong? But then how should it be solved?


SECOND QUESTION
Second question corresponds to the first one. Let's say I want to pitch shift with factor exact 2, so I should achieve the signal with one octave higher than original. While it works for one sinusoid, I get very ugly results for normal audio signals where all freq bins in array are filled with some value. So after shift all bins by factor 2 then I have every two bins empty, let mi illustrate it:
enter image description here

And it seems (and it sounds) like it’s wrong way to shifting freq bins. But then how to do that properly?

For any help great thanks in advance.

$\endgroup$
1
  • $\begingroup$ It doesn’t answer your question specifically but to do pitch shifting without changing the duration of the waveform use the phase vocoder algorithm where all these details have been worked out. $\endgroup$ – Dan Boschen Apr 2 at 22:39

Your Answer

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

Browse other questions tagged or ask your own question.