Thread Subject: Strange Behavior in Phase Calculation

Subject: Strange Behavior in Phase Calculation

From: Chen Sagiv

Date: 14 May, 2008 06:49:02

Message: 1 of 6

Dear friends,

I have a strange phenomenon.
I have a cosine wave. I take two instances of it.

I call the first Case 1, where I have 10 cycles of this
wave. Case 2 is 10 cycle + one extra point.

Now, when I calculate the FT of both signals, I get a non
zero imaginary value for the second case.

If I try to calculate the phase, and use either atan,
atan2, angle and phase commands I get a linear phase.

Isn't it Gibberish ? How does Matlab generate linear phase
when the imaginary part of the FT is practically zero ?

I would be happy to get comments on this issue.

Thanks,

Chen

Subject: Strange Behavior in Phase Calculation

From: Chen Sagiv

Date: 14 May, 2008 06:52:01

Message: 2 of 6

"Chen Sagiv" <chensagivron@gmail.com> wrote in message
<g0e20u$kmt$1@fred.mathworks.com>...
> Dear friends,
>
> I have a strange phenomenon.
> I have a cosine wave. I take two instances of it.
>
> I call the first Case 1, where I have 10 cycles of this
> wave. Case 2 is 10 cycle + one extra point.
>
> Now, when I calculate the FT of both signals, I get a non
> zero imaginary value for the second case.
>
> If I try to calculate the phase, and use either atan,
> atan2, angle and phase commands I get a linear phase.
>
> Isn't it Gibberish ? How does Matlab generate linear
phase
> when the imaginary part of the FT is practically zero ?
>
> I would be happy to get comments on this issue.
>
> Thanks,
>
> Chen

Sorry, forgot to attach the code:

close all;
clear all;

% Constants
T = 10;
w0 = 2*pi;
sigma = 1;
% Case 1: there are 10 cycles of the cosine function
t1 = 0:0.01:10-0.01;
f1 = cos(w0*t1);
fw1 = fftshift(fft(f1));

% Case 2: there are 10 cycles + 1 point
t2 = 0:0.01:10;
f2 = cos(w0*t2);
fw2 = fftshift(fft(f2));

figure ;
subplot(3,2,1); plot(real(fw1),'.k');
title('Case 1: real FT');
subplot(3,2,3); plot(imag(fw1),'.k');
title('Case 1: imag FT');
subplot(3,2,5); plot(atan2(imag(fw1), real(fw1)),'.');
title('Case 1: phase of FT');
subplot(3,2,2); plot(real(fw2),'.k');
title('Case 2: real FT');
subplot(3,2,4); plot(imag(fw2),'.k');
title('Case 2: imag FT');
subplot(3,2,6); plot(atan2(imag(fw2), real(fw2)),'.');
title('Case 2: phase of FT');

Best,

Chen

Subject: Strange Behavior in Phase Calculation

From: NZTideMan

Date: 14 May, 2008 07:14:12

Message: 3 of 6

On May 14, 6:52=A0pm, "Chen Sagiv" <chensagiv...@gmail.com> wrote:
> "Chen Sagiv" <chensagiv...@gmail.com> wrote in message
>
> <g0e20u$km...@fred.mathworks.com>...
>
>
>
>
>
> > Dear friends,
>
> > I have a strange phenomenon.
> > I have a cosine wave. I take two instances of it.
>
> > I call the first Case 1, where I have 10 cycles of this
> > wave. Case 2 is 10 cycle + one extra point.
>
> > Now, when I calculate the FT of both signals, I get a non
> > zero imaginary value for the second case.
>
> > If I try to calculate the phase, and use either atan,
> > atan2, angle and phase commands I get a linear phase.
>
> > Isn't it Gibberish ? How does Matlab generate linear
> phase
> > when the imaginary part of the FT is practically zero ?
>
> > I would be happy to get comments on this issue.
>
> > Thanks,
>
> > Chen
>
> Sorry, forgot to attach the code:
>
> close all;
> clear all;
>
> % Constants
> T =3D 10;
> w0 =3D 2*pi;
> sigma =3D 1;
> % Case 1: there are 10 cycles of the cosine function
> t1 =3D 0:0.01:10-0.01;
> f1 =3D cos(w0*t1);
> fw1 =3D fftshift(fft(f1));
>
> % Case 2: there are 10 cycles + 1 point
> t2 =3D 0:0.01:10;
> f2 =3D cos(w0*t2);
> fw2 =3D fftshift(fft(f2));
>
> figure ;
> subplot(3,2,1); plot(real(fw1),'.k');
> title('Case 1: real FT');
> subplot(3,2,3); plot(imag(fw1),'.k');
> title('Case 1: imag FT');
> subplot(3,2,5); plot(atan2(imag(fw1), real(fw1)),'.');
> title('Case 1: phase of FT');
> subplot(3,2,2); plot(real(fw2),'.k');
> title('Case 2: real FT');
> subplot(3,2,4); plot(imag(fw2),'.k');
> title('Case 2: imag FT');
> subplot(3,2,6); plot(atan2(imag(fw2), real(fw2)),'.');
> title('Case 2: phase of FT');
>
> Best,
>
> Chen- Hide quoted text -
>
> - Show quoted text -

