# Quite confused with Fourier Analysis results

So I'm meant to show how the DFT can find the frequencies, and respective amplitudes, associated to some data. And I have this data set from the curve $$f(t) = 1 + 2\cos(2\pi t) + 4\cos(4\pi t)$$ sampled with a period $$T_s = 0.1$$ gives the following between 0 and 1, [7.00, 3.85,-1.62,-2.85,0.62, 3.00,0.62, -2.85,-1.62,3.85] and using the simple Scipy fft library it gives, $$\begin{bmatrix} 1.00000000\cdot 10^{1}+0.j\\ 9.98643159+0.j \\ 1.99952239\cdot 10^1 +0.j \\ 1.35684102\cdot 10^{-2} +0.j\\ 4.77614058 \cdot 10^{-3}+0.j\\ 0.00000000 +0.j\\ 4.77614058\cdot 10^{-3}-0.j\\ 1.35684102 \cdot 10^{-2}-0.j\\ 1.99952239 \cdot 10^{1}-0.j\\ 9.98643159 -0.j\\ \end{bmatrix}$$ My instructor has said that each frequency should be multiplied by two and the upper limit, in this case, would be $$\mathcal{F}[4]$$ however I'm still not sure where this comes from. Was hoping someone could explain this to me thank you.

• I think you might be confusing the e in your output! 1.2e3 means $1.2\cdot 10^3= 1200$, not $1.2e^3\approx 24$. – Marcus Müller Nov 19 '18 at 18:30
• also, from a quick look: the fifth and the seventh coefficient must be the same. My guess: you meant $e-3$ and wrote $e3$ instead in the fifth. – Marcus Müller Nov 19 '18 at 18:32
• I don't understand your comment. To what are you saying "no"? – Marcus Müller Nov 19 '18 at 18:37
• I still don't understand what you're saying "no" to. Please explain. I also don't understand where your formula "9.98/10" comes from. Can you elaborate? Why are you expecting that to be 2? – Marcus Müller Nov 19 '18 at 18:38
• If you know what e^x means, why are you then giving us numbers as factors in front of e^x ? (Still not quite sure you really mean what you write.) – Marcus Müller Nov 19 '18 at 18:39

You have a programming problem somewhere. Below I show you a very simple Matlab / Octave implementation of what you are after:

clc; clear all; close all;

Ts = 0.1;           % Sampling period
N = 10;             % number fo samples to take
t = Ts*(0:N-1)';    % sampling time points from t0=0 to tN-1 = Ts*(N-1)

f = 1 + 2*cos(2*pi*t) + 4*cos(4*pi*t)      % f(t) sampled at Fs=1/Ts
F = fft(f,N)      % N-point DFT/FFT of f(t)


And the output, at the Matlab console, of this simple computation is the following:

f =

7.0000
3.8541
-1.6180
-2.8541
0.6180
3.0000
0.6180
-2.8541
-1.6180
3.8541

F =

10.0000
10.0000 - 0.0000i
20.0000 - 0.0000i
0.0000 - 0.0000i
0.0000 + 0.0000i
-0.0000
0.0000 - 0.0000i
0.0000 + 0.0000i
20.0000 + 0.0000i
10.0000 + 0.0000i


As can be seen, the DFT $$F[k]$$ output is as expected. Note that the first DFT bin (k=0) $$F[0] = 10$$ is the $$N \times$$ the DC value of x[n]. Also, the DFT bins for $$k=1,2,8,9$$ (or the F vector elements at indices 2,3,9,10) correspond to those two cosine waves. Sepcifically bins 1 and 9 , and , bins 2 and 8 correspond to first and second cosine terms respectively.

This means that you have a programming error. To find where it is, first check that your time domain samples of f[n] are the same as those of f(t) printed above. If they are not the same, then your sampling stage has a problem. Most probably you have an issue in generating the sampling times. If the time domain sample values are the same as above then your DFT/FFT stage is doing something wrong. But that's a very weak probability.

• But I get the same results as you? But it's fine i understand why the values are doubled. – John Miller Nov 20 '18 at 22:03
• @JohnMiller they ar not the same. Look at your data, for example first three bins: F(0) = 10.0, F(1) = 9.98 , F(2) = 19.99 . Wheres data in my post is: F(0)=10.0, F(1)=10.0, F(2)=20.0 . So they are very close but not the same and the correct one is the second set. – Fat32 Nov 20 '18 at 22:29
• It's just because I sample my data to 3 significant figures not more. – John Miller Nov 22 '18 at 12:17
• oh I see it now! But your FFT results are not correct to any figures, interesting :-P ... – Fat32 Nov 22 '18 at 22:11