FFT using CSV data file

4 次查看(过去 30 天)
Mateusz Bess
Mateusz Bess 2017-7-4
Hi guys, ive been struggling with a task. I have to import the data from .csv file and then do the fft from the data imported, im using code like this:
filename = 'pomiary1.csv';
X = csvread(filename);
Fs = 2.5;
T = 1/Fs;
L = 100000;
t = (0:L-1)*T;
Fn = Fs/2;
FX = fft(X)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:length(Fv);
figure(1);
plot(Fv, abs(FX(Iv))*2)
grid
title('Fourier Transform Of Original Signal ‘X’')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
Code seems to be fine but the fft it gives is a straight line on 0 level (x axis) and i dont know why
I attached the data file first column is time second is the current

回答(1 个)

Star Strider
Star Strider 2017-7-4
I could not get csvread to read the file correctly, because each number in the second column has ‘;;;;’ following it in the file you attached.
This works:
[t,S] = xlsread(filename);
X = cellfun(@(c) sscanf(c,'%f;;;;'), S);
Ts = mean(diff(t));
Fs = 1/Ts;
L = length(t);
Fn = Fs/2;
FX = fft(X)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:length(Fv);
figure(1);
semilogy(Fv, abs(FX(Iv))*2)
grid
title('Fourier Transform Of Original Signal ‘X’')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
I changed your code slightly to correct for the sampling time interval and to define a few other variables from the data.
  6 个评论
Mateusz Bess
Mateusz Bess 2017-7-4
Thanks a lot for your time. I know your code works, i think its just my matlab issue, cause as u saw i dont have any plots just empty diagrams. I'm working on it, could you please send me a screenshot of this figure(3) i would be so grateful.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Measurements and Feature Extraction 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by