MATLAB: How to perform fft in matlab using a set of data from excel sheet

fft of data from excel sheet

Fs=3800;
Ts=1/Fs;
t=0:Ts:1;
L=97;
Y=abs(fft(VarName1)); %varname1 is the filename of the excel sheet
P1=Y/L;
P2=P1(1:(L+1)/2);
P2(2:end-1)=2*P2(2:end-1);
f=Fs*(0:(L/2))/L;
plot(f,P2)
xlabel('frequency')
ylabel('magnitude of P1')
Is this correct?

Best Answer

I doubt if your code would work.
Try mine:
[d,s] = xlsread(VarName1); % Data in ‘d’
Fs=3800; % Sampling Frequency
Ts=1/Fs; % Sampling Interval
Fn = Fs/2; % Nyquist Frequency
L = size(d,1); % Length Of Arrayt
t = linspace(0, 1, L); % Time Vector
FTd = fft(d)/L; % Complex Fourier Transform Of ‘d’
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Matching Index Vector (For ‘FTd’ Addressing)
figure(1)
plot(Fv, abs(FTd(Iv))*2)
xlabel('frequency')
ylabel('magnitude of P1')
NOTE This is UNTESTED CODE. It should work, but may require modification.
Related Question