http://www.mathworks.com/matlabcentral/newsreader/view_thread/310535
MATLAB Central Newsreader  angle function in matlab
Feed for thread: angle function in matlab
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Fri, 15 Jul 2011 20:59:12 +0000
angle function in matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/310535#845630
Penny
I am doing with some ultasound data now. I want to find out the phase difference between the RF data of two adjacent elements. But when i use angle function in matlab, i find a problems:<br>
<br>
when i do this<br>
t=0:0.05:2*pi;<br>
a=sin(2*pi*t);<br>
plot(angle(hilbert(a)))<br>
<br>
I don't know why the first phase is not zero. <br>
Could anyone tell me where the problem is? Many thanks!

Fri, 15 Jul 2011 21:17:28 +0000
Re: angle function in matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/310535#845632
Matt J
"Penny" wrote in message <ivq9n0$rpn$1@newscl01ah.mathworks.com>...<br>
><br>
> I don't know why the first phase is not zero. <br>
> Could anyone tell me where the problem is? Many thanks!<br>
==================<br>
<br>
There are at least 3 potential problems<br>
<br>
(1) Your sine wave is not perfect. It's truncated to the interval 0 to 2*pi.<br>
<br>
(2) The hilbert transform is not perfect  it's discretized.<br>
<br>
(3) The computation is not perfect  there is numerical finite precision error.

Sat, 16 Jul 2011 05:06:10 +0000
Re: angle function in matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/310535#845650
Roger Stafford
"Penny" wrote in message <ivq9n0$rpn$1@newscl01ah.mathworks.com>...<br>
> t=0:0.05:2*pi;<br>
> a=sin(2*pi*t);<br>
> plot(angle(hilbert(a)))<br>
> <br>
> I don't know why the first phase is not zero. <br>
> Could anyone tell me where the problem is? Many thanks!<br>
         <br>
Beside the points raised by Matt I have a couple of additional observations.<br>
<br>
Even if your 'a' signal were not truncated at t = 0 but extended well beyond that time both before and after, I would expect that the value of angle(hilbert(a)) at t = 0 using sin(2*pi*t) would be close to pi/2 rather than zero. The real part, the 'a' value itself, would be zero but the imaginary component added by hilbert(a), which is to be pi/2 (ninety degrees) out of phase with 'a', would then be at maximum value which would give 'angle' a value of pi/2. It is when the real part in 'a' is at its positive maximum and the imaginary part zero that you would get a zero value from 'angle'. If you want an initial phase of zero, you should be using cosine instead of sine.<br>
<br>
I notice that you have written:<br>
<br>
t=0:0.05:2*pi;<br>
a=sin(2*pi*t);<br>
<br>
which would cause the phase to range over 4*pi^2 radians rather than a single 2*pi cycle  your t extends up to 2*pi and the argument of sin(2*pi*t) extends up to (2*pi)*(2*pi). It also means that the increments in the argument of sin(2*pi*t) are not 0.05 but are a larger 0.31415 radians. Is that what you really meant?<br>
<br>
Roger Stafford

Sat, 16 Jul 2011 14:24:34 +0000
Re: angle function in matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/310535#845667
Greg Heath
On Jul 15, 4:59 pm, "Penny " <pqq3393...@yahoo.com.cn> wrote:<br>
> I am doing with some ultasound data now. I want to find out the phase difference between the RF data of two adjacent elements. But when i use angle function in matlab, i find a problems:<br>
><br>
> when i do this<br>
> t=0:0.05:2*pi;<br>
> a=sin(2*pi*t);<br>
> plot(angle(hilbert(a)))<br>
><br>
> I don't know why the first phase is not zero.<br>
> Could anyone tell me where the problem is? Many thanks!<br>
<br>
phase of the cosine is 0<br>
phase of the sine is pi/2<br>
<br>
Hope this helps.<br>
<br>
Greg