How to determine phase of a sine wave using FFT

37 ビュー (過去 30 日間)
Fuh-Cherng
Fuh-Cherng 2016 年 3 月 25 日
コメント済み: Star Strider 2018 年 1 月 6 日
Dear MATLAB experts,
For a small project that I want to do, I need to compute the phase of a sine wave. However, I was unable to obtain a correct result. I have posted my code with this message (please see attachment) for your review and comments. If anyone could help me with this, I would greatly appreciate it.
Thank you!
Fuh
  1 件のコメント
Fuh-Cherng
Fuh-Cherng 2016 年 3 月 25 日
Here is the code.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2016 年 3 月 25 日
編集済み: Star Strider 2016 年 3 月 25 日
The code hasn’t posted. Use the angle function on the output of the fft function:
t = [...]; % Time Vector
s = [...]; % Signal Vector
Ts = mean(diff(t)); % Sampling Time
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = length(s);
fts = fft(s)/L; % Normalised Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
amp_fts = abs(fts(Iv))*2; % Spectrum Amplitude
phs_fts = angle(fts(Iv)); % Spectrum Phase
Note This is obviously UNTESTED CODE but it should work.
  6 件のコメント
H S
H S 2018 年 1 月 6 日
Dear Star Strider,
I think for the zero frequency (DC), your code after "amp_fts = abs(fts(Iv))*2;" should be corrected as follows:
amp_fts(1)=amp_fts(1)/2;
Star Strider
Star Strider 2018 年 1 月 6 日
Not according to fft (link).

サインインしてコメントする。

その他の回答 (1 件)

Fuh-Cherng
Fuh-Cherng 2016 年 3 月 27 日
Thank you so much for pointing out the mistake I made! Greatly appreciated!
  1 件のコメント
Star Strider
Star Strider 2016 年 3 月 27 日
As always, my pleasure.
I would appreciate it then if you would Accept my Answer.
You can do that by deleting your Answer and then Accepting mine. (No one gets any credit for Accepting their own Answer, anyway.)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeBartlett についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by