# Fast Fourier Transform from data in file

51 views (last 30 days)
Jitendra Kumar Singh on 7 Nov 2017
Commented: Star Strider on 17 Dec 2017
Hello everyone,
I am getting vector length error in a matlab code. The problem is that I don't know how to construct vectors properly.
The file contains single column of electric field time domain data. Number of rows are 19838, which means the time of recording is sampled at these points. Total time is around 33 picoseconds.
Now I want to convert this time domain data to frequency domain data in range 0.001 to 6 GHz. How should I sample my frequency?
My code:-
file = Ez_time;
aa = fft(file);
%File contains 19838 rows each correspoing to
% one time step. Total time is around 33 picoseconds.
T =length(file);
Fs = 1/T;
%For taking fft in a frequency range 0.001 to 6 GHz
freq = 0.001 : 1./T : 6;
plot(freq,abs(aa));
Alternatively, I also tried below written code, but this isn't giving me the right spectrum.
file = Ez_time;
aa = fft(file);
freq = linspace(0,6,19838);
plot(freq,abs(aa))

Star Strider on 7 Nov 2017
Try this:
L = length(file); % Signal Length
t = linspace(0, 1, L)*33E-12; % Time Vector (s)
Ts = mean(diff(t)); % Sampling Time (s)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
aa = fft(file)/L; % Fourier Transform (Scaled)
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector (One-Sided)
Iv = 1:length(Fv); % Index Vector
figure(1)
plot(Fv, abs(aa(Iv))*2)
set(gca, 'XLim',[0.001 6]*1E+9)
The plot is not going to be very informative, since the steps of the frequency vector are 30.3015 GHz. You will have to sample at a much higher frequency if you want any detail in that range.
Star Strider on 7 Nov 2017
As always, my pleasure!

miki90 on 14 Dec 2017
Hello. I didn't want to start the different topic for the same problem, so I will be thankful if anyone can help me. I have the data in the file, gained from the acquisition in LabVIEW. There is a matrix of voltages in the file, with frequency sampling of 1kHz, and the number of samples - 10000. I need to find the frequency range in which the signal belongs to, using these data. I tried to follow the example found on the Mathworks site, but I get only the straight horizontal line with the one peak at about 2.5, which is the magnitude. Can anyone help me with this task? Thanks in advance.
##### 2 CommentsShow 1 older commentHide 1 older comment
Star Strider on 17 Dec 2017
@miki90 — I find this documentation on the fft (link) function a bit easier to follow.