<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/257306</link>
    <title>MATLAB Central Newsreader - Understanding phase in the FFT</title>
    <description>Feed for thread: Understanding phase in the FFT</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 29 Jul 2009 21:35:03 -0400</pubDate>
      <title>Understanding phase in the FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/257306#669259</link>
      <author>aaaa Vadimov</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
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! &lt;br&gt;
&lt;br&gt;
fs = 10;                         &lt;br&gt;
t = 0:1/fs:50-1/fs;              &lt;br&gt;
&lt;br&gt;
x1 = sin(2*pi*t);&lt;br&gt;
x2 = sin(2*pi*t+pi/2);&lt;br&gt;
x3 = sin(2*pi*t+pi/4);&lt;br&gt;
&lt;br&gt;
m = length(x1);          % Window length&lt;br&gt;
n = pow2(nextpow2(m));  % Transform length&lt;br&gt;
&lt;br&gt;
y1 = fft(x1,n);&lt;br&gt;
y2 = fft(x2,n);&lt;br&gt;
y3 = fft(x3,n);&lt;br&gt;
&lt;br&gt;
FT_power1 = abs(y1(1:floor(n/2))).^2;&lt;br&gt;
FT_phase1= (unwrap(angle(y1(1:floor(n/2))))) * 180/pi;&lt;br&gt;
[c1,i1] = max(FT_power1);&lt;br&gt;
phase(1) = FT_phase1(i1);&lt;br&gt;
&lt;br&gt;
FT_power2 = abs(y2(1:floor(n/2))).^2;&lt;br&gt;
FT_phase2= (unwrap(angle(y2(1:floor(n/2))))) * 180/pi;&lt;br&gt;
[c2,i2] = max(FT_power2);&lt;br&gt;
phase(2) = FT_phase2(i2);&lt;br&gt;
&lt;br&gt;
FT_power3 = abs(y3(1:floor(n/2))).^2;&lt;br&gt;
FT_phase3= (unwrap(angle(y3(1:floor(n/2))))) * 180/pi;&lt;br&gt;
[c3,i3] = max(FT_power3);&lt;br&gt;
phase(3) = FT_phase3(i3);&lt;br&gt;
&lt;br&gt;
phase =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;305.1562   35.0154  -10.0109</description>
    </item>
    <item>
      <pubDate>Wed, 29 Jul 2009 21:45:45 -0400</pubDate>
      <title>Re: Understanding phase in the FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/257306#669262</link>
      <author>TideMan</author>
      <description>On Jul 30, 9:35&#160;am, &quot;aaaa Vadimov&quot; &amp;lt;a...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; 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!&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; fs = 10; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;br&gt;
