0
$\begingroup$

I've set up this case to try to understand DFT implementing a real case in Excel

Frame Size $\;\color{blue}{(T}$): 5 s
Time Sampling $\;\color{blue}{(TS}$): 0,1 s
Block Size $\;\color{blue}{(N = TT/TS+1)}$: 51
Sampling Rate $\;\color{blue}{(FS = TT/TS+1)}$: 10 Hz
Frequency Resolution $\;\color{blue}{(FR = FS/(N-1))}$: 0.2 Hz

In time spectrum I have put just 2 sines functions added

The firt sine has amplitude $\color{blue}{10}$, phase $ \color{blue}{\pi/3}$ and frequency $\color{blue}{2}$ Hz. The second sine has amplitude $\color{blue}{5}$, phase $\color{blue}{0}$ and frequency $\color{blue}{1}$ Hz: $ \color{blue}{\quad ( n = 0\; to \;50)}$

$$ \color{blue}{X[n] = 10\, \sin{(2\pi t 2 + \pi/3)}+ 5\, \sin{(2\pi t 1)}}$$

So I have generated DFT values where $\color{blue}{\; k=0\; to\; 50\quad }$ and $\color{blue}{\quad x_k=a_k + ib_k}\;$:

$$\color{blue}{a_k = (1/N) \; \Sigma_{n=0,N-1} X_n \cos{(2 \pi n k /N)}} $$ $$\color{blue}{b_k = (1/N) \; \Sigma_{n=0,N-1} X_n \sin{(2 \pi n k /N)}} $$

After, I've calculated module $\color{blue}{A}$ and phase $\color{blue}{\Phi}$ for $ \color{blue}{\; ( n = 0\; to \;50)}$

$$\color{blue}{A_k = \sqrt{(a_k)^2 + (b_k)^2}} $$ $$\color{blue}{\Phi_k = atan2(b_k, a_k)} $$

I consider in my analysis $$\color{blue}{ Freq_k = k.FS/(N-1)} $$

Now my doubt arise. In my understanding, the signal should be concentrated in the values of frequencies $\color{blue}{1}$ Hz and $\color{blue}{2}$ Hz. It is not. Not even remotely. Amplitude $\color{blue}{A_k}$ for $\color{blue}{8.2}$ and $\color{blue}{9.2}$ Hz are very strong. In short, the frequency spectrum is very noise. Also $\color{blue}{2.2}$ Hz and $\color{blue}{8}$ hz amplitudes are almost half of $\color{blue}{1}$ Hz amplitude.

I'm working with frequence sampling $\color{blue}{10}$ Hz, five times than maximum detected frequency ($\color{blue}{2}$ Hz).

What's happening?

To check if I had made a mistake, I calculated the DTF inverse and the original signal was restored exactly!

$\endgroup$
  • $\begingroup$ It is not clear that there is a problem. You will always get extra peaks at the high end of the spectrum, in particular $A_{N-k} = A_k$, due to aliasing. You can interpret those peaks as existing at $A_{-k}$ instead. Also, since the period of your signal is exactly 50 samples, you should drop the 51st one, and then the spectrum ought to be what you expect. $\endgroup$ – Rahul Oct 6 '18 at 21:28
  • $\begingroup$ Not exactly, my total period is 5 s, 51 samples, 0.1 s between samples. When I take out the last data, the inverse DFT not match anymore. I've made a complete IDFT and all real part match with original sign and all complex part is 0. $\endgroup$ – Paulo Buchsbaum Oct 6 '18 at 22:04
  • $\begingroup$ I'm studying the aliasing. I'm new in DFT so it's hard for me. $\endgroup$ – Paulo Buchsbaum Oct 6 '18 at 22:05
  • $\begingroup$ Now I'm using k from -25 to 25, 51 samples. It improves a lot! The bigger values are -2Hz, -1Hz, 1Hz and 2Hz, but 2,2 Hz amplitude is around 25% of 2 Hz amplitude. Is it normal? $\endgroup$ – Paulo Buchsbaum Oct 6 '18 at 22:13
0
$\begingroup$

DFT frequencies may be easier to think of as going from -SR/2 to SR/2 instead of from 0 to SR. Then for real-valued input, F(-k) = conj(F(k)).

$\endgroup$
  • $\begingroup$ I'm new in DFT. I will try this approach. $\endgroup$ – Paulo Buchsbaum Oct 6 '18 at 22:05
  • $\begingroup$ I've made the changes and now I'm using k from -25 to 25 (51 samples from - 5 Hz to 5 Hz). It improves a lot! The bigger values are -2Hz, -1Hz, 1Hz and 2Hz, but 2,2 Hz amplitude is around 25% of 2 Hz amplitude, my sampling rate is 10 Hz. Is it normal? $\endgroup$ – Paulo Buchsbaum Oct 6 '18 at 22:11
  • $\begingroup$ you should use BlockSize = TotalTime / SampleTime without any +1, you may be getting bin leakage because the waveform is a sine wave with one extra sample; for a sine wave the last sample of the input will be different from the first sample (this is normal) $\endgroup$ – Claude Oct 6 '18 at 22:47

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.