The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Puzzle about the FFT phase angle, an error?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

natie

China
3 Posts

Posted - 12/02/2011 :  06:19:34 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Found some inconsistence on FFT.

Perform FFT on a time series, and I obtained serveral collumn data such as real part, imaginary part, and phase, as a result. Then I use the real and imginary parts to calcualte the phase angle, but the calucated one is diffrent from the Origin result.

FFT options: without unwrap phase, resulting a angle between -180 to 180 degree.

I calculate the phase using equation of "atan(col(imag)/col(real))*180/pi", according to the Origin FFT algorithm.




natie

China
3 Posts

Posted - 12/02/2011 :  06:25:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Ok, I cannot upload any file...



Edited by - natie on 12/02/2011 06:38:33 AM
Go to Top of Page

Sam Fang

293 Posts

Posted - 12/04/2011 :  10:30:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I can't reproduce your problem.

Note that you can't simply use "atan(col(imag)/col(real))*180/pi" to calculate the phase because atan only ranges from -pi/2 to pi/2, i.e. -90 to 90. You need also check the sign of real and imag.

To reproduce your problem, you need tell us your Origin's version and send us your project file. To upload a file, click Send File to Tech support button at the top right of the forum.

Thanks.

Sam
OriginLab Technical Services
Go to Top of Page

natie

China
3 Posts

Posted - 12/07/2011 :  05:50:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Sam, thank you for your reply.


Yes the difference results from the range of "atan" function.
but it is interesting as the attaced figures show:

our wave has a frequency of 70Hz, and the phase angle calculated by both method is identical, i.e.at 70Hz. At the triple frequency 210Hz, we get a similar result,but contary at a double frequency,140Hz. Obvious difference is found at the rest frequnecies.


Listed is FFT result by Origin 8.5, and the comparasion figure about phase angle of both calcualtion method.

FFT result:


Comparasion of phase angele produced by Origin and direct calculation by real and imaginary part:


It seems, I have gotten a consistant result since both method can produce the same phase angle at a interested frequency. But I don't know the exact reason for these result. And what does it means for the phase angles at the rest frenquecies?

Below is the wave file we used:
http://www.originlab.com/ftp/forum_and_kbase/Images/wave.txt

Thank you for your consideration of this problem.

Natie

Edited by - natie on 12/07/2011 06:00:32 AM
Go to Top of Page

Sam Fang

293 Posts

Posted - 12/07/2011 :  06:07:22 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Phase angles agree only for Real>0 if you use atan.

Sam
OriginLab Technical Services
Go to Top of Page

Drbobshepherd

USA
Posts

Posted - 12/07/2011 :  12:46:47 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Instead of atan(imag,real), try angle(real, imag); this is the LabTalk version of atan2. Then convert the result from radians to degrees.
Go to Top of Page

Sam Fang

293 Posts

Posted - 12/07/2011 :  10:20:24 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, Drbobshepherd.

We can use following script to return an angle between -180 to 180.

col(imag)<0?angle(col(real),col(imag))/pi*180-360:angle(col(real),col(imag))/pi*180


Sam
OriginLab Technical Services
Go to Top of Page

Drbobshepherd

USA
Posts

Posted - 01/27/2012 :  6:27:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hey, I just noticed in OriginPro 8.6 that LabTalk has added Atan2() to the command set. That is great! I know there are many like me that need to use Atan2(), instead of Atan(), for calculating polar angles because the range for Atan2() spans a complete cycle (360 degrees) while the range for Atan() only spans half of a cycle (180 degrees).

The LabTalk command Angle() also has a full cycle range, but Atan2() is more well-known. Atan2() can be found in C, C++, C#, Visual Basic, Excel, MatLab, JAVA, and PHP codes.

Atan2() is the superior choice for natie's problem for two reasons:
1. The range for atan2() is from -pi to pi, which is easily converted to degrees without the need for conditional testing.
2. atan2() is defined at the origin (0,0); angle() is not and this can cause errors.

Note: The conventional usage of atan2 is atan(y,x), where the y is the vertical component, and x is the horizontal. This is so the order of the input data pair (x,y) remains the same for both atan() and atan2(), for you see, atan2(y,x)=atan(y/x) where the range is from -pi/2 to pi/2. I wish I had a nickel everytime a programmer suddenly realized he had to replace his "atan(y/x)" commands with "atan2(y,x)".

By the way, Excel has reversed the order, but Origin has it right. Congatulations, guys.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000