&amp;gt; t = 0:1/fs:50-1/fs; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; x1 = sin(2*pi*t);&lt;br&gt;
&amp;gt; x2 = sin(2*pi*t+pi/2);&lt;br&gt;
&amp;gt; x3 = sin(2*pi*t+pi/4);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; m = length(x1); &#160; &#160; &#160; &#160; &#160;% Window length&lt;br&gt;
&amp;gt; n = pow2(nextpow2(m)); &#160;% Transform length&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; y1 = fft(x1,n);&lt;br&gt;
&amp;gt; y2 = fft(x2,n);&lt;br&gt;
&amp;gt; y3 = fft(x3,n);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; FT_power1 = abs(y1(1:floor(n/2))).^2;&lt;br&gt;
&amp;gt; FT_phase1= (unwrap(angle(y1(1:floor(n/2))))) * 180/pi;&lt;br&gt;
&amp;gt; [c1,i1] = max(FT_power1);&lt;br&gt;
&amp;gt; phase(1) = FT_phase1(i1);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; FT_power2 = abs(y2(1:floor(n/2))).^2;&lt;br&gt;
&amp;gt; FT_phase2= (unwrap(angle(y2(1:floor(n/2))))) * 180/pi;&lt;br&gt;
&amp;gt; [c2,i2] = max(FT_power2);&lt;br&gt;
&amp;gt; phase(2) = FT_phase2(i2);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; FT_power3 = abs(y3(1:floor(n/2))).^2;&lt;br&gt;
&amp;gt; FT_phase3= (unwrap(angle(y3(1:floor(n/2))))) * 180/pi;&lt;br&gt;
&amp;gt; [c3,i3] = max(FT_power3);&lt;br&gt;
&amp;gt; phase(3) = FT_phase3(i3);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; phase =&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &#160; 305.1562 &#160; 35.0154 &#160;-10.0109&lt;br&gt;
&lt;br&gt;
It's called leakage.&lt;br&gt;
Because n is not an integral multiple of 1/fs, the energy of each sine&lt;br&gt;
wave is not in a single component, but spread over adjacent&lt;br&gt;
components, so when you find the maximum, it is not at exactly fs.&lt;br&gt;
You can fix this simply by using m instead of n in the FFT.&lt;br&gt;
These days, there's no need to use dyadic numbers for FFT.</description>
    </item>
    <item>
      <pubDate>Wed, 29 Jul 2009 22:16:12 -0400</pubDate>
      <title>Re: Understanding phase in the FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/257306#669268</link>
      <author>TideMan</author>
      <description>On Jul 30, 9:45&#160;am, TideMan &amp;lt;mul...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; On Jul 30, 9:35&#160;am, &quot;aaaa Vadimov&quot; &amp;lt;a...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; 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!&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; fs = 10; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;br&gt;
&amp;gt; &amp;gt; t = 0:1/fs:50-1/fs; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; x1 = sin(2*pi*t);&lt;br&gt;
&amp;gt; &amp;gt; x2 = sin(2*pi*t+pi/2);&lt;br&gt;
&amp;gt; &amp;gt; x3 = sin(2*pi*t+pi/4);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; m = length(x1); &#160; &#160; &#160; &#160; &#160;% Window length&lt;br&gt;
&amp;gt; &amp;gt; n = pow2(nextpow2(m)); &#160;% Transform length&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; y1 = fft(x1,n);&lt;br&gt;
&amp;gt; &amp;gt; y2 = fft(x2,n);&lt;br&gt;
&amp;gt; &amp;gt; y3 = fft(x3,n);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; FT_power1 = abs(y1(1:floor(n/2))).^2;&lt;br&gt;
&amp;gt; &amp;gt; FT_phase1= (unwrap(angle(y1(1:floor(n/2))))) * 180/pi;&lt;br&gt;
&amp;gt; &amp;gt; [c1,i1] = max(FT_power1);&lt;br&gt;
&amp;gt; &amp;gt; phase(1) = FT_phase1(i1);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; FT_power2 = abs(y2(1:floor(n/2))).^2;&lt;br&gt;
&amp;gt; &amp;gt; FT_phase2= (unwrap(angle(y2(1:floor(n/2))))) * 180/pi;&lt;br&gt;
&amp;gt; &amp;gt; [c2,i2] = max(FT_power2);&lt;br&gt;
&amp;gt; &amp;gt; phase(2) = FT_phase2(i2);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; FT_power3 = abs(y3(1:floor(n/2))).^2;&lt;br&gt;
&amp;gt; &amp;gt; FT_phase3= (unwrap(angle(y3(1:floor(n/2))))) * 180/pi;&lt;br&gt;
&amp;gt; &amp;gt; [c3,i3] = max(FT_power3);&lt;br&gt;
&amp;gt; &amp;gt; phase(3) = FT_phase3(i3);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; phase =&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &#160; 305.1562 &#160; 35.0154 &#160;-10.0109&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; It's called leakage.&lt;br&gt;
&amp;gt; Because n is not an integral multiple of 1/fs, the energy of each sine&lt;br&gt;
&amp;gt; wave is not in a single component, but spread over adjacent&lt;br&gt;
&amp;gt; components, so when you find the maximum, it is not at exactly fs.&lt;br&gt;
&amp;gt; You can fix this simply by using m instead of n in the FFT.&lt;br&gt;
&amp;gt; These days, there's no need to use dyadic numbers for FFT.&lt;br&gt;
&lt;br&gt;
I should add that if you're interested in calculating the phase of a&lt;br&gt;
sinusoidal signal of a particular frequency, using FFT is completely&lt;br&gt;
the wrong way to go about it.&lt;br&gt;
We do this all the time in tidal analysis - calculating the amplitude&lt;br&gt;
and phase of various tidal constituents - and without almost exception&lt;br&gt;
it is done in the time domain using Matlab's \ facility, or similar.</description>
    </item>
    <item>
      <pubDate>Thu, 30 Jul 2009 03:37:31 -0400</pubDate>
      <title>Re: Understanding phase in the FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/257306#669313</link>
      <author>dbd</author>
      <description>On Jul 29, 2:35 pm, &quot;aaaa Vadimov&quot; &amp;lt;a...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; 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!&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; fs = 10;&lt;br&gt;
