How can i create a FFT/FRF graph using matlab from csv file?

as the title, i want to convert the data to the frequency domain using FFT... and here the csv....which function should i use? tfestimate or fft to generate FRF in order to get the natural frequency....

 Accepted Answer

clc;
data = csvread('data.csv') ;
t = data(:,1) ;
amp = data(:,2) ;
L = length(t) ;
dt = max(diff(t)) ;
Fs = 1/dt ;
Y = fft(amp);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
% xlim([0 3000])

3 Comments

if i got the input and output data should i use tfestimate or fft?
For fft you have to use fft.
in this code why we used p1(2:end-1)=2*p1(2:end-1). unless in ploting we only used p1 value??

Sign in to comment.

More Answers (1)

Hi, I am having problem to generate FFT from time-domain data of csv file. I can generate values of two variables from the two rows. The first row contains time and the second row contains current. Now I can generate a normal plot. But I want to plot FFT and power spectral density. I got the csv from a simulation (Cadence). there is no fixed step-size of the time values which is problem. Can anyone help me generating FFT and psd? I have attached the file for your convenience.

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Asked:

on 14 Mar 2017

Commented:

on 30 Apr 2018

Community Treasure Hunt

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

Start Hunting!