It's called "leakage". It's a feature of the FFT, so don't for a
moment think you've discovered something new.
There's a very good explanation in E Oran Brigham's book Fast Fourier
Transform published in 1973.

Subject: Strange Behavior in Phase Calculation

From: Chen Sagiv

Date: 14 May, 2008 07:20:17

Message: 4 of 6

NZTideMan <mulgor@gmail.com> wrote in message <5784b2e7-
6422-4da5-bbfa-6f93523e0635@k10g2000prm.googlegroups.com>...
> On May 14, 6:52=A0pm, "Chen Sagiv"
<chensagiv...@gmail.com> wrote:
> > "Chen Sagiv" <chensagiv...@gmail.com> wrote in message
> >
> > <g0e20u$km...@fred.mathworks.com>...
> >
> >
> >
> >
> >
> > > Dear friends,
> >
> > > I have a strange phenomenon.
> > > I have a cosine wave. I take two instances of it.
> >
> > > I call the first Case 1, where I have 10 cycles of
this
> > > wave. Case 2 is 10 cycle + one extra point.
> >
> > > Now, when I calculate the FT of both signals, I get a
non
> > > zero imaginary value for the second case.
> >
> > > If I try to calculate the phase, and use either atan,
> > > atan2, angle and phase commands I get a linear phase.
> >
> > > Isn't it Gibberish ? How does Matlab generate linear
> > phase
> > > when the imaginary part of the FT is practically
zero ?
> >
> > > I would be happy to get comments on this issue.
> >
> > > Thanks,
> >
> > > Chen
> >
> > Sorry, forgot to attach the code:
> >
> > close all;
> > clear all;
> >
> > % Constants
> > T =3D 10;
> > w0 =3D 2*pi;
> > sigma =3D 1;
> > % Case 1: there are 10 cycles of the cosine function
> > t1 =3D 0:0.01:10-0.01;
> > f1 =3D cos(w0*t1);
> > fw1 =3D fftshift(fft(f1));
> >
> > % Case 2: there are 10 cycles + 1 point
> > t2 =3D 0:0.01:10;
> > f2 =3D cos(w0*t2);
> > fw2 =3D fftshift(fft(f2));
> >
> > figure ;
> > subplot(3,2,1); plot(real(fw1),'.k');
> > title('Case 1: real FT');
> > subplot(3,2,3); plot(imag(fw1),'.k');
> > title('Case 1: imag FT');
> > subplot(3,2,5); plot(atan2(imag(fw1), real(fw1)),'.');
> > title('Case 1: phase of FT');
> > subplot(3,2,2); plot(real(fw2),'.k');
> > title('Case 2: real FT');
> > subplot(3,2,4); plot(imag(fw2),'.k');
> > title('Case 2: imag FT');
> > subplot(3,2,6); plot(atan2(imag(fw2), real(fw2)),'.');
> > title('Case 2: phase of FT');
> >
> > Best,
> >
> > Chen- Hide quoted text -
> >
> > - Show quoted text -
>
> It's called "leakage". It's a feature of the FFT, so
don't for a
> moment think you've discovered something new.
> There's a very good explanation in E Oran Brigham's book
Fast Fourier
> Transform published in 1973.

Dear NZTideMan,

I am afraid you completely missed my point.
I am not referring to the leakage (thanks for the reference
though), but to the linear phase that seems to be
calculated with no reason.