&amp;gt; t = 0:1/fs:50-1/fs;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; x1 = sin(2*pi*t);&lt;br&gt;
&amp;gt; x2 = sin(2*pi*t+pi/2);&lt;br&gt;
&amp;gt; x3 = sin(2*pi*t+pi/4);&lt;br&gt;
&amp;gt; ...&lt;br&gt;
&lt;br&gt;
Why do you expect a sine wave to give a phase of 0 with an fft()? The&lt;br&gt;
basis vectors are cos()+i*sin().&lt;br&gt;
&lt;br&gt;
Dale B. Dalrymple</description>
    </item>
    <item>
      <pubDate>Thu, 30 Jul 2009 04:50:04 -0400</pubDate>
      <title>Re: Understanding phase in the FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/257306#669319</link>
      <author>Steve Amphlett</author>
      <description>dbd &amp;lt;dbd@ieee.org&amp;gt; wrote in message &amp;lt;8ea06202-cfd1-44cf-8656-c6c03daa210d@q40g2000prh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; On Jul 29, 2:35 pm, &quot;aaaa Vadimov&quot; &amp;lt;a...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; 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!&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; fs = 10;&lt;br&gt;
&amp;gt; &amp;gt; t = 0:1/fs:50-1/fs;&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; x1 = sin(2*pi*t);&lt;br&gt;
&amp;gt; &amp;gt; x2 = sin(2*pi*t+pi/2);&lt;br&gt;
&amp;gt; &amp;gt; x3 = sin(2*pi*t+pi/4);&lt;br&gt;
&amp;gt; &amp;gt; ...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Why do you expect a sine wave to give a phase of 0 with an fft()? The&lt;br&gt;
&amp;gt; basis vectors are cos()+i*sin().&lt;br&gt;
&lt;br&gt;
Phase is relative.  The phase between two signals is obtained from the cross spectrum.  The phase of a single signal isn't that meaningful or useful.</description>
    </item>
    <item>
      <pubDate>Thu, 30 Jul 2009 05:31:30 -0400</pubDate>
      <title>Re: Understanding phase in the FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/257306#669325</link>
      <author>TideMan</author>
      <description>On Jul 30, 4:50&#160;pm, &quot;Steve Amphlett&quot; &amp;lt;Firstname.Lastn...@Where-I-&lt;br&gt;
