JUK1
rot.m
Go to the documentation of this file.
1 function [OUT]=rot(S); %03.04.2001, Bjorn G.
2 %CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
3 %C Rotating e-vectors so that the imag. parts are minimized in the "least squares sense"
4 %C V. Brandwajn, EMTP Newsletter, August 1982 :
5 %C
6 
7 Nc=length(S);
8 
9 
10 % E-vector #col :
11  for col=1:Nc
12 % Calculate min/max-value for square sum (error) of imag.parts :
13  numerator(col)=0.0;
14  denominator(col)=0.0;
15  for j=1:Nc
16  numerator(col)=numerator(col)+imag(S(j,col))*real(S(j,col)); % Q2(j,i)*Q1(j,i)
17  denominator(col)=denominator(col)+(real(S(j,col)))^2 - (imag(S(j,col)))^2; % Q1(j,i)**2 - Q2(j,i)**2
18  end
19 
20  numerator(col)=-2.0*numerator(col);
21  ang(col)=0.5*atan2(numerator(col),denominator(col));
22 
23  scale1(col)=cos(ang(col)) +i*sin(ang(col));
24  %11.07.2001 B.G.
25  % scale2(col)=scale1(col) + pi/2.0;
26  scale2(col)=cos(ang(col)+pi/2) +i*sin(ang(col)+pi/2);
27 % Deciding which solution (1,2) will produce the smallest error :
28 
29  for j=1:Nc
30  SA(j,col)=S(j,col)*scale1(col);
31  SB(j,col)=S(j,col)*scale2(col);
32  end
33 
34 % Square sum (error) of solution :
35  aaa=0.0;
36  bbb=0.0;
37  ccc=0.0;
38  for j=1:Nc
39  aaa = aaa + (imag(SA(j,col)))^2; % Q2A(j,i)**2
40  bbb = bbb + real(SA(j,col))*imag(SA(j,col)); % Q1A(j,i)*Q2A(j,i)
41  ccc = ccc + (real(SA(j,col)))^2; % Q1A(j,i)**2
42  end
43  err1(col)=aaa*cos(ang(col))^2 + bbb*sin(2.0d0*ang(col))+ ccc*sin(ang(col))^2;
44 
45 % Square sum (error) of solution #2 :
46  aaa=0.0;
47  bbb=0.0;
48  ccc=0.0;
49  for j=1:Nc
50  aaa = aaa + (imag(SB(j,col)))^2; % Q2A(j,i)**2
51  bbb = bbb + real(SB(j,col))*imag(SB(j,col)); % Q1A(j,i)*Q2A(j,i)
52  ccc = ccc + (real(SB(j,col)))^2; % Q1A(j,i)**2
53  end
54  err2(col)=aaa*cos(ang(col))^2 + bbb*sin(2.0d0*ang(col))+ ccc*sin(ang(col))^2;%+ ccc*sin(ang(col))^2;
55 
56 % Picking the solution (1,2) with the smallest square sum :
57  if(err1(col)<err2(col))
58  scale(col)=scale1(col);
59  else
60  scale(col)=scale2(col);
61  end
62 
63 % Rotating e-vector #col :
64  S(:,col)=S(:,col).*scale(col);
65 end
66 
67  OUT=S;
pi
Definition: Freq.m:24
for i
ang(col sin()
Square sum(error) of solution aaa=0.0
scale1(col)
end Square sum(error) of solution bbb
Definition: rot.m:36
ccc
Definition: rot.m:37
i **end numerator(col)
B G scale2(col)
Q2(j, i) *Q1(j
end OUT
Definition: rot.m:67
Q1A(j, i) *Q2A(j
denominator(col)=0.0
Picking the solution(1, 2) with the smallest square sum else scale(col)
Q1(j, i) **2 - Q2(j
Deciding which solution(1, 2) will produce the smallest error SB(j, col)
for j
Definition: rot.m:15
Q2A(j, i) **2 bbb
ang(col)=0.5 *atan2(numerator(col)