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!