How to plot FFT of time domain data?

Dear all...
I have vibration data from Digital Storage Oscilloscope (DSO), the extension is 'xxx.CSV' . I need to convert it into Freq Domain (Magnitude vs Freq). I've tried several times and still stuck, I can't import that data into the formula/function. I've attached an excel file I got from the DSO (only 75KB), maybe you can download and see the excel files for complete information (like sample rate, length of signal,sample interval, etc). Ignore the CH2 (Impulse Hammer input) for a while, I only need the FFT from CH1 and plot it.. Can you guys help and suggest me, what function/formula should I write?
here's the link from dropbox.com (just in case) : DSO
Thanks in advance
Regards

 Accepted Answer

Star Strider
Star Strider on 16 Sep 2014
Edited: Star Strider on 16 Sep 2014
Guessing here as to what channel your data are in, but this seems to work:
[D, T, R] = xlsread('ADS00001.CSV');
F = D(:,4); % Data Channel
Ts = 2E-4; % Sampling Interval (s)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
F(isnan(F))=[]; % Eliminate ‘NaN’ Values First
LF = size(F,1); % Length of Data Vector
T = linspace(0,1,LF)*Ts; % Create Time Vector
figure(1) % Plot Data
plot(T, F)
grid
FF = fft(F)/LF; % Fourier Series of Data, Freq Vector
Fv = linspace(0,1,fix(LF/2)+1)*Fn;
Iv = 1:length(Fv); % Index Vector
figure(2) % Plot FFT
plot(Fv, abs(FF(Iv)))
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude')
axis([0 1500 ylim])

6 Comments

Doesn't the fourth column of the data correspond to time? (With a difference between each of 2e-05?)
When I plotted it it didn’t. It was a decaying impulse response. I believe the third one is time, since it looked linear when plotted against my synthesised time vector, but I couldn’t be sure. The fifth column seems to be the impulse hammer input. (All my references are to the xlsread output, since that is what I have to work with.)
That is an interesting difference between importdata and xlsread - the former will read in six columns (with the first three all NaN) whereas the latter will read in five columns (with the first two all NaN).
I went for xlsread as a first choice when I saw the file, because it neatly takes care of the text and numeric data without my having to do anything further. I would’ve gone to importdata next if xlsread had failed for some reason.
dude, it works! thanks a lot.. I have another question. how to detect max peaks on figure (2)?
My pleasure!
If you have the Signal Processing Toolbox, use findpeaks. For this particular problem, this works:
[A,L] = findpeaks(abs(FF(Iv)),'MinPeakDistance',10, 'MinPeakHeight',5E-4); % A = Amplitude
F = Fv(L); % F = Frequency
The first two it finds seem to be spurious, so you can manually delete them by simply taking A(3:end) and F(3:end).
This gives you (with a couple fprintf statements):
Frequency (Hz) Amplitude
76.667 5.80261E-03
110.000 1.38142E-03
221.667 8.47767E-04

Sign in to comment.

More Answers (2)

Nelson - it may be helpful to include what you have tried so that others can see what the problem may be and offer advice.
For importing the data from the csv file, consider using importdata. This will allow you to separate the header lines (of which you have ten) from the rest of the numeric data
myData = importdata('ADS00001.csv',',',10);
myData will be a structure; the numeric data (a 2992x6 matrix) will be in the field data. This matrix has three empty columns (the first three) followed by (presumably) the time stamp for each sample, the CH1 data, and the CH2 data
timestampsSec = myData.data(:,4); % in seconds
ch1Data = myData.data(:,5); % volts?
From timestampsSec we observe that the sample rate, Fs, is 1/2e-05 or 50000 samples per second. However there is only about 3/10 of a second's worth of valid data (the first 3/10 correspond to negative timestamps and the ch1 data is near zero - you will see this when you plot the data, time vs ch1).
See fft for examples on how you would transform ch1Data from the time domain to the frequency domain, and plot the result.
pilot 88
pilot 88 on 18 Mar 2016
Dear all,
How can I do FFT from my excel data - this accelerometer data from vibration test. The
FS = 500 Hz
First column = time
Second column is acceleration (m/s^2).
Data is as attached.
Thank you very much.

Asked:

on 16 Sep 2014

Answered:

on 18 Mar 2016

Community Treasure Hunt

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

Start Hunting!