Friday, October 26, 2018

matlab - Frequency vector and fft


I have got a question concerning the definition of the frequency vector for an fft operation.


Generally, I work with a frequency vector, f, with power of 2 elements (2048, 4096, 8192, ...).



Given a certain simulation analysis time, time (e.g. 600s), I should define f as follows:


% Frequency defition
t = 0:dt:(time-dt);
df = 1/(time);
fn = Nfft/time;

f=fn/2:df:fn/21;


where fn represent the Nyquist cut-off frequency.


Actually, for:




  • computational reasons

  • symmetry of the power spectra along f axis

  • not throwing away real or imag part of the fft


I aim to define only half of the frequency range, as for example


f=0:df:fn/21;


After calling the fft of my input signal, I would get the desired time series as


ouput = [real(fft) imag(fft)];

But, this way, I count the 0 frequency term twice and the -fn/2 is completely discarded.



How would it be possible to emcompasses the whole standard frequency range starting from only half of it?



Answer



The proper way to define your frequency vector after a DFT is as follows. Let N be your DFT length, and fs be your sampling rate in Hz. Furthermore, define an N-length frequency vector f, where each element fi=i, for i=0,1,2,...N1.


Now your frequency vector in hertz is simply going to be ffsN


Now, assuming you are DFT'ing a real sequence, simply pick all elements with frequency values less than fs2, and you are in business!


You can also see my answer here for actual code.


No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, MgX2+ is closest in radius to LiX+. Is this true, and if so, why would a whole larger shell ($\ce{...