4
$\begingroup$

So I am taking the Fast Fourier Transform of the following function:

$$ x[n] = \displaystyle\sum\limits_{i=0}^{5} A_{i} \cos\left(\frac{\omega_{i}}{\omega_{s}} n + \phi_{i}\right) $$

Where the sampling rate $\omega_{s} = 2 \pi 8000$, the frequencies $\omega$, the phases $\phi$ and the amplitudes $A$ are: \begin{align} \omega &= 2 \pi \{500, 522, 610, 675, 746, 825 \}\\ \phi &= \{0,0,0,0,0,0\}\\ A &= \{1, 1, -1, -1, 1, -1\} \end{align}

The length of the signal is $N = 2048$ samples. No window is applied before taking the FFT.

The resulting FFT spectrum should have only a real component since the imaginary component should be zero. However, when taking the FFT and plotting the spectrum I get the following:

Real Spectrum Imaginary Spectrum

Why is the imaginary part not zero? It seems to be a discontinuity. However, I am not sure why it exists. Why does the imaginary part of the spectrum look like this?

$\endgroup$
  • $\begingroup$ What do you get if you apply a window? $\endgroup$ – John R. Strohm Mar 9 '18 at 0:47
5
$\begingroup$

Your parameters aren't correct for producing a whole number of cycles for each component.

For each $i$ the value of $ \frac{\omega_{i}}{\omega_{s}} N $ has to be a multiple of $ 2 \pi $.

Hope this helps.

Ced


Followup:

Suppose your signal is

$$ x[n] = A \cos( \alpha n + \phi ) $$

If $ \phi \neq 0 $ there is a possible solution which will give you a strictly real valued DFT bins besides one with a whole number of cycles. The condition that must be met is: $ \alpha N + 2 \phi $ must be a multiple of $ 2 \pi $.

For a whole number of cycles, your only non-zero bins will be at $ k $ and $ N-k $ where $ k $ is the number of cylces in the frame. There is no leakage. The bins will be real valued if $\phi = 0 $ or $\phi = \pi $.

For the alternative above, there will be leakage and it will all be real valued.

Edit: A simpler way of stating this is that your signal has to be symmetric about the center of your interval.


Response to comment:

Sorry, I didn't see your comment until after I posted the followup.

The mathematical answer lies in equations (23) through (25) in my blog article "DFT Bin Value Formulas for Pure Real Tones".

In order to have strictly real valued bin values, the value of $ U $ must be zero. For whole numbers of cycles, $ V $ is also zero and eq (25) becomes undefined at the relevant bins and you have to use equation (19). The alternative solution in my followup makes $ U $ zero, but not $ V $.

$\endgroup$
  • $\begingroup$ Okay I know that, but, so what? Is this the problem? If so, how can we show this mathematically? $\endgroup$ – The Dude Mar 8 '18 at 17:35
  • $\begingroup$ But my leakage is not real valued, it is complex valued. So how does this relate? From what I am understanding, you are saying to minimize leakage by selecting a sampling rate or length such that the frequencies fall on a DFT bin. This way, I won't get any of this imaginary garbage out in the FFT? I am going to take a look at your blog to understand deeper. $\endgroup$ – The Dude Mar 8 '18 at 18:03
  • $\begingroup$ @The Dude, I am wondering why you consider the imaginary part garbage. $\endgroup$ – Cedron Dawg Mar 8 '18 at 18:29
  • $\begingroup$ Thank you so much for the link to the blog post. It answered my question 100%. Great article, and many thanks! $\endgroup$ – The Dude Mar 8 '18 at 19:03
  • $\begingroup$ Cedron, only because I didn't want it. Thanks to your blog post, I understand why it is there. Thanks again, it was very informative and well written. $\endgroup$ – The Dude Mar 8 '18 at 19:04
3
$\begingroup$

Another way to produce strictly real FFT results (other than numerical rounding/quantization noise in the imaginary component) is to make sure that the wave form is circularly symmetric around time domain sample 0. For a cosine function starting with a phase of 0, this can be produced by doing an FFT shift (circularly rotating the input vector by N/2 samples).

This will work whether or not the cosine is exactly integer periodic in the FFT aperture, since it produces an purely even function around sample 0, which always produces a strictly real FFT result.

$\endgroup$
  • $\begingroup$ This is a really practical answer. Thanks for this! $\endgroup$ – The Dude Mar 9 '18 at 17:36

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.