How to plot FFT?

조회 수: 15 (최근 30일)
Sara Boznik
Sara Boznik 2023년 9월 9일
댓글: Sara Boznik 2023년 9월 9일
Hi,
I am trying to plot FFT of tuning fork. I know that peak must be at 440 Hz. I am trying with my Matlab code but nothing works. Please for help.
plot(t,p)
title 'Časovni potek zvočnega signala'
grid on
xlabel '{\itt} [s]'
ylabel '{\itp}'
m = length(p);
n = pow2(nextpow2(m));
y = fft(p,n);
figure(2)
f = (0:n-1)*(1/n)/10;
amplituda = abs(y).^2/n;
plot(f(1:floor(n/2)),amplituda(1:floor(n/2)))
xlabel('Frekvenca(Hz)')
ylabel('Amplituda')

채택된 답변

Paul
Paul 2023년 9월 9일
Hi Sara,
The frequency vector needs to be corrected. And for this data it's helpful to subtract out the mean before taking the fft.
% load in the data and run the original code
vilice
t = 1001×1
1.0e+00 * 0 0.0001 0.0002 0.0003 0.0004 0.0005 0.0006 0.0007 0.0008 0.0009
p = 1001×1
2.6691 2.6593 2.6508 2.6496 2.6447 2.6386 2.6435 2.6508 2.6557 2.6508
jCorrect expression for frequency
f = (0:n-1)*(1/n)*1e4;
Subtract mean
y = fft(p-mean(p),n);
amplituda = abs(y).^2/n;
figure
plot(f(1:floor(n/2)),amplituda(1:floor(n/2)))
xlim([200 600])
  댓글 수: 1
Sara Boznik
Sara Boznik 2023년 9월 9일
Thank you so much, I am satisfied with that result.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by