Hi,

I have defined a filter, X, with unit magnitude and a phase of 45deg. Its real and imaginary parts are:

real{X} = {0.70701, 0.70701, 0.70701, 0.70701}

imag{X} = {0.70701, 0.70701, 0.70701, 0.70701}

So:

magnitude{X} = {1, 1, 1, 1}

phase{X} = {45deg, 45deg, 45deg, 45deg}

Now, if I take the inverse DFT of the real/imagninary parts, and then take the DFT of that result, I should end up with the same real/imaginary parts:

X --> [IDFT] --> h[n] --> [DFT] --> X (h[n] is always real).

However, this is not what I'm getting when I perform the IDFT/DFT. What I get back is the correct real parts, but the imaginary parts are all zero.

The algorithms (see below) I'm using for the IDFT/DFT is are

*direct* implementations of the exponential forms.

What am I not doing right?

Thanks.

DFT algorithm:

Code:

omega = 2pi / N
**
do while k < N**
realX[k] = 0
imagX[k] = 0
**do while n < N**
realX[k] = realX[k] + h[n] * cos(k * omega * n)
imagX[k] = imagX[k] - h[n] * sin(k * omega * n)
n = n + 1
realX[k] = realX[k] / N;
imagX[k] = imagX[k] / N;
k = k + 1

IDFT algorithm:

Code:

**do while n < N**
**do while k < N**
h[n] = h[n] + (realX[k] * cos(k * omega * n) - imagX[k] * sin(k * omega * n))