Fast Fourier Transform from data in file
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jitendra Kumar Singh
le 7 Nov 2017
Commenté : Star Strider
le 17 Déc 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:-
load Ez_time.txt
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.
load Ez_time.txt
file = Ez_time;
aa = fft(file);
freq = linspace(0,6,19838);
plot(freq,abs(aa))
0 commentaires
Réponse acceptée
Star Strider
le 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.
4 commentaires
Plus de réponses (1)
miki90
le 14 Déc 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.
Voir également
Catégories
En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!