If you can refer to this point, i will appreciate it.

Best,

Chen

Subject: Strange Behavior in Phase Calculation

From: NZTideMan

Date: 14 May, 2008 07:31:59

Message: 5 of 6

On May 14, 7:20=A0pm, "Chen Sagiv" <chensagiv...@gmail.com> wrote:
> NZTideMan <mul...@gmail.com> wrote in message <5784b2e7-
>
> 6422-4da5-bbfa-6f93523e0...@k10g2000prm.googlegroups.com>...
>
>
>
>
>
> > On May 14, 6:52=3DA0pm, "Chen Sagiv"
> <chensagiv...@gmail.com> wrote:
> > > "Chen Sagiv" <chensagiv...@gmail.com> wrote in message
>
> > > <g0e20u$km...@fred.mathworks.com>...
>
> > > > Dear friends,
>
> > > > I have a strange phenomenon.
> > > > I have a cosine wave. I take two instances of it.
>
> > > > I call the first Case 1, where I have 10 cycles of
> this
> > > > wave. Case 2 is 10 cycle + one extra point.
>
> > > > Now, when I calculate the FT of both signals, I get a
> non
> > > > zero imaginary value for the second case.
>
> > > > If I try to calculate the phase, and use either atan,
> > > > atan2, angle and phase commands I get a linear phase.
>
> > > > Isn't it Gibberish ? How does Matlab generate linear
> > > phase
> > > > when the imaginary part of the FT is practically
> zero ?
>
> > > > I would be happy to get comments on this issue.
>
> > > > Thanks,
>
> > > > Chen
>
> > > Sorry, forgot to attach the code:
>
> > > close all;
> > > clear all;
>
> > > % Constants
> > > T =3D3D 10;
> > > w0 =3D3D 2*pi;
> > > sigma =3D3D 1;
> > > % Case 1: there are 10 cycles of the cosine function
> > > t1 =3D3D 0:0.01:10-0.01;
> > > f1 =3D3D cos(w0*t1);
> > > fw1 =3D3D fftshift(fft(f1));
>
> > > % Case 2: there are 10 cycles + 1 point
> > > t2 =3D3D 0:0.01:10;
> > > f2 =3D3D cos(w0*t2);
> > > fw2 =3D3D fftshift(fft(f2));
>
> > > figure ;
> > > subplot(3,2,1); plot(real(fw1),'.k');
> > > title('Case 1: real FT');
> > > subplot(3,2,3); plot(imag(fw1),'.k');
> > > title('Case 1: imag FT');
> > > subplot(3,2,5); plot(atan2(imag(fw1), real(fw1)),'.');
> > > title('Case 1: phase of FT');
> > > subplot(3,2,2); plot(real(fw2),'.k');
> > > title('Case 2: real FT');
> > > subplot(3,2,4); plot(imag(fw2),'.k');
> > > title('Case 2: imag FT');
> > > subplot(3,2,6); plot(atan2(imag(fw2), real(fw2)),'.');
> > > title('Case 2: phase of FT');
>
> > > Best,
>
> > > Chen- Hide quoted text -
>
> > > - Show quoted text -
>
> > It's called "leakage". =A0It's a feature of the FFT, so
> don't for a
> > moment think you've discovered something new.
> > There's a very good explanation in E Oran Brigham's book
> Fast Fourier
> > Transform published in 1973.
>
> Dear NZTideMan,
>
> I am afraid you completely missed my point.
> I am not referring to the leakage (thanks for the reference
> though), but to the linear phase that seems to be
> calculated with no reason.
>
> If you can refer to this point, i will appreciate it.
>
> Best,
>
> Chen- Hide quoted text -
>
> - Show quoted text -

OK, so it's leakage AND truncation error.
You should have realised this when you saw the plot for fw1's phase.
Did you notice it's all over the place between -pi and pi? Did you
ask yourself why?

Subject: Strange Behavior in Phase Calculation

From: Chen Sagiv

Date: 14 May, 2008 08:30:20

Message: 6 of 6

