Need help with an FFT function

1 次查看(过去 30 天)
the questioneer
the questioneer 2017-3-16
Hello everyone.
My problem is such- i have 2x1 matrix with a column of times and another of function which is time dependent. How do i correctly convert the time dependent function to the frequency domain using FFT? What i've done is to convert the function and than, using the fact that the sampeling frequency is given to me to construct a frequncy vector matching the length of the function column. I get a fairly reasonable plot, however i am not entierly sure my answer is correct, especially because i haven't used the time column, which is given to me
  3 个评论
John D'Errico
John D'Errico 2017-3-16
As Adam said, trying to guess what you did wrong is impossible. That means we would need to instead guess exactly what you want to do, and then write it completely for you.
By showing what you have done, it is far easier to correct what you did. This helps those who might be willing and able to help you.
the questioneer
the questioneer 2017-3-16
编辑:Star Strider 2017-3-16
First of all, I apologize for the double post. Couldn't for some reason find the original post.
Secondly, the code is:
Fs = 2000; %1/sec
L=length(Q2(:,2)); %length of the function column
f = (0:L-1)*Fs; %frequency vector
y1=fft(Q2(:,2)); %fft on the function
Y1=abs(y1);
plot(f,Y1);

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2017-3-16
I continue to refer to the R2015a documentation for fft (link).
See if this provides a better result:
Fs = 2000; % 1/sec
Fn = Fs/2; % Nyquist Frequency
L=length(Q2(:,2)); %length of the function column
f = linspace(0, fix(L/2)+1)*Fn; % frequency vector
Iv = 1:length(f); % Index Vector
y1=fft(Q2(:,2))/L; % fft on the function
Y1=abs(y1);
figure(1)
plot(f,Y1(Iv)*2)
grid
If it is difficult to see frequencies other than the 0 Hz d-c- offset value, subtract the mean of your signal first:
Fs = 2000; % 1/sec
Fn = Fs/2; % Nyquist Frequency
Q2(:,2) = Q(:,2)-mean(Q(:,2);
L=length(Q2(:,2)); %length of the function column
. . . THE REST OF YOUR CODE IS UNCHANGED . . .
  2 个评论
the questioneer
the questioneer 2017-3-16
First of all- thank you very much. Secondly, why is the FFT normalized by the length of the vector?
Star Strider
Star Strider 2017-3-16
My pleasure.
The Fourier transform is calculated as the sum of sine and cosine functions over the lenght of the time-domain vector, so the amplitude of the individual frequencies are the sum of these. Normalising by the length of the vector corrects for this. (Any textbook on digital signal processing discusses this in detail.)
In addition, the Fourier transform calculates a ‘double-sided’ (positive and negative frequencies) transform, with the energies of the individual frequencies divided equally between each positive and negative frequency. Because of this, in plotting a one-sided Fourier transform, it is necessary to multiply the amplitudes by 2 to give an accurate estimate of the amplitudes of the constituent frequencies in the signal, as I did in the code I posted.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by