2
votes

I want to make a frequency shift on a .wav file.

The problem I have is that the FFT uses complex numbers, and the .wav file has integer values. So I want to make a frequency shift and that means that I have to make a direct transform and an inverse transform , the problem is that the inverse transform doesn't give me integer values (it gives me complex values), but I need integer values for the samples of the .wav file.

How do I interpret the values of the inverse transform ?

1
So long as you maintain conjugate symmetry in the frequency domain then the inverse transform will be purely real, and then you can scale and round these values back to integer samples.Paul R
As Paul pointed out. But your imaginary part might contain some very small numbers. Keep an eye out for that, safe to ignore if they are very small.roadrunner66
@PaulR But a simple shift can never retain that symmetry!Marcus Müller
@MarcusMüller: you just have to shift symmetrically - the bins in the lower half are shifted up, while the bins in the upper half are shifted down.Paul R
@PaulR: true; but that's not a "simple shift" by my definition (which I didn't mention ;) so please excuse my excessive commenting!). But yeah, I didn't correctly potrait that aspect in my answer's last paragraph, so let me fix that.Marcus Müller

1 Answers

1
votes

I want to make a frequency shift on a .wav file.

So you've got an audio, which means a real-valued, signal.

The spectrum of a real valued signal has symmetry to f=0, i.e. it's Fourier Transform has hermitian symmetry.

If you now shift that input spectrum (blue), the result (red) loses symmetry, i.e. the resulting signal is no longer real: spectra

Notice how things are, through aliasing, circular, so what you "shift out" of the Nyquist range will appear at the opposite end. In my example, this means that you get unexpected high frequency components!

The problem I have is that the FFT uses complex numbers, and the .wav file has integer values. So I want to make a frequency shift and that means that I have to make a direct transform and an inverse transform , the problem is that the inverse transform doesn't give me integer values (it gives me complex values), but I need integer values for the samples of the .wav file.

Indeed! And that's because the result of your shift really isn't a real signal anymore.

What you can do, however, is:

  1. shift (either in time or frequency domain – honestly, doing it in time domain would be easier! Just multiply the nth sample with exp(2j π f_shift/f_sample n ).)
  2. apply a complex bandpass filter that removes everything outside the frequency [0; f_sample / 2 - shift ]. This gives you what is called an analytical signal (i.e. only positive frequencies), which still isn't real-valued, because it's not symmetric.
  3. Throwing away the imaginary part now doesn't alter the information of your signal - it just halves the energy and gives you a symmetric spectrum, and something you can write to a .wav file.

Now, this whole "doing it in frequency domain through the FFT" is an approach that people in the Software Defined Radio world are pretty used to – they deal with complex baseband signals all the time.

How do I interpret the values of the inverse transform ?

As the complex signal that they are. Ignoring the imaginary part as suggested in the comments will lead to the energy contained in the negative frequencies being mirrored onto you positive frequencies (and the other way around), and is most likely not what you want – unless either:

  • you've made sure that prior to this "symmetricalization", the energy on either side of f=0 was 0, so that nothing bad happens, pr
  • you've made sure that you selectively shifted the negative and positive frequencies so, that symmetry was retained. Notice that this is not a "simple" shift of the whole frequency domain, but two selective shifts; the selection of these shifting regions has a shape, which boils down to using a window. If you just "select" or "not select" each bin for shifting, you're effectively applying a rectangular window – with all the Gibb's Phenomenom you can incur with that.