NZTideMan <mulgor@gmail.com> wrote in message <dda8029b-
882c-463b-8424-0473115436e1@c19g2000prf.googlegroups.com>...
> On May 14, 7:20=A0pm, "Chen Sagiv"
<chensagiv...@gmail.com> wrote:
> > NZTideMan <mul...@gmail.com> wrote in message <5784b2e7-
> >
> > 6422-4da5-bbfa-
6f93523e0...@k10g2000prm.googlegroups.com>...
> >
> >
> >
> >
> >
> > > On May 14, 6:52=3DA0pm, "Chen Sagiv"
> > <chensagiv...@gmail.com> wrote:
> > > > "Chen Sagiv" <chensagiv...@gmail.com> wrote in
message
> >
> > > > <g0e20u$km...@fred.mathworks.com>...
> >
> > > > > Dear friends,
> >
> > > > > I have a strange phenomenon.
> > > > > I have a cosine wave. I take two instances of it.
> >
> > > > > I call the first Case 1, where I have 10 cycles of
> > this
> > > > > wave. Case 2 is 10 cycle + one extra point.
> >
> > > > > Now, when I calculate the FT of both signals, I
get a
> > non
> > > > > zero imaginary value for the second case.
> >
> > > > > If I try to calculate the phase, and use either
atan,
> > > > > atan2, angle and phase commands I get a linear
phase.
> >
> > > > > Isn't it Gibberish ? How does Matlab generate
linear
> > > > phase
> > > > > when the imaginary part of the FT is practically
> > zero ?
> >
> > > > > I would be happy to get comments on this issue.
> >
> > > > > Thanks,
> >
> > > > > Chen
> >
> > > > Sorry, forgot to attach the code:
> >
> > > > close all;
> > > > clear all;
> >
> > > > % Constants
> > > > T =3D3D 10;
> > > > w0 =3D3D 2*pi;
> > > > sigma =3D3D 1;
> > > > % Case 1: there are 10 cycles of the cosine function
> > > > t1 =3D3D 0:0.01:10-0.01;
> > > > f1 =3D3D cos(w0*t1);
> > > > fw1 =3D3D fftshift(fft(f1));
> >
> > > > % Case 2: there are 10 cycles + 1 point
> > > > t2 =3D3D 0:0.01:10;
> > > > f2 =3D3D cos(w0*t2);
> > > > fw2 =3D3D fftshift(fft(f2));
> >
> > > > figure ;
> > > > subplot(3,2,1); plot(real(fw1),'.k');
> > > > title('Case 1: real FT');
> > > > subplot(3,2,3); plot(imag(fw1),'.k');
> > > > title('Case 1: imag FT');
> > > > subplot(3,2,5); plot(atan2(imag(fw1), real
(fw1)),'.');
> > > > title('Case 1: phase of FT');
> > > > subplot(3,2,2); plot(real(fw2),'.k');
> > > > title('Case 2: real FT');
> > > > subplot(3,2,4); plot(imag(fw2),'.k');
> > > > title('Case 2: imag FT');
> > > > subplot(3,2,6); plot(atan2(imag(fw2), real
(fw2)),'.');
> > > > title('Case 2: phase of FT');
> >
> > > > Best,
> >
> > > > Chen- Hide quoted text -
> >
> > > > - Show quoted text -
> >
> > > It's called "leakage". =A0It's a feature of the FFT,
so
> > don't for a
> > > moment think you've discovered something new.
> > > There's a very good explanation in E Oran Brigham's
book
> > Fast Fourier
> > > Transform published in 1973.
> >
> > Dear NZTideMan,
> >
> > I am afraid you completely missed my point.
> > I am not referring to the leakage (thanks for the
reference
> > though), but to the linear phase that seems to be
> > calculated with no reason.
> >
> > If you can refer to this point, i will appreciate it.
> >
> > Best,
> >
> > Chen- Hide quoted text -
> >
> > - Show quoted text -
>
> OK, so it's leakage AND truncation error.
> You should have realised this when you saw the plot for
fw1's phase.
> Did you notice it's all over the place between -pi and
pi? Did you
> ask yourself why?

Dear NZTideMan,

Yes I did, but got no good answer.
But, as I see it it is a "reasonable" behavior for an
error. When it takes the form of an ordered pattern, as is
the case for the phase of fw2, I do not have a good
explanation yet.

Best,

Chen

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
dft Chen Sagiv 14 May, 2008 02:50:20
phase Chen Sagiv 14 May, 2008 02:50:20
rssFeed for this Thread

Contact us at files@mathworks.com