how to perform fft in matlab using a set of data from excel sheet
14 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Star Strider
2017-3-11
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.
3 个评论
Star Strider
2017-3-11
‘could you tell me if I could do fft on the same excel sheet with two columns of data simultaneously?’
Yes, you can. The fft (link) function operates column-wise in a matrix, so it will take the Fourier transforms of each column with the same call to it. The frequency and index vectors will be the same as well. They should work without modification with your matrix.
ahmad syaiful md subri
2019-11-22
dataset=xlsread('Group5.xlsx','Sheet1','A1:ALM1')
tstep=0.001;
N=1;
t = 0:0.001:1-0.001;
x=dataset;
X=fft(x);
n=size(x,2)/2;
spec=abs(x)/n;
freq=(0:499/2*n*tstep);
plot(freq,spec(1:500));
can somebody help me..error :
Error using plot
Vectors must be the same length.
Error in Untitled (line 11)
plot(freq,spec(1:500));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!