# Phase response of FFT in practice

As I know if the impulse response is symmetric around sample zero phase response should be entirely zero.

The code below just set a rectangular window for vector "in"

const int N = 10;

// in = 0 , 0 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , 0
std::vector< std::complex<double> > in (N);
std::vector< std::complex<double> > out (N);
std::vector< std::complex<double> > polarOut (N);

auto middleElem = in.begin() + in.size()/2;
std::fill( middleElem - 1, middleElem + 2, 1);

fftw_plan my_plan  = fftw_plan_dft_1d(N, reinterpret_cast<fftw_complex*>(&in[0]),
reinterpret_cast<fftw_complex*>(&out[0]), FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(my_plan);

std::transform( out.begin(), out.end(), polarOut.begin(),
[]( auto& in ){
return  std::complex<double>( std::abs(in), std::arg(in) );
} );


I getting back a sinc like result in magnitude, But I am so curious why I have values different than zero in phase :

    polarOut    <11 items>  std::vector<std::complex<double>>
[0] (3.000000, 0.000000)    std::complex<double>
[1] (2.682507, -2.855993)   std::complex<double>
[2] (1.830830, 0.571199)    std::complex<double>
[3] (0.715370, -2.284795)   std::complex<double>
[4] (0.309721, -1.999195)   std::complex<double>
[5] (0.918986, 1.427997)    std::complex<double>
[6] (0.918986, -1.427997)   std::complex<double>
[7] (0.309721, 1.999195)    std::complex<double>
[8] (0.715370, 2.284795)    std::complex<double>
[9] (1.830830, -0.571199)   std::complex<double>
[10]    (2.682507, 2.855993)    std::complex<double>


Any explanation about the phase response of behaviour of this fft will be great.

The problem is that your input vector is not symmetric when considering the definition of the DFT:

$$X[k]=\sum_{n=0}^{N-1}x[n]e^{-j2\pi nk/N}\tag{1}$$

Note that from (1) the time indices start at $n=0$. If you periodically continue the signal $x[n]$ in your example you get

n: ... -5 -4 -3 -2 -1 | 0 | 1 2 3 4 5 6 7 8 9 10

x[n]: ... 1 0 0 0 0 | 0 | 0 0 0 1 1 1 0 0 0 0

If $x[n]$ were symmetric, the values for negative $n$ would need to be the same as the values for positive $n$. For $n=\pm 4$ this is not the case. If you defined your signal instead as

x[n] = 0 0 0 0 1 1 1 0 0 0

i.e. a signal of length $N=10$, then it would be symmetric and, consequently, its DFT (FFT) would be real-valued, apart from numerical errors.

• Good Observation. You mean that , because the samples are not symmetric, an extra phase got added!! Commented Feb 25, 2015 at 12:12
• @phanitej: Yes, if the signal is not symmetric, the DFT is not real-valued, i.e. there is a non-zero phase. Commented Feb 25, 2015 at 12:17
• Thanks a lot @MattL., I correctted my input and got zero phase. Commented Feb 25, 2015 at 12:20

Those are complex conjugates, which when you add give only , the real part. Intuitively exp(jwo)+exp(-jwo). so the resulting phase has the form invtan(imaginary_part/real_part) (invtan is tan inverse function), where b is o. so the phase spectrum will only have zeros.

That is the angles obtained, from a+jb is theta, and from that of a-jb is -theta. Both will sum up to give zero.