How can i determine phase in FFT?
Show older comments
Hi everyone, right now im trying to calculate signal phases using angle(x) from FFT Function im Matlab. Noted that i've coded the program like below :
%%Plotting Grafik
%create a time vector 't', containing integers from 1 to n(summary of data)
count= length(data);
Ts=mean(diff(times1));
Fs=1/Ts;
NFFT=2^nextpow2(count);
y=fft(data,NFFT)/count;
f=Fs/2*linspace(0,1,NFFT/2+1);
figure(2)
plot(f,2*abs(y(1:NFFT/2+1)));
grid on
title('Single-Sided Amplitude Spectrum of y(t)');
xlabel('Frequency(Hz)');
ylabel('|Y(f)|');
phase=angle(y);
But i'm not really sure with the phase function. Does anyone ever has the same experience?
Thanks before for your answer.
6 Comments
Dan Bullard
on 18 Mar 2023
I use this constantly in Excel, it's atan2(real, imaginary)
With this I proved Bullard Laws of Harmonics #5,
http://www.danbullard.com/dan/articles/why_law_5_is_so_important/why_law_5_is_so_important.html
Star Strider
on 18 Mar 2023
Bruno Luong
on 19 Mar 2023
Edited: Bruno Luong
on 19 Mar 2023
@Dan Bullard "it's atan2(real, imaginary)"
That formula is wrong the right formula is atan2(imaginary, real) and this is exactly what angle function does.
So reverse the two atan2 arguments, then you will fix the "backwardness" of your formula.
Dan Bullard
on 19 Mar 2023
arctan2 is different in Fortran and Excel, forgive me, I use Excel and didn't know about the angle() function.
WH Wang
on 28 Jun 2023
it's atan2(imaginary,real) in matlab, or using phase() function of matlab.
Star Strider
on 28 Jun 2023
There is no phase function that I can find in the documentation, however there is the angle function that returns the phase angle (in radians) of a complex argument.
Accepted Answer
More Answers (1)
karinkan
on 1 Jun 2018
0 votes
I am a bit confusing that the following two equations which one is correct? eq.1 y=fft(data,NFFT)/count; eq.2 y=fft(data,NFFT)/NFFT;
1 Comment
Star Strider
on 1 Jun 2018
The first one.
Categories
Find more on Digital and Analog Filters 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!