X-axis for Fast Fourier Transformation

5 visualizaciones (últimos 30 días)
Ronald Tan
Ronald Tan el 20 de Oct. de 2018
Respondida: Star Strider el 20 de Oct. de 2018
Hello everyone,
I have a set of .csv files containing about 20,000 lines each. The first column is a time interval (10ms each) and the second, third and forth columns are for X, Y, and Z axes data respectively.
I've been having problems with the x-axis of my intended outcome. Have been getting warning message: Warning: Imaginary parts of complex X and/or Y arguments ignored
I've tried having the x-axis as 1/t, 1/10 and quite some other inputs but am still not able to get what i hope to get.
Hope that I could get some guidance on this.
Thank you in advance! :)
if true
% code
end
t=Data1(:,1);
x=Data1(:,2);
y=Data1(:,3);
z=Data1(:,4);
XX=fft(x);
YY=fft(y);
ZZ=fft(z);
DataFFT(:,1)= t;
DataFFT(:,2)= XX;
DataFFT(:,3)= YY;
DataFFT(:,4)= ZZ;
csvwrite(fullfile(folderSource,'FFT.csv'), DataFFT);
subplot(3,1,1);
plot(t,XX);
title('X-Axis');
subplot(3,1,2);
plot(t,YY);
title('Y-Axis');
subplot(3,1,3);
plot(t,ZZ);
title('Z-Axis');
end

Respuestas (1)

Star Strider
Star Strider el 20 de Oct. de 2018

I am not certain what you are doing, or what you want.

I usually create frequency vectors (the x-axis for a Fourier transform plot) this way:

Ts = mean(diff(t));                                     % Sampling Interval
Fs = 1/Ts;                                              % Sampling Frequency
Fn = Fs/2;                                              % Nyquist Frequency
Fv = linspace(0, 1, fix(numel(t)/2)+1)*Fn;              % Frequency Vector
Iv = 1:numel(Fv);                                       % Index Vector (For One-Sided FFT Plots)

The plots would then be:

plot(Fv,XX(Iv))
title('X-Axis')

or:

plot(Fv,abs(XX(Iv))*2)
title('X-Axis')

depending on what you want, and similarly for the others.

See the documentation on fft (link) for details.

Community Treasure Hunt

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

Start Hunting!

Translated by