FFT for an arbitrary plot using MATLAB

Dear All, My question has not received much attention apparently. It might be too simple but I do not know how to use FFT tool implemented in MATLAB. Assume I have an arbitrary plot of the evolution of variable y in time. The plot obtained from the following data:
0 116.0080214
0.0005 116.051128
0.001 116.0939229
0.0015 116.1362197
0.002 116.1776665
0.0025 116.2178118
0.003 116.256182
.
.
.
.
50.0 123.000
The first and second columns represent time and the value of y at the corresponding t respectively. As it is clear in the data format time interval of the plot is from 0 to 50 ps. And I have data for the y component of the plot every 0.5 fs. Basically the plot contains 100000 data printed every 0.5fs. Using information of this page, I guess I have to choose the following values for my calculation:
Fs = 100000/50; % Sampling frequency (in 1/ps)
T = 1/Fs; % Sample time (in ps)
L = 100000; % Length of signal
t = (0:L-1)*T; % Time vector; my first column should replace this
% Also I know that the second column would be the y in the sample code used as an example in that page!
I do not know hoe I have to define X. I do appreciate any of your helps to illustrate it more for me! Best

 Respuesta aceptada

Walter Roberson
Walter Roberson el 24 de Jun. de 2015
In the notation of that page, you have x and y reversed. They use x to refer to the samples in time, and y to refer to the frequency information, whereas you are using y to refer to the samples in time. Using your notation, all that is needed is
result = fft(y(:,2));
and all the rest of what is there has to do either with generating data for use in the example, or has to do with labeling plots correctly.

5 comentarios

Dear Walter, I wrote it in this way and it gives me a plot as an output. I just want to double check if I am right!
y=xlsread ('ffttest.xlsx'); % my data file which is matrix. The first column is t and the second one refers to samples in time
Fs = 100000/50; % Sampling frequency (in 1/ps)
T = 1/Fs; % Sample time (in ps)
L = 100000; % Length of signal
t = (0:L-1)*T;
plot(Fs*t(1:100000),y(: ,2));
NFFT = 2^nextpow2(L); % However, I do not understand what it exactly is!!
Y = fft(y(:,2),NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(Y(1:NFFT/2+1)))
Thanks Walter
You can simplify your first plot() to
plot(Fs*t,y(: ,2));
and I would suggest you consider
y = xlsread('ffttest.xlsx');
T = 50/100000;
Fs = 1/T;
L = size(y, 1);
t = 0 : T : (L-1)*T;
plot(t, y(:,2));
Homayoon
Homayoon el 25 de Jun. de 2015
Thanks! :-)
However Walter, I still do not understand the meaning of :
NFFT = 2^nextpow2(L); % However, I do not understand what it exactly is!!
would you please help to understand it? best
Walter Roberson
Walter Roberson el 29 de Jun. de 2015
2^nextpow2(L) effectively "rounds up" to the next power of 2 from L. For example, the first power of 2 above 93 is 128 which is 2^7; nextpow2(93) would return 7 and 2^7 would give the 128. Likewise it would round 8191 up to 8192. But 2^nextpow2(L) is always the same as L if L is already a power of 2.
The reason for "rounding up" to the next power of 2 for FFT has to do with the performance of the Fast Fourier Transform, as FFT is fastest if the number of points is a power of 2. The original FFT algorithm only applied for exact powers of 2; extensions were later made to do prime decomposition of the length.
Basically on modern computers, the only reason to bother would be if you are doing millions of FFT of the same length, or if you are planning to do code generation for a DSP or FPGA. Just leave that part out for your purposes.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 24 de Jun. de 2015

Comentada:

el 29 de Jun. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by