1
$\begingroup$

I have been buzzed about this issue for more than an hour. I have been tasked to execute a simple DTFT task using MATLAB for the signal $x(t):=\cos(2\pi f_{0}t)$. Assuming we are sampling at a rate of $200\operatorname{Hz}$ at $0.5\operatorname{sec}$ i.e., we require $N=100$ sampled points. Furthermore, let $f_{0}:=55\operatorname{Hz}$.

The time interval specified is $5\times10^{-3}\leq t\leq 0.5$ in seconds. Using MATLAB I first defined $t$ as a vector of size $100\times 1$. Therefore, let t=linspace(5e-3,0.5,100) so that x=cos(2*pi*55*t) in addition to the frequency vector f=linspace(-fs/2,fs/2,100) where fs=200 and then finally, execute the command X=fftshift(fft(x/100)).

Plotting the magnitude spectrum on MATLAB using $\mathsf{stem(f,abs(X))}$ produces the following result : enter image description here

While this simply accomplishes this task, I am not satisfied with the result without understand the following :

  1. Why are there low-quantized frequencies in between and out of $f=\pm 55\operatorname{Hz}$? We know by theory that $x[n]=\cos(2\pi f_0n)\xrightarrow{\mathscr{F}}0.5[\delta(f-f_{0})+\delta(f+f_{0})]$, this also leads me to the second question.
  1. I defined DFT as $$X[k]:=\frac{1}{N}\sum_{n=0}^{N}x[n]\exp\left(-j\frac{2\pi kn}{N}\right)\tag{1}$$ In theory, the amplitude should lie exactly at $0.5\operatorname{Hz}$, this is in contrast with the observation that the amplitude is about $0.33$. Why is this occuring? The way I defined DFT should scale the magnitude of the output to $0.5$
  1. Why does it take two points to represent $\delta(f-55)$ and two points to represent $\delta(f+55)$? We should expect one sharp delta. I am sampling even-number of points could this be the issue?

Note that for the first question, I did a bit of research on the web and I received some results about spectral leakage, It seems to hint about some aspects related to the number of oscillations occurring with respect to the number of sampled points.

Another note: Having these three questions answered would grant me the ability to understand more about how frequency spectrum is affected by number of sampled points, it will also allow me to get introduced to new concepts such as spectral leakage if that's the case for my first question, it will also help me manipulate DTFT more while understanding the variations such as changing $f_{0}$ and $N$ and observing how the frequency domain reacts.

$\endgroup$
2
  • 2
    $\begingroup$ You are not calculating the DFT of a cosine. You're calculating the DFT of a cosine multipled by a rectangle. All your questions are answered in many different answers in this website. It'd pay off to spend some time searching for similar questions. $\endgroup$
    – MBaz
    Feb 25, 2022 at 19:52
  • $\begingroup$ This visual might help. $\endgroup$ Feb 25, 2022 at 20:40

2 Answers 2

1
$\begingroup$

All three of your questions center about the topic of spectral leakage, which occurs when a periodic signal does not have an integer number of periods in the measurement window. Window functions can be used to mitigate the effects of spectral leakage, but not without trade-offs. There are plenty of answers about this topic on this site.

Also, your frequency vector is incorrect. For a two sided DFT, it should be f=((-N/2):(N/2-1))*fs/N after fftshift. The Nyquist component is only included on one side of the spectrum, not both.

$\endgroup$
1
$\begingroup$

The length of your FFT has convolved your cosine waveform with a rectangle the length of the FFT. The transform of that rectangle is a Sinc function, which has a non-zero skirt (or stop band).

If you use Sinc interpolation between the two highest peaks, you will eventually find your expected amplitude.

To get a single peak, use an FFT with a length that is an exact integer number of periods of the cosine waveform. A Sinc function convolution will then produce zeros at all but one (below Nyquist) bin.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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