Fast Fourier Transform for csv file with multiple column

5 views (last 30 days)
Hello,
I have a set of .csv files containing about 20,000 lines each. The first column is a time interval (10ms) and the second, third and forth columns are for X, Y, and Z axes data respectively.
After reading this set of data and plotting them in their time domain, I am trying to perform a Fast Fourier Transform for them and plotting them in a graph, and also to generate a new .csv file with the data that underwent fft.
I've been reading up some other post of fft but seems like that are some parameters such as frequency that I am unsure of how I can get them.
I'm not sure how I should go about solving this and hope that some of you may be able to help me with this issue.
I have attached my code below
{
folderSource= 'C:\Users\r-o-n\Desktop\DP2\Testing2\csvtest\Incoming';
folderDestination= 'C:\Users\r-o-n\Desktop\DP2\Testing2\csvtest\Incoming\';
csvFiles=dir(fullfile(folderSource,'*.csv'));
for k=1:length(csvFiles)
baseFileName=csvFiles(k).name;
fullFileName=fullfile(folderSource,baseFileName);
inData=csvread(fullFileName,1,0);
end
t=inData(:,1);
x=inData(:,2);
y=inData(:,3);
z=inData(:,4);
subplot(3,1,1);
plot(t,x,':');
title('X-Axis');
ylabel('X-Acceleration (mg)');
subplot(3,1,2);
plot(t,y,':');
title('Y-Axis');
ylabel('Y-Acceleration (mg)');
subplot(3,1,3);
plot(t,z,':');
title('Z-Axis');
ylabel('Z-Acceleration (mg)');
xlabel('Time (ms)');
%would like to perform FTT to the data (both X,Y and Z)
xdft = fft(inData(:,2));
}
Thanks in advance! :)
Best Regards, Ron

Accepted Answer

Dimitris Kalogiros
Dimitris Kalogiros on 14 Sep 2018
You must find Fsampling.
You can achieve this by observing values of vector t. If t(k)-t(k-1) is the same for each 1<k<length(t) then you have "uniform sampling" and everything is OK for you. You can use as Fsampling the quantity 1/(t(k)-t(k-1)) , for whatever k you want, and follow the recipes of the "other posts"
Good luck

More Answers (0)

Community Treasure Hunt

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

Start Hunting!