Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!z4g2000prh.googlegroups.com!not-for-mail
From: TideMan <mulgor@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Understanding phase in the FFT
Date: Wed, 29 Jul 2009 15:16:12 -0700 (PDT)
Organization: http://groups.google.com
Lines: 57
Message-ID: <917fec82-e97e-4228-9349-a1053f19bc3b@z4g2000prh.googlegroups.com>
References: <h4qfa7$fa0$1@fred.mathworks.com> <712266fa-f831-45fb-9e33-9d6dff49fb65@x6g2000prc.googlegroups.com>
NNTP-Posting-Host: 202.78.152.105
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1248905773 1154 127.0.0.1 (29 Jul 2009 22:16:13 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 29 Jul 2009 22:16:13 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: z4g2000prh.googlegroups.com; posting-host=202.78.152.105; 
	posting-account=qPexFwkAAABOl8VUndE6Jm-9Z5z_fSpR
User-Agent: G2/1.0
X-HTTP-Via: 1.1 bc1
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.12) 
	Gecko/2009070611 Firefox/3.0.12,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:559454


On Jul 30, 9:45 am, TideMan <mul...@gmail.com> wrote:
> On Jul 30, 9:35 am, "aaaa Vadimov" <a...@hotmail.com> wrote:
>
>
>
> > 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
>
> It's called leakage.
> Because n is not an integral multiple of 1/fs, the energy of each sine
> wave is not in a single component, but spread over adjacent
> components, so when you find the maximum, it is not at exactly fs.
> You can fix this simply by using m instead of n in the FFT.
> These days, there's no need to use dyadic numbers for FFT.

I should add that if you're interested in calculating the phase of a
sinusoidal signal of a particular frequency, using FFT is completely
the wrong way to go about it.
We do this all the time in tidal analysis - calculating the amplitude
and phase of various tidal constituents - and without almost exception
it is done in the time domain using Matlab's \ facility, or similar.