Matlab 中求相位的函數有 phase atan2 angle atan
Phase和angle的區別:
1Phase 支持標量和一維向量輸入 angle 可以輸入任意矩陣,
2相鄰相位角差的絕對值大於3.5時,phase會對相位角做修正,angle則不會,例如
a=[-1+i,-1-i]; phase(a)結果為[-2.3562 -3.9270],
而angle(a)結果為[-2.3562 2.3562].
這兩點區別可以從它們的源代碼中看出來,在命令行中鍵入edit phase和edit angle即可以得到
function PHI=phase(G)
[nr,nc] = size(G);
if min(nr,nc) > 1
error(sprintf(['PHASE applies only to row or column vectors.'...
'\nFor matrices you have to decide along which dimension the'...
'\nphase should be continuous.']))
end
if nr>nc
G = G.';
end
PHI=atan2(imag(G),real(G));
N=length(PHI);
DF=PHI(1:N-1)-PHI(2:N);
I=find(abs(DF)>3.5);
for i=I
if i~=0,
PHI=PHI+2*pi*sign(DF(i))*[zeros(1,i) ones(1,N-i)];
end
end
if nr>nc
PHI = PHI.';
end
function p = angle(h)
p = atan2(imag(h), real(h));
從angle.m中可見,angle實際上是atan2(imag,real)的形式,imag和real都為實數
另外,還有個求反正切的函數atan,它與atan2的區別在於:1.atan(x)得出的結果區間是[-pi/2,pi/2],atan2(x)的區間是[-pi,pi]
2.atan(x)只能用於求實數,atan2(x)可以用於求實數或者複數的相位
在matlab中鍵入 x=-20:0.01:20; y=plot(x,atan(x));grid on;結果如下:
鍵入x=-20:0.01:20;y=plot(x,atan2(x));grid on;結果如下: