# Why am I getting unexpected result while implementing Fourier Transform?

I have considered five signals of different amplitude, frequency and phase components and applied Fourier Transform using the code given below:

Abs[Table[1/\[Pi] \!$$\*SubsuperscriptBox[\(\[Integral]$$, $$-\ \[Pi]$$, $$\(\ \$$$$\[Pi]$$\)]$$\((1.6 Cos[x\ + 0.3] + 3.9\ Cos[3\ x - 1.5] - 2.8\ Cos[7\ x + 1.7] - 80.1\ Cos[5\ x + 2.1] + 5.5\ Cos[9\ x - 2.4])$$
\*SuperscriptBox[$$E$$, $$\(\$$$$\(-\[ImaginaryJ]$$\ $$(\[Omega]\ x)\$$\)\)]\ \ \[DifferentialD]x\)\) , {\[Omega], 1, 10}]]


and the result is:

{1.6, 2.24011*10^-15, 3.9, 4.46075*10^-15, 80.1, 1.07175*10^-14, 2.8,
6.06724*10^-15, 5.5, 7.28752*10^-15}


After that, I got the argument values from

Arg[Table[1/\[Pi] \!$$\*SubsuperscriptBox[\(\[Integral]$$, $$-\ \[Pi]$$, $$\(\ \$$$$\[Pi]$$\)]$$\((1.6 Cos[x\ + 0.3] + 3.9\ Cos[3\ x - 1.5] + 2.8\ Cos[7\ x + 1.7] + 80.1\ Cos[5\ x + 2.1] + 5.5\ Cos[9\ x - 2.4])$$
\*SuperscriptBox[$$E$$, $$\(\$$$$\(-\[ImaginaryJ]$$\ $$(\[Omega]\ x)\$$\)\)]\ \ \[DifferentialD]x\)\) , {\[Omega], 1, 10}]]


and the corresponding result is:

{0.3, 3.04684, -1.5, -3.00265, 2.1, -2.50861, 1.7, 1.45689, -2.4, \
-2.47675}


Clearly, I'm getting some unwanted values for amplitude and phase. Although it's negligible for amplitude values, it's not so for the phases.

Please explain me where I've done wrong and what's the way out.

• Say you have a complex number whose absolute value is zero. Zero can have any phase. Now suppose it's numerically zero (like 10^-15). What is it's phase? It can be anything at all! Try Chop[] on those small values. – bill s Dec 19 '16 at 15:03
• @bills I can apply Chop[] on the magnitude values. However, What will I do for the phase values? – Majis Dec 19 '16 at 15:06

Say you have a complex number whose absolute value is zero. Zero can have any phase. Now suppose it's numerically zero (like 10^-15). What is it's phase? It can be anything at all! Try Chop[] on those small values. To be explicit:

tab = Table[1/\[Pi] \!$$\*SubsuperscriptBox[\(\[Integral]$$, $$-\ \[Pi]$$, $$\(\ \$$$$\[Pi]$$\)]$$\((1.6 Cos[x\ + 0.3] + 3.9\ Cos[3\ x - 1.5] - 2.8\ Cos[7\ x + 1.7] - 80.1\ Cos[5\ x + 2.1] + 5.5\ Cos[9\ x - 2.4])$$
\*SuperscriptBox[$$E$$, $$\(\$$$$\(-\[ImaginaryJ]$$\ $$(\[Omega]\ x)\$$\)\)]\ \ \[DifferentialD]x\)\) , {\[Omega], 1, 10}];


Now calculate Abs[Chop[tab]] and

Arg[Chop[tab]]
{0.3, 0, -1.5, 0, -1.04159, 0, -1.44159, 0, -2.4, 0}


The latter now reports the arg of the zero values as zero, which is probably what you intend. This has the added advantage that you only do the integral once.