2
$\begingroup$

I started off with this:

$$ x = 5 \cos(200 \times 2 \pi t ) + 10 \cos( 400 \times 2 \pi t)$$

by performing a 1024 point DFT on it. Then I performed IDFT on the complex values obtained through DFT. Now, I want to express the original wave in terms of it's harmonics, so when I combine the DC and first harmonic or upto n harmonics, I get the original wave back. But how do I obtain these harmonics?

This is what I actually want to do. I have some real valued data(144 points). I want to express this data as a sum of cosines. For this purpose, I perform a 144 point DFT operation on this data, and bring them to frequency domain. Does the Euler's identity, give me these cosine?

$$X[k] * e^{\tfrac{j2\pi kn}{144}} + X[144−k] * e^{\tfrac{−j2\pi kn}{144}}$$

Please help me obtain the Amplitude and phases of these harmonics.

$\endgroup$
4
  • $\begingroup$ Your cosines are both of the same frequency. Are you sure you wrote down the question correctly? $\endgroup$
    – Phonon
    Commented Feb 21, 2012 at 19:51
  • 1
    $\begingroup$ I'm not sure I understand your question. What you want is just the harmonics that represent those two sinusoidal signals? And if I understand correctly, by harmonics you mean the frequency at which each cosine is centered? You want the amplitude and phase of the cosines? I'm not understanding your question :S $\endgroup$ Commented Feb 21, 2012 at 22:39
  • $\begingroup$ possible duplicate of Calculate harmonics using DFT from real points $\endgroup$ Commented Feb 22, 2012 at 0:33
  • 2
    $\begingroup$ Discrete Cosine Transform?... $\endgroup$
    – Spacey
    Commented Feb 22, 2012 at 6:48

1 Answer 1

1
$\begingroup$

The Fourier transform converts signals into coefficients of cosines and sines. This is why the coefficients are complex. Simply adding up those two coefficients won't give you sufficient information about the phase (someone can correct me on this statement, but I believe it's true). In other words, for signal of length N you're trying to find coefficients $a_k$ and $b_k$ such that

$$ x[n] = \sum_{k=0}^{N/2} a_k \cos(\omega k)+\sum_{k=0}^{N/2} b_k \sin(\omega k)$$

I would suggest using Discrete Cosine Transform (DCT) instead. It literally breaks you signal up into a sum of cosines, it gives you back all real coefficients and it takes care of the phase problem completely.

If you must use Fourier Transform, you should realize that

$$e^{i \omega t} = \cos (\omega t) + i \sin(\omega t)$$

This tells us that we can recreate the even-symmetric component (cosine) from real coefficients of the Fourier Transform, and odd-symmetric component (sine) from imaginary coefficients of the Fourier Transform.

The formula then befomes:

For a given $k$,

$$a_k \cos\left( \frac{2 \pi kn}{N} \right) = \frac{1}{N}\left( \Re (X[k]) e^{ \tfrac{i 2 \pi kn}{N}} + \Re (X[N-k]) e^{ \tfrac{i 2 \pi (N-k)n}{N} } \right), $$

$$b_k \sin\left( \frac{2 \pi kn}{N} \right) = \frac{1}{Ni}\left( \Im (X[k]) e^{ \tfrac{i 2 \pi kn}{N}} + \Im (X[N-k]) e^{ \tfrac{i 2 \pi (N-k)n}{N} } \right), $$

where $\Re(\cdot)$ and $\Im(\cdot)$ represent taking real and imaginary part of a complex number respectively. Note that this is done for each $n \in \{0 \ldots N-1\}$

Note that because of circular symmetry of DFT, $X[N] = X[0]$, so you'll end up adding up the same thing twice according to the formula above. If you do that, then the actual $a_0$ is half of what you get according to the formula above. If you find this division by 2 confusing, this section of Wikipedia article on Fourier Series may provide a better explanation (look for the formula where $a_0$ is divided by 2).

$\endgroup$
8
  • $\begingroup$ Beware of lots of typographical errors in the statement: "For each $k$, $$a_k \cos\left( \frac{2 \pi kn}{N} \right) = \Re (X[k]) e^{ \tfrac{i 2 \pi kn}{N}} + \Re (X[N-k]) e^{ \tfrac{i 2 \pi (N-k)n}{N} }, $$ $$b_k \sin\left( \frac{2 \pi kn}{N} \right) = \frac{1}{i}\left( \Im (X[k]) e^{ \tfrac{i 2 \pi kn}{N}} + \Im (X[N-k]) e^{ \tfrac{i 2 \pi (N-k)n}{N} } \right), $$ where $\Re(\cdot)$ and $\Im(\cdot)$ represent taking real and imaginary part of a complex number respectively. Note that this is done for each $n \in \{0 \ldots N-1\}$" $\endgroup$ Commented Feb 23, 2012 at 3:39
  • $\begingroup$ @DilipSarwate I have to be either blind or wrong in my math. Feel free to fix it or post your own answer. $\endgroup$
    – Phonon
    Commented Feb 23, 2012 at 3:45
  • $\begingroup$ @DilipSarwate ...or point out what's wrong. Is it the math or the style? I checked the formula with MATLAB. Recovered the signal fine. $\endgroup$
    – Phonon
    Commented Feb 23, 2012 at 3:49
  • $\begingroup$ I had voted to close this question as a duplicate of another one which had been answered and the (correct) answer there accepted by OP Rakesh. Your answer is wrong because it does not distinguish $X[0]$ must always be treated separately, and when $N$ is even, as it is in this case, $X[N/2]$ must also be must be treated separately. See Hilmar's answer to the other question or Wikipedia. The result is something that looks like your (continued) $\endgroup$ Commented Feb 24, 2012 at 2:29
  • $\begingroup$ $$x[n] = \sum_{k=0}^{N/2} a_k \cos(\omega k)+\sum_{k=0}^{N/2} b_k \sin(\omega k)$$ which also has typos since the a_0 term is missing. Your assertion that "Note that this is done for each $n \in \{0…N−1\}$" is incorrect; you only need to do it for $1 \leq n \leq (N-1)/2$ and you need to account for $n=0$ and $n=N/2$ (even $N$) separately. $\endgroup$ Commented Feb 24, 2012 at 2:39

Your Answer

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

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