Work.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; dbd &amp;lt;d...@ieee.org&amp;gt; wrote in message &amp;lt;8ea06202-cfd1-44cf-8656-c6c03daa2...@q40g2000prh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; On Jul 29, 2:35 pm, &quot;aaaa Vadimov&quot; &amp;lt;a...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; 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!&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; fs = 10;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; t = 0:1/fs:50-1/fs;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; x1 = sin(2*pi*t);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; x2 = sin(2*pi*t+pi/2);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; x3 = sin(2*pi*t+pi/4);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; ...&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Why do you expect a sine wave to give a phase of 0 with an fft()? The&lt;br&gt;
&amp;gt; &amp;gt; basis vectors are cos()+i*sin().&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Phase is relative. &#160;The phase between two signals is obtained from the cross spectrum. &#160;The phase of a single signal isn't that meaningful or useful.&lt;br&gt;
&lt;br&gt;
No it's not.  It's absolute.&lt;br&gt;
In the time domain, it defines the time when the cosine is a maximum.&lt;br&gt;
In the frequency domain, it defines what proportion of the Fourier&lt;br&gt;
transform is imaginary.</description>
    </item>
    <item>
      <pubDate>Thu, 30 Jul 2009 06:57:01 -0400</pubDate>
      <title>Re: Understanding phase in the FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/257306#669334</link>
      <author>aaaa Vadimov</author>
      <description>Thanks for all your answers. &lt;br&gt;
Actually, I don't need to make FFT of sine function, it was just a test.&lt;br&gt;
What I actually have are two signals, which have the maximal power at some frequency. I preselected those signals and this is the only significant power in them. However, when I calculate the correlation between these two signals the correlation is around &quot;0&quot;. Would it be correct to expect to get difference between phases around 180 degrees? Would it be just abs(phase(2)-phase(1)), if I am using my previous example? If somebody can post some simple example of correct phase usage, I would really appreciate it.&lt;br&gt;
&lt;br&gt;
TideMan &amp;lt;mulgor@gmail.com&amp;gt; wrote in message &amp;lt;a4004cfa-186e-43c7-ac6f-559fd9ef78c8@12g2000pri.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; On Jul 30, 4:50?pm, &quot;Steve Amphlett&quot; &amp;lt;Firstname.Lastn...@Where-I-&lt;br&gt;
&amp;gt; Work.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; dbd &amp;lt;d...@ieee.org&amp;gt; wrote in message &amp;lt;8ea06202-cfd1-44cf-8656-c6c03daa2...@q40g2000prh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; On Jul 29, 2:35 pm, &quot;aaaa Vadimov&quot; &amp;lt;a...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; 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!&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; fs = 10;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; t = 0:1/fs:50-1/fs;&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; x1 = sin(2*pi*t);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; x2 = sin(2*pi*t+pi/2);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; x3 = sin(2*pi*t+pi/4);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; ...&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Why do you expect a sine wave to give a phase of 0 with an fft()? The&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; basis vectors are cos()+i*sin().&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Phase is relative. ?The phase between two signals is obtained from the cross spectrum. ?The phase of a single signal isn't that meaningful or useful.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; No it's not.  It's absolute.&lt;br&gt;
&amp;gt; In the time domain, it defines the time when the cosine is a maximum.&lt;br&gt;
&amp;gt; In the frequency domain, it defines what proportion of the Fourier&lt;br&gt;
&amp;gt; transform is imaginary.</description>
    </item>
    <item>
      <pubDate>Thu, 30 Jul 2009 07:02:01 -0400</pubDate>
      <title>Re: Understanding phase in the FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/257306#669335</link>
      <author>Steve Amphlett</author>
      <description>TideMan &amp;lt;mulgor@gmail.com&amp;gt; wrote in message &amp;lt;a4004cfa-186e-43c7-ac6f-559fd9ef78c8@12g2000pri.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; On Jul 30, 4:50?pm, &quot;Steve Amphlett&quot; &amp;lt;Firstname.Lastn...@Where-I-&lt;br&gt;
