2
$\begingroup$

Problem

Sample the signal $\cos(500 \cdot 2\pi t)$ with sampling frequency $f_s = 5000 \ \text{Hz}$ and sample for a duration of $T = 0.5 \ \text{s}$. Perform an FFT on the samples. Now, change the signal to $\cos(499 \cdot 2\pi t)$ and plot the FFT. Comment on the results.

Attempt

We note that the spectral resolution is $\Delta f = \frac{1}{T} = 2 \ \text{Hz}$. Performing an FFT on the first signal and plotting yields two peaks at $\pm 500 \ \text{Hz}$, while the rest of the frequencies have no presence. This makes perfect sense.

enter image description here

Performing an FFT on $\cos(499 \cdot 2\pi t)$ shows peaks at $\pm 500 \ \text{Hz}$ and $\pm 498 \ \text{Hz}$, but now the magnitude of the rest of the frequencies is not zero.

enter image description here

I get that because the spectral resolution is $2 \ \text{Hz}$ the frequency content of $499 \ \text{Hz}$ gets "spilled" onto 500 Hz and 498 Hz, but why do other frequencies also now have a magnitude different from zero?

$\endgroup$
3
  • $\begingroup$ Let me turn the question around: Why would you expect the magnitudes to be zero? $\endgroup$ Commented Jun 28, 2024 at 12:05
  • 1
    $\begingroup$ @Hilmar: Because the Fourier transform of a single tells you the frequency contents of the signal. The only frequency contained in $\cos(499 \cdot 2\pi t)$ is 499 Hz, hence I expect that all other frequencies have magnitude zero. $\endgroup$ Commented Jun 28, 2024 at 12:41
  • 4
    $\begingroup$ That's a reasonable interpretation for the continuous Fourier transform but not for the DFT. The DFT is periodic with the FFT length N in both time and frequency. Your signal is NOT periodic in N so the notion that this signal contains only one frequency is wrong. $\endgroup$ Commented Jun 28, 2024 at 15:36

3 Answers 3

1
$\begingroup$

In this entire discussion, let $k,r,N,N_0,m,n \in \mathbb{Z}$.

Derivation of DFT for a cosine signal sampled exactly $p$ periods

The DFT of a discrete time signal $x[k]$ with length $N_0$ is defined as

$$X[r] = \sum_{k=0}^{N_0-1}x[k]e^{-jr\Omega_0 k}, \; \; \; \Omega_0 = \frac{2\pi}{N_0} \tag1$$

where we only need to perform calculations for $r \in [0, N_0-1]$ because the DFT is $N_0$-periodic in $r$ ($2\pi$-periodic in $\Omega$).

We know from continuous time that

$$\int_{T} \cos(n\omega_0 t)\cos(m\omega_0 t) \: \text{d}t = \begin{cases} 0 \: \: \: n \neq m \\\\ \frac{T}{2} \: \: \: n = m\end{cases} \tag2$$ $$\int_{T} \cos(n\omega_0 t)\sin(m\omega_0 t) \: \text{d}t = 0 \: \: \: \text{for all n and m} \tag3$$

where $T$ denotes one period. The discretized versions are

$$\sum_{k=0}^{N-1} \cos(n\Omega k)\cos(m\Omega k) = \begin{cases} 0 \: \: \: n \neq m \\\\ \frac{N}{2} \: \: \: n = m, \; \; \; \Omega \neq \pm \pi \\\\ N \: \: \: n = m, \; \, \; \Omega = \pm \pi \end{cases} \tag4$$ $$\sum_{k=0}^{N-1} \cos(n\Omega k)\sin(m\Omega k) = 0 \: \: \: \text{for all n and m} \tag5$$

where $N$ denotes one period.

If the signal we are performing the DFT on is a cosine signal $x[k] = \cos(\Omega k), \Omega \in [-\pi, \pi)$, then

