我對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')
下面是複數的情節 -
注意,我可以使用的角度()函數,或相位的明確定義,如上所示。兩者都產生了良好的結果(我不能解開後者,但那不是我的問題)。因爲沒有虛部存在,所以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')
下面是實數的情節 -
爲什麼振盪時我使用角度()?
你確定你不需要其他傳統的atan定義,實現爲'atan2'嗎? –