&amp;gt; Work.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; dbd &amp;lt;d...@ieee.org&amp;gt; wrote in message &amp;lt;8ea06202-cfd1-44cf-8656-c6c03daa2...@q40g2000prh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; On Jul 29, 2:35 pm, &quot;aaaa Vadimov&quot; &amp;lt;a...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; 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!&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; fs = 10;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; t = 0:1/fs:50-1/fs;&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; x1 = sin(2*pi*t);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; x2 = sin(2*pi*t+pi/2);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; x3 = sin(2*pi*t+pi/4);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; ...&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Why do you expect a sine wave to give a phase of 0 with an fft()? The&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; basis vectors are cos()+i*sin().&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Phase is relative. ?The phase between two signals is obtained from the cross spectrum. ?The phase of a single signal isn't that meaningful or useful.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; No it's not.  It's absolute.&lt;br&gt;
&amp;gt; In the time domain, it defines the time when the cosine is a maximum.&lt;br&gt;
&amp;gt; In the frequency domain, it defines what proportion of the Fourier&lt;br&gt;
&amp;gt; transform is imaginary.&lt;br&gt;
&lt;br&gt;
Ok, phase is useful when it's relative, for example, when there is a common reference involved.</description>
    </item>
    <item>
      <pubDate>Wed, 17 Aug 2011 10:32:09 -0400</pubDate>
      <title>Re: Understanding phase in the FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/257306#849429</link>
      <author>Chris </author>
      <description>TideMan &amp;lt;mulgor@gmail.com&amp;gt; wrote in message &amp;lt;917fec82-e97e-4228-9349-a1053f19bc3b@z4g2000prh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; On Jul 30, 9:45&#160;am, TideMan &amp;lt;mul...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; On Jul 30, 9:35&#160;am, &quot;aaaa Vadimov&quot; &amp;lt;a...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; 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!&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; fs = 10; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; t = 0:1/fs:50-1/fs; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; x1 = sin(2*pi*t);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; x2 = sin(2*pi*t+pi/2);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; x3 = sin(2*pi*t+pi/4);&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; m = length(x1); &#160; &#160; &#160; &#160; &#160;% Window length&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; n = pow2(nextpow2(m)); &#160;% Transform length&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; y1 = fft(x1,n);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; y2 = fft(x2,n);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; y3 = fft(x3,n);&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; FT_power1 = abs(y1(1:floor(n/2))).^2;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; FT_phase1= (unwrap(angle(y1(1:floor(n/2))))) * 180/pi;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; [c1,i1] = max(FT_power1);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; phase(1) = FT_phase1(i1);&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; FT_power2 = abs(y2(1:floor(n/2))).^2;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; FT_phase2= (unwrap(angle(y2(1:floor(n/2))))) * 180/pi;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; [c2,i2] = max(FT_power2);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; phase(2) = FT_phase2(i2);&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; FT_power3 = abs(y3(1:floor(n/2))).^2;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; FT_phase3= (unwrap(angle(y3(1:floor(n/2))))) * 180/pi;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; [c3,i3] = max(FT_power3);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; phase(3) = FT_phase3(i3);&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; phase =&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &#160; 305.1562 &#160; 35.0154 &#160;-10.0109&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; It's called leakage.&lt;br&gt;
