fftshift

Spectrum shift so as to be centered on the low frequencies.

Namespace: dsp::fourier

Prototype

Vector<T> fftshift(const Vector<T> &X)

Parameters

XInput spectrum, uncentered (typicaly ouput of the fft() function)

Returns

0 Hz centered spectrum.

Description

This function shift the input spectrum so as the 0 Hz bin is at the center. If the number of samples is even: \[ X'_k = X_{k+N/2\ [N]} \] That is: \[ X' = \left[X_{N/2}, X_{N/2+1}, \dots, X_{N-1}, X_0, X_1, \dots, X_{N/2-1}\right] \]

And if \(N\) is odd: \[ X' = \left[X_{N/2+1}, X_{N/2+2}, \dots, X_{N-1}, X_0, X_1, \dots, X_{N/2}\right] \]

Example

  soit n = 10000;
  soit x  = bruit_colore(n, 1.0f);
  soit y1 = 10 * log10(abs2(fft(x)));
  soit y2 = fftshift(y1);


  soit fr1 = linspace(0, 1.0, n),
       fr2 = linspace(-0.5, 0.5, n);

  Figures f;
  f.subplot().plot(fr1, y1, "b-", "y1 (spectre avant fftshift)");
  f.subplot().plot(fr2, y2, "b-", "y2 (spectre après fftshift)");