$$\begin{align*} X[r] &= \sum_{k=0}^{N_0-1}\cos(\Omega k)e^{-jr \Omega_0 k} \\\\ \tag6 X[r] &= \sum_{k=0}^{N_0-1}\cos(\Omega k)\cos(r\Omega_0 k) - i \sum_{k=0}^{N_0-1}\cos(\Omega k)\sin(r\Omega_0 k) \end{align*} $$

Note that $x[k]$ has period $N = \frac{2\pi}{\Omega}$. If we have sampled exactly $p$ periods of $x[k]$, that is, $N_0 = pN$, then $\Omega_0 = \frac{2\pi}{pN}$ and equation $(6)$ becomes

$$X[r] = p\sum_{k=0}^{N-1}\cos(\Omega k)\cos(r\Omega_0 k) - ip \sum_{k=0}^{N-1}\cos(\Omega k)\sin(r\Omega_0 k) \tag7$$

Applying $(5)$ on $(7)$ removes the second sum

$$X[r] = p\sum_{k=0}^{N-1}\cos(\Omega k)\cos(r\Omega_0 k) \tag8$$

Substituting $\Omega = \frac{2\pi}{N}$ and $ \Omega_0 = \frac{2\pi}{pN} $ we are left with

$$X[r] = p\sum_{k=0}^{N_0-1}\cos\bigg(\frac{2\pi}{N} k \bigg)\cos \bigg(\frac{r}{p} \frac{2\pi}{N} k \bigg) \tag8$$

Here, we need to consider two cases: When $\Omega \neq \pm \pi$, that is, $N \neq 2, $or $\Omega = \pm \pi$, that is, $N = 2$.

In the special case where $\Omega = \pi$ we have only one value of $r$ with a non-zero result.

$$X[r] = p\sum_{k=0}^{1}\cos(\pi k)\cos(\frac{r}{p}\pi k) = \begin{cases}0 \; \; \; r \neq p \\\\ pN \; \; \; r = p \end{cases} \tag9$$

In the general case we have two values of $r$ yielding non-zero results. Recall that $\cos(\Omega k) = \cos( (-\Omega + 2\pi) k)$, which is equivalent to $\cos\bigg( (-\frac{2\pi}{N} + 2\pi) k \bigg) =\cos\bigg( (N-1)\frac{2\pi}{N}k \bigg)$.

This means that $(8)$ has two values of $r$ in $[0, N_0-1]$ that yields a non-zero result: $r=p$ and $\frac{r}{p}=N-1 \Rightarrow r = (N-1)p$.

Conclusion

The DFT of a time-discrete cosine signal $x[k] = \cos(\Omega k)$ with exactly $p$-periods of samples and length $N_0$ has one non-zero value if $\Omega = \pm \pi$ and two non-zeros values for the general case, when $r\in[0,N_0-1]$. More specifically $$X[r] = \sum_{k=0}^{N_0-1}x[k]e^{-jr\Omega_0 k} = \begin{cases} pN \; \; \; \Omega = \pm \pi , \; \; \; r = p \\\\ p\frac{N}{2} \; \; \; \Omega \neq \pm \pi, \; \; \; r = p \; \; \; \text{or} \; \; \; r = (N-1)p \\\\ 0 \; \; \; \text{otherwise}\end{cases}$$

This shows why the DFT of 500 Hz signal in the question has only two places where it is different from zero.

$\endgroup$
7
  • 1
    $\begingroup$ It's sorta interesting that the convention from Oppenheim and Schafer is to use $\Omega$ for continuous-time signals, like $x(t) = A \cos(\Omega_0 \, t)$ and to use $\omega$ for discrete-time signals like $x[n] =A \cos(\omega_0 \, n)$. I'm not sure if there is a fully established convention across the discipline. It's sorta like long ago the $a_k$ coefficients were in the numerator of the transfer function and $b_k$ coefficients in the denominator. Now, pretty much everyone, has reversed that convention. $\endgroup$ Commented Aug 5, 2024 at 15:21
  • 1
    $\begingroup$ @robertbristow-johnson The notation convention I use in this answer is the same as in “Signal processing and Linear systems” by Lathi. That is the best textbook I’ve ever used for any subject and I can highly recommend it if you haven’t seen it before. In Lathi he uses the convention for discrete signals $x[k]$ while most people on here use $x[n]$. Btw, does my answer look correct in your opinion? $\endgroup$ Commented Aug 5, 2024 at 17:41
  • $\begingroup$ Well, it looks like you're doing Fourier Series derivation. I've always said that the DFT and DFS are the same thing. It just seems to me that deriving the coefficients using the complex exponential instead the real $\sin$ and $\cos$ would be simpler. $\endgroup$ Commented Aug 6, 2024 at 0:50
  • $\begingroup$ @robertbristow-johnson I am showing that taking the DFT (or DTFS) of a cosine function that has been sampled for exactly p periods only yields two non-zero values on the interval $r \in [0, N_0-1]$. $\endgroup$ Commented Aug 6, 2024 at 7:58
  • $\begingroup$ It can be shown much more simply with just the complex exponential form of Fourier series and the exponential form of $\cos$. $\endgroup$ Commented Aug 7, 2024 at 1:39
0
$\begingroup$

The DFT of a finite duration sine/cosine is a sinc pulse with zero crossing at multiples of $1/T$Hz. The FFT is just sampled version of DFT, with samples at $f_s/N$ = $2$Hz in this case.

In the first case, the zero crossings were at multiples of $1/T$=$1/0.5$=$2$Hz, and coincidentally where the FFT samples the DFT waveform. So you didn't see any magnitude at those points. In the second case, the waveform shifted away from the sampling points of FFT. The waveform zero crossing are $499 \pm 2n$ Hz, but FFT sampling points are at multiples of $2$Hz. So you will see non-zero magnitude in FFT.

$\endgroup$
0
$\begingroup$

You can model your discrete signal $y[n]$ as an infinite sinusoid $x[n]=cos(2\pi f_0 n), n=[-\infty,\infty]$ multiplied by a (boxcar/rectangular) window function of 0.5 sec

$$w[n] = \begin{cases} 1 \qquad & \text{for } \ 0<n<f_s/2, \\ 0 \qquad & \text{otherwise} \\ \end{cases}$$

So we have

$$y[n] = x[n]w[n]=\cos(2\pi f_0n)w[n]$$

We can perform a Fourier Transform to get (the Discrete Time Fourier Transform, DTFT): $$Y(f) = X(f)*W_n(f)$$ Since y[n] was discrete, you have replicas of the baseband spectrum every $f_s$, but let's focus only on the baseband. An infinite length sinusoid has a Fourier Transform that is a delta function around its frequency, and a rectangular/boxcar window has a Fourier Transform called a Dirichlet Kernel (similar to the continuous sinc function) $$Y(f) = 0.5(\delta(f-f_0)+\delta(f+f_0))*W_n(f)=0.5W_n(f-f_0) + 0.5W_n(f+f_0)$$ where $W_n(f)$ is the Dirichlet kernel for $n=0.5f_s=2500$. So what you get is the Dirichlet kernel centered around the frequency $f_0$ (and $-f_0$) rather than 0. This derivation is for any $f_0$. We can think of the DFT as sampling the DTFT (which is continuous in the frequency domain) in the dft bins, i.e. $f=\frac{2\pi k}{N}$. So, even in the first case you showed, there is a Dirichlet kernel "hiding" there, you just don't see it. Why? because it happens that all all the other dft bins fall on the zeros of the dirichlet kernel, which are the points $x_k=\frac{2\pi k}{2n+1}, 𝑘∈ℤ$. To see that even in your first example there is still a Dirichlet kernel (i.e., the Fourier Transform of your first signal is not a pure delta function), you can pad the time domain signal with zeros and see the result. As for the second case, in this case you centered the dirichlet kernel to a place where you don't sample it only when it is equal to zero (with the dft bins of nfft=n)

$\endgroup$
1
  • $\begingroup$ Welcome to the DSP SE. I started cleaning this up, but you're mixing conventions of discrete-time and continuous-time that I cannot tell really which you mean. $\endgroup$ Commented Aug 5, 2024 at 15:30

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.