Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
angle function in matlab

Subject: angle function in matlab

From: Penny

Date: 15 Jul, 2011 20:59:12

Message: 1 of 4

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:

when i do this
t=0:0.05:2*pi;
a=sin(2*pi*t);
plot(angle(hilbert(a)))

I don't know why the first phase is not zero.
Could anyone tell me where the problem is? Many thanks!

Subject: angle function in matlab

From: Matt J

Date: 15 Jul, 2011 21:17:28

Message: 2 of 4

"Penny" wrote in message <ivq9n0$rpn$1@newscl01ah.mathworks.com>...
>
> I don't know why the first phase is not zero.
> Could anyone tell me where the problem is? Many thanks!
==================

There are at least 3 potential problems

(1) Your sine wave is not perfect. It's truncated to the interval 0 to 2*pi.

(2) The hilbert transform is not perfect - it's discretized.

(3) The computation is not perfect - there is numerical finite precision error.

Subject: angle function in matlab

From: Roger Stafford

Date: 16 Jul, 2011 05:06:10

Message: 3 of 4

"Penny" wrote in message <ivq9n0$rpn$1@newscl01ah.mathworks.com>...
> t=0:0.05:2*pi;
> a=sin(2*pi*t);
> plot(angle(hilbert(a)))
>
> I don't know why the first phase is not zero.
> Could anyone tell me where the problem is? Many thanks!
- - - - - - - - - -
  Beside the points raised by Matt I have a couple of additional observations.

  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.

  I notice that you have written:

t=0:0.05:2*pi;
a=sin(2*pi*t);

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?

Roger Stafford

Subject: angle function in matlab

From: Greg Heath

Date: 16 Jul, 2011 14:24:34

Message: 4 of 4

On Jul 15, 4:59 pm, "Penny " <pqq3393...@yahoo.com.cn> wrote:
> 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:
>
> when i do this
> t=0:0.05:2*pi;
> a=sin(2*pi*t);
> plot(angle(hilbert(a)))
>
> I don't know why the first phase is not zero.
> Could anyone tell me where the problem is? Many thanks!

phase of the cosine is 0
phase of the sine is pi/2

Hope this helps.

Greg

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us