I am stuck trying to calculate the DFT for a given $N$

Given the signal $x[n] = \cos(\frac{\pi}{2}n - \frac{\pi}{2})+2 \cos(\pi n + \frac{\pi}{2})$ and $N = 4$ I tried to calculate the DFT $X[k] = \sum\limits_{n=0}^{N-1}x[n]e^{\frac{-2 \pi ink}{N}}$

Now since

  • $X[k] = \sum\limits_{n=0}^{3}x[n]e^{\frac{-2 \pi ink}{4}} = \sum\limits_{n=0}^{3}e^{\frac{-2 \pi ink}{4}} \cos(\frac{\pi}{2}n - \frac{\pi}{2}) + \sum\limits_{n=0}^{3}e^{\frac{-2 \pi ink}{4}} 2 \cos(\pi n + \frac{\pi}{2})$

I can have a look at both signals seperatly and it would come down on how to solve the dft for the cosine. For this matter I looked at different sources like here and here

I tried to solve it using the geoemetric series for $\cos(\frac{\pi}{2}n - \frac{\pi}{2})$ which led to

  • $\sum\limits_{n=0}^{3}e^{\frac{-2 \pi ink}{4}} \cos(\frac{\pi}{2}n - \frac{\pi}{2}) = \dots = \frac{1}{2} e^{-\frac{\pi}{2}} \frac{1 - e^{\frac{\pi}{2}3i(1-k)}}{1 - e^{\frac{\pi}{2}i(1-k)}} + \frac{1}{2} e^{\frac{\pi}{2}} \frac{1 - e^{\frac{\pi}{2}3i(1+k)}}{1 - e^{\frac{\pi}{2}i(1+k)}}$

Now something seems wrong because now I get $X[0] \neq 0 $ which is false given my plots using this code

import numpy as np
import matplotlib.pyplot as plt

time   = np.arange(0.,5,1) 
pnts   = len(time)
signal = np.cos(np.pi/2*time - np.pi/2) + 2*np.cos(np.pi*time + np.pi/2)

fourTime = np.array(range(pnts))/pnts
fCoefs   = np.zeros((len(signal)),dtype=complex)

for freq in range(pnts):
    csw = np.exp( -1j*2*np.pi*freq*fourTime )
    fCoefs[freq] = np.sum(np.multiply(signal,csw) )

ampls = 2*np.abs(fCoefs)

plt.plot(time, signal)
plt.xlabel('Time (s)'), plt.ylabel('Amplitude')

plt.xlabel('Frequency (Hz)'), plt.ylabel('Amplitude (a.u.)')

enter image description here

enter image description here

Anyways this way of calculating actually seems a little bit overcomplicated as well. I looked different fourier tables and their derivation as well and found contradicting results. I am confused and it seems as if I am still missing something crucial.

updated using the hint from the first answer

$\sum\limits_{n=0}^3 x[n] \cdot e^{\frac{-2 \pi i k}{4}} = x[0] e^{\frac{- \pi i 0 k}{2}} + x[1] e^{\frac{- \pi i 1 k}{2}} + x[2] e^{\frac{- \pi i 2 k}{N}} + x[3] e^{\frac{- \pi i 3 k}{2}}$ $0 \cdot e^{\frac{- \pi i 0 k}{2}} + e^{\frac{- \pi i 1 k}{2}} + 0 \cdot e^{\frac{- \pi i 2 k}{N}} - e^{\frac{- \pi i 3 k}{2}} = e^{\frac{- \pi i k}{2}} - e^{\frac{- \pi i 3 k}{2}}$

So now when calculate $X[k]$ for $k = 0, 1, 2, 3$

  • $X[0] = 0$
  • $X[1] = e^{\frac{- \pi i \cdot 1}{2}} - e^{\frac{- \pi i 3 \cdot 1}{2}} = - i - i = - 2 i$
  • $X[2] = e^{\frac{- \pi i \cdot 2}{2}} - e^{\frac{- \pi i 3 \cdot 2}{2}} = -1 - (-1) = 0$
  • $X[3] = e^{\frac{- \pi i \cdot 3}{2}} - e^{\frac{- \pi i 3 \cdot 3}{2}} = i - (-i) = 2i$

So it is a little bit confusing for me that $X[2] = 0$ I expected it to be bigger than $0$ because I thought it would be corresponding to frequency of $1/2$.


1 Answer 1



The sequence $x[n]$ is written in an unnecessarily complicated way. Figure out what the values of the sequence are for $n=0,1,2,3$, and then it should be extremely straightforward to compute its DFT.

  • $\begingroup$ Thanks for the hint! This is actually what I tried first and then I got contradicting results, I will update my answer and add the calculations $\endgroup$ Jan 24 at 20:16
  • $\begingroup$ I have added my calculations for this approach and what confuses me about the result.Would be appreciated if you could have a look $\endgroup$ Jan 24 at 20:42
  • $\begingroup$ @OuttaSpaceTime: But that result is correct; you have zeros at DC and at Nyquist. $\endgroup$
    – Matt L.
    Jan 24 at 21:02
  • $\begingroup$ So how do you now that this is the Nyquist? I am not yet able to see it, also because I expected two non zero values for two different frequencies (though the other cosine is always $0$) Okay maybe something with my code is wrong as well which produced the shown plots, I have added it as well. $\endgroup$ Jan 24 at 21:12
  • $\begingroup$ @OuttaSpaceTime: For even $N$, $N/2$ is the Nyquist bin. Also note that $x[n]$ can be written as $x[n]=\sin(n\pi/2)$, so it's no surprise that there's only a single frequency component. $\endgroup$
    – Matt L.
    Jan 24 at 21:17

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.