How to plot FFT?
15 views (last 30 days)
Show older comments
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')
0 Comments
Accepted Answer
Paul
on 9 Sep 2023
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
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])
More Answers (0)
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!