I'm a bit stumped here, maybe someone can help me out? y = atan (sin(2*pi*x) / cos(2*pi*x)); s = atan2 (sin(2*pi*x) , cos(2*pi*x)); I would expect y and s to be equal, but they're not. Most surprising to me is that the maximum value of s appears to be pi, despite the fact that the limit of atan2(a,b) as a/b->infinity is pi/2 (right?) Can anyone clue me in as to why my expectations are being defied here? I think the root of my misunderstanding lies in my not understanding the differences between atan(a/b) and atan2(a,b). Thanks, any help is much appreciated
difference between atan2(x,y) and atan(x/y)
Started by ●January 8, 2008
Reply by ●January 8, 20082008-01-08
atan2(y,x) is used to find the angle from the point (0,0) to the point (x,y), using the x-axis as reference; e.g., atan2 (.707, .707) = pi/4 => 45 degrees atan2 (.707, -.707) = 3*pi/4 => 135 degrees atan2 (-.707, .707) = -pi/4 = -45 degrees atan2 (-.707, -.707) = -3*pi/4 => -135 degrees (the signs of x and y determine the quadrant of the result) On Jan 8, 6:13 pm, "maxplanck" <erik.bo...@comcast.net> wrote:> I'm a bit stumped here, maybe someone can help me out? > > y = atan (sin(2*pi*x) / cos(2*pi*x)); > > s = atan2 (sin(2*pi*x) , cos(2*pi*x)); > > I would expect y and s to be equal, but they're not. > > Most surprising to me is that the maximum value of s appears to be pi, > despite the fact that the limit of atan2(a,b) as a/b->infinity is pi/2 > (right?) > > Can anyone clue me in as to why my expectations are being defied here? I > think the root of my misunderstanding lies in my not understanding the > differences between atan(a/b) and atan2(a,b). > > Thanks, any help is much appreciated
Reply by ●January 8, 20082008-01-08
On Jan 8, 6:13 pm, "maxplanck" <erik.bo...@comcast.net> wrote:> I'm a bit stumped here, maybe someone can help me out? > > y = atan (sin(2*pi*x) / cos(2*pi*x)); > > s = atan2 (sin(2*pi*x) , cos(2*pi*x)); > > I would expect y and s to be equal, but they're not. > > Most surprising to me is that the maximum value of s appears to be pi, > despite the fact that the limit of atan2(a,b) as a/b->infinity is pi/2 > (right?) > > Can anyone clue me in as to why my expectations are being defied here? I > think the root of my misunderstanding lies in my not understanding the > differences between atan(a/b) and atan2(a,b).atan2(Im{z}, Re{z}) is meant to be the angle of a complex number z. arg{z} = atan2(Im{z}, Re{z}) when using the atan2(Im{z}, Re{z}) for the angle of a complex number, it is correct only if Re(z)>0. for the case Re(z)<0, your atan2(Im{z}, Re{z}) expression for the angle is off by a constant value of pi. sometimes we say: {arctan(Im{z}/Re{z}) for Re{z}>0 arg{z} = { {arctan(Im{z}/Re{z}) +/- pi for Re{z}<0 or better: {arctan(Im{z}/Re{z}) Re{z}>0, Im{z}<|Re{z}| arg{z} = { {sgn(Im{z})*pi/2 - arctan(Re{z}/Im{z}) otherwize atan2() deals with getting the angle right, no matter which quadrant z ends up in. r b-j
Reply by ●January 8, 20082008-01-08
maxplanck wrote:> I'm a bit stumped here, maybe someone can help me out? > > y = atan (sin(2*pi*x) / cos(2*pi*x)); > > s = atan2 (sin(2*pi*x) , cos(2*pi*x)); > > I would expect y and s to be equal, but they're not. > > Most surprising to me is that the maximum value of s appears to be pi, > despite the fact that the limit of atan2(a,b) as a/b->infinity is pi/2 > (right?) > > Can anyone clue me in as to why my expectations are being defied here? I > think the root of my misunderstanding lies in my not understanding the > differences between atan(a/b) and atan2(a,b). > > Thanks, any help is much appreciatedHow much trig do you remember? Can you simplify sin(x)/cos(x)? Are you familiar with the concept of "principal value"? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●January 8, 20082008-01-08
Jerry Avins wrote:> maxplanck wrote: >> I'm a bit stumped here, maybe someone can help me out? >> >> y = atan (sin(2*pi*x) / cos(2*pi*x)); >> s = atan2 (sin(2*pi*x) , cos(2*pi*x)); >> >> I would expect y and s to be equal, but they're not. >> >> Most surprising to me is that the maximum value of s appears to be pi, >> despite the fact that the limit of atan2(a,b) as a/b->infinity is pi/2 >> (right?) >> >> Can anyone clue me in as to why my expectations are being defied here? I >> think the root of my misunderstanding lies in my not understanding the >> differences between atan(a/b) and atan2(a,b). >> >> Thanks, any help is much appreciated > > How much trig do you remember? Can you simplify sin(x)/cos(x)? Are you > familiar with the concept of "principal value"?This is a DSP group, so why not express it in terms of information.... Division is lossy, as maps the answers to -ve/-ve to the same space as +ve/+ve ones. Same for -ve/+ve and +ve/-ve. atan2() lets the functiom have the complete raw information, so it can handle all four quadrants properly. Steve
Reply by ●January 8, 20082008-01-08
"maxplanck" <erik.bowen@comcast.net> writes:> I'm a bit stumped here, maybe someone can help me out? > > y = atan (sin(2*pi*x) / cos(2*pi*x)); > > s = atan2 (sin(2*pi*x) , cos(2*pi*x)); > > I would expect y and s to be equal, but they're not. > > Most surprising to me is that the maximum value of s appears to be pi, > despite the fact that the limit of atan2(a,b) as a/b->infinity is pi/2 > (right?) > > Can anyone clue me in as to why my expectations are being defied here? I > think the root of my misunderstanding lies in my not understanding the > differences between atan(a/b) and atan2(a,b). > > Thanks, any help is much appreciatedy is just the principle value, which will only be -pi/2 and pi/2. s is the four quandrant version which can be between -pi and pi. http://en.wikipedia.org/wiki/Atan (see the section entitled "Two argument variant of arctangent"). Ciao, Peter K. -- "And he sees the vision splendid of the sunlit plains extended And at night the wondrous glory of the everlasting stars."
Reply by ●January 8, 20082008-01-08
What I meant to say was the angle between the x-axis and the line segment connecting the points (0,0) and (x,y) On Jan 8, 6:50 pm, predict...@gmail.com wrote:> atan2(y,x) is used to find the angle from the point (0,0) to the point > (x,y), using the x-axis as reference; e.g., > > atan2 (.707, .707) = pi/4 => 45 degrees > atan2 (.707, -.707) = 3*pi/4 => 135 degrees > atan2 (-.707, .707) = -pi/4 = -45 degrees > atan2 (-.707, -.707) = -3*pi/4 => -135 degrees > > (the signs of x and y determine the quadrant of the result) > > On Jan 8, 6:13 pm, "maxplanck" <erik.bo...@comcast.net> wrote: > > > I'm a bit stumped here, maybe someone can help me out? > > > y = atan (sin(2*pi*x) / cos(2*pi*x)); > > > s = atan2 (sin(2*pi*x) , cos(2*pi*x)); > > > I would expect y and s to be equal, but they're not. > > > Most surprising to me is that the maximum value of s appears to be pi, > > despite the fact that the limit of atan2(a,b) as a/b->infinity is pi/2 > > (right?) > > > Can anyone clue me in as to why my expectations are being defied here? I > > think the root of my misunderstanding lies in my not understanding the > > differences between atan(a/b) and atan2(a,b). > > > Thanks, any help is much appreciated
Reply by ●January 9, 20082008-01-09
In case if you can get hold of the book "understanding dsp" by richard lyons a nice section is written, 13.21 an efficient arctangent approximation. which tells about how to approximate theta = atan(Q/I) where Q and I can be both positive as well as negative numbers. actually the tan(theta) plot can go both positive infinity and negative infinity. but atan plot output is always bounded between -pi and pi, though the input argument can go both +/- infinity. so when you consider Q and I seperately (meaning signs of it), we get the sense of quadrant. Else the sense of quadrant is somewhat lost when we have a single quantity Q/I as an argument. Bharat Pathak Arithos Designs
Reply by ●January 9, 20082008-01-09
i just noticed a mistake: On Jan 8, 6:52 pm, robert bristow-johnson <r...@audioimagination.com> wrote:> > atan2(Im{z}, Re{z}) is meant to be the angle of a complex number z. > > arg{z} = atan2(Im{z}, Re{z}) > > when using the atan2(Im{z}, Re{z}) for the angle of a complex number, > it is correct only if Re(z)>0. for the case Re(z)<0, your atan2(Im{z}, > Re{z}) expression for the angle is off by a constant value of pi.i meant to say: "when using the arctan(Im{z}/Re{z}) for the angle of a complex number, it is correct only if Re(z)>0. for the case Re(z)<0, your arctan(Im{z}/Re{z}) expression for the angle is off by a constant value of pi." atan2(Im{z}, Re{z}) is correct (for the principal angle) in anycase where z is not 0. also> {arctan(Im{z}/Re{z}) Re{z}>0, Im{z}<|Re{z}| > arg{z} = { > {sgn(Im{z})*pi/2 - arctan(Re{z}/Im{z}) otherwizeis slightly wrong. but i think the rest of it was accurate. the 4-quadrant expressions for arg{z} are useful for the case where you might not have an efficient implementation of atan2() available to you in your DSP context, e.g. phase-vocoder or sinusoidal modeling. then you have to combine this { arctan(Im{z}/Re{z}) Re{z}>0, |Im{z}|<=Re{z} { { pi/2 - arctan(Re{z}/Im{z}) Im{z}>0, |Re{z}|<=Im{z} { Arg{z} = {-pi/2 - arctan(Re{z}/Im{z}) Im{z}<0, |Re{z}|<=-Im{z} { { arctan(Im{z}/Re{z}) + pi Re{z}<0, 0<=Im{z}<=-Re{z} { { arctan(Im{z}/Re{z}) - pi Re{z}<0, Re{z}<=Im{z}<0 with a means of implementing arctan(), such as arctan(x) ~= x/f(x^2) where f(u) = 1.0 + 0.33288950512027 * u + -0.08467922817644 * u^2 + 0.03252232640125 * u^3 + -0.00749305860992 * u^4 for |x| <= 1 . r b-j
Reply by ●January 9, 20082008-01-09
On Jan 8, 7:56�pm, p.kootsoo...@remove.ieee.org (Peter K.) wrote:> "maxplanck" <erik.bo...@comcast.net> writes: > > I'm a bit stumped here, maybe someone can help me out? > > > y = atan (sin(2*pi*x) / cos(2*pi*x)); > > > s = atan2 (sin(2*pi*x) , cos(2*pi*x)); > > > I would expect y and s to be equal, but they're not. > > > Most surprising to me is that the maximum value of s appears to be pi, > > despite the fact that the limit of atan2(a,b) as a/b->infinity is pi/2 > > (right?) > > > Can anyone clue me in as to why my expectations are being defied here? �I > > think the root of my misunderstanding lies in my not understanding the > > differences between atan(a/b) and atan2(a,b). > > > Thanks, any help is much appreciated > > y is just the principle value, which will only be -pi/2 and pi/2. > > s is the four quandrant version which can be between -pi and pi. > > http://en.wikipedia.org/wiki/Atan > > (see the section entitled "Two argument variant of arctangent"). > > Ciao, > > Peter K. > > -- > "And he sees the vision splendid > of the sunlit plains extended > And at night the wondrous glory of the everlasting stars."- Hide quoted text - > > - Show quoted text -Peter, Word is "principal' not your word "principle". Correct wordings most value if you are too be Dsp Guru! Ciao, Kamar Ruptan






