Path: news.mathworks.com!not-for-mail
From: "aaaa Vadimov" <aaa@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Understanding phase in the FFT
Date: Wed, 29 Jul 2009 21:35:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <h4qfa7$fa0$1@fred.mathworks.com>
Reply-To: "aaaa Vadimov" <aaa@hotmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1248903303 15680 172.30.248.35 (29 Jul 2009 21:35:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 29 Jul 2009 21:35:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1920336
Xref: news.mathworks.com comp.soft-sys.matlab:559445


Hi,

Here the simple code of three series, which differ only by phase. I don't understand why I am not getting phases,which I expect to. Shouldn't I get 0 (or 360), 90 and 45 ? Thanks a lot! 

fs = 10;                         
t = 0:1/fs:50-1/fs;              

x1 = sin(2*pi*t);
x2 = sin(2*pi*t+pi/2);
x3 = sin(2*pi*t+pi/4);

m = length(x1);          % Window length
n = pow2(nextpow2(m));  % Transform length

y1 = fft(x1,n);
y2 = fft(x2,n);
y3 = fft(x3,n);

FT_power1 = abs(y1(1:floor(n/2))).^2;
FT_phase1= (unwrap(angle(y1(1:floor(n/2))))) * 180/pi;
[c1,i1] = max(FT_power1);
phase(1) = FT_phase1(i1);

FT_power2 = abs(y2(1:floor(n/2))).^2;
FT_phase2= (unwrap(angle(y2(1:floor(n/2))))) * 180/pi;
[c2,i2] = max(FT_power2);
phase(2) = FT_phase2(i2);

FT_power3 = abs(y3(1:floor(n/2))).^2;
FT_phase3= (unwrap(angle(y3(1:floor(n/2))))) * 180/pi;
[c3,i3] = max(FT_power3);
phase(3) = FT_phase3(i3);

phase =

  305.1562   35.0154  -10.0109