2017-02-16 34 views
3

我對Matlab中的angle()函數有點困惑,特別是當應用於實數數組時。angle()的實數

angle()函數應該給我一個複數的相位。例如:y = a + bi,==> phase = arctan(b/a)。事實上,以下工作:

for t=1:1000 
    comp(t) = exp(1i*(t/10)); 
end 

phase_good_comp1 = unwrap(angle(comp)); %this gives me the right answer 
b = imag(comp); 
a = real(comp); 
phase_good_comp2 = atan(b./a); %this gives me the right answer too, but 
wrapped (not sure if there is a way to unwrap this, but unwrap() does not 
work) 

figure(1) 
plot(phase_good_comp1) 
hold on 
plot(phase_good_comp2,'--r') 
legend('good phase1', 'good phase2') 
title('complex number') 

下面是複數的情節 -

enter image description here

注意,我可以使用的角度()函數,或相位的明確定義,如上所示。兩者都產生了良好的結果(我不能解開後者,但那不是我的問題)。因爲沒有虛部存在,所以arctan(b/a)= arctan(0)= 0。如果我將相同的邏輯應用於一個實數數組,我用的階段,明確的定義,但我得到一個奇怪的結果,如果我用角():

for t=1:1000 
    ree(t) = cos((t/10)); 
end 

phase_bad_re = unwrap(angle(ree)); %this gives me an unreasonable (?) answer 
b = imag(ree); 
a = real(ree); 
phase_good_re = atan(b./a); %this gives me the right answer 

figure(1) 
plot(phase_bad_re) 
hold on 
plot(phase_good_re,'--r') 
legend('bad phase', 'good phase') 
title('real number') 

下面是實數的情節 -

enter image description here

爲什麼振盪時我使用角度()?

+3

你確定你不需要其他傳統的atan定義,實現爲'atan2'嗎? –

回答

4

Matlab的文檔講述瞭如何計算這樣的:

角度函數可以表示爲angle(z) = imag(log(z)) = atan2(imag(z),real(z))

https://www.mathworks.com/help/matlab/ref/angle.html

注意,他們與atan2而不是atan定義它。

現在您的數據處於餘弦範圍內,其中包括正數和負數。正數上的角度應該是0,負數上的角度應該是pi的奇數整數倍。使用他們選擇的特定定義來獲得唯一的答案,它是pi。這就是你得到的。 (實際上,對於正數,pi的任何偶數倍都可以,但0是「自然」選擇,你從atan2得到的那個)

如果你不清楚爲什麼負數沒有角度= 0,將其繪製在複平面中,並記住複數的徑向部分根據定義爲正。那就是z = r * exp(i*theta)對於正面rtheta給出你正在計算的這個角度。

+0

「......根據定義,複數的徑向部分爲正值」爲我清除所有內容。謝謝。 –

1

由於餘弦函數的符號週期性地改變,角度()也會振盪。

請試試這個。

a=angle(1); 
b=angle(-1); 

1 + i * 0的相位是0,而-1 + i * 0的相位是3.14。

但是,ATAN的情況下,B/A總是0,​​因此ATAN()的結果是全0

相關問題