&amp;gt; &amp;gt; Because n is not an integral multiple of 1/fs, the energy of each sine&lt;br&gt;
&amp;gt; &amp;gt; wave is not in a single component, but spread over adjacent&lt;br&gt;
&amp;gt; &amp;gt; components, so when you find the maximum, it is not at exactly fs.&lt;br&gt;
&amp;gt; &amp;gt; You can fix this simply by using m instead of n in the FFT.&lt;br&gt;
&amp;gt; &amp;gt; These days, there's no need to use dyadic numbers for FFT.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I should add that if you're interested in calculating the phase of a&lt;br&gt;
&amp;gt; sinusoidal signal of a particular frequency, using FFT is completely&lt;br&gt;
&amp;gt; the wrong way to go about it.&lt;br&gt;
&amp;gt; We do this all the time in tidal analysis - calculating the amplitude&lt;br&gt;
&amp;gt; and phase of various tidal constituents - and without almost exception&lt;br&gt;
&amp;gt; it is done in the time domain using Matlab's \ facility, or similar.&lt;br&gt;
&lt;br&gt;
Dear TideMan,&lt;br&gt;
I'm in wave energy and desperately want to calculate the phase and amplitude of each frequency in the spectrum of measured wave elevation. This sounds like exactly what you've done with your tidal analysis. As you imply, the fft approach gives rubbish phase information. Would you be kind enough to provide some more detailed information on how you actually do this? Maybe a link to some documentation or even the code itself :)&lt;br&gt;
Thanks in advance,&lt;br&gt;
One grateful WaveMan...</description>
    </item>
    <item>
      <pubDate>Wed, 17 Aug 2011 10:52:37 -0400</pubDate>
      <title>Re: Understanding phase in the FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/257306#849431</link>
      <author>TideMan</author>
      <description>On Aug 17, 10:32&#160;pm, &quot;Chris &quot; &amp;lt;chris.signore...@wavebob.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; TideMan &amp;lt;mul...@gmail.com&amp;gt; wrote in message &amp;lt;917fec82-e97e-4228-9349-a1053f19b...@z4g2000prh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; On Jul 30, 9:45&#160;am, TideMan &amp;lt;mul...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; On Jul 30, 9:35&#160;am, &quot;aaaa Vadimov&quot; &amp;lt;a...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; 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!&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; fs = 10; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; t = 0:1/fs:50-1/fs; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; x1 = sin(2*pi*t);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; x2 = sin(2*pi*t+pi/2);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; x3 = sin(2*pi*t+pi/4);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; m = length(x1); &#160; &#160; &#160; &#160; &#160;% Window length&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; n = pow2(nextpow2(m)); &#160;% Transform length&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; y1 = fft(x1,n);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; y2 = fft(x2,n);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; y3 = fft(x3,n);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; FT_power1 = abs(y1(1:floor(n/2))).^2;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; FT_phase1= (unwrap(angle(y1(1:floor(n/2))))) * 180/pi;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; [c1,i1] = max(FT_power1);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; phase(1) = FT_phase1(i1);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; FT_power2 = abs(y2(1:floor(n/2))).^2;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; FT_phase2= (unwrap(angle(y2(1:floor(n/2))))) * 180/pi;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; [c2,i2] = max(FT_power2);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; phase(2) = FT_phase2(i2);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; FT_power3 = abs(y3(1:floor(n/2))).^2;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; FT_phase3= (unwrap(angle(y3(1:floor(n/2))))) * 180/pi;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; [c3,i3] = max(FT_power3);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; phase(3) = FT_phase3(i3);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; phase =&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &#160; 305.1562 &#160; 35.0154 &#160;-10.0109&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; It's called leakage.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Because n is not an integral multiple of 1/fs, the energy of each sine&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; wave is not in a single component, but spread over adjacent&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; components, so when you find the maximum, it is not at exactly fs.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; You can fix this simply by using m instead of n in the FFT.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; These days, there's no need to use dyadic numbers for FFT.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I should add that if you're interested in calculating the phase of a&lt;br&gt;
&amp;gt; &amp;gt; sinusoidal signal of a particular frequency, using FFT is completely&lt;br&gt;
&amp;gt; &amp;gt; the wrong way to go about it.&lt;br&gt;
&amp;gt; &amp;gt; We do this all the time in tidal analysis - calculating the amplitude&lt;br&gt;
&amp;gt; &amp;gt; and phase of various tidal constituents - and without almost exception&lt;br&gt;
&amp;gt; &amp;gt; it is done in the time domain using Matlab's \ facility, or similar.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Dear TideMan,&lt;br&gt;
&amp;gt; I'm in wave energy and desperately want to calculate the phase and amplitude of each frequency in the spectrum of measured wave elevation. This sounds like exactly what you've done with your tidal analysis. As you imply, the fft approach gives rubbish phase information. Would you be kind enough to provide some more detailed information on how you actually do this? Maybe a link to some documentation or even the code itself :)&lt;br&gt;
&amp;gt; Thanks in advance,&lt;br&gt;
&amp;gt; One grateful WaveMan...&lt;br&gt;
&lt;br&gt;
Google t_tide</description>
    </item>
  </channel>
</rss>

