forked from Future-Power-Networks/Simplus-Grid-Tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdq2abc.m
67 lines (56 loc) · 2.06 KB
/
dq2abc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
% This function transforms a time-domain signal from the synchronous frame
% (dq0 frame) to natural frame (abc frame).
% Author(s): Yitong Li
% Notes:
%
% theta is the angle that dq axis leads abc axis.
%
% q axis leads d axis by 90 degrees.
function u_abc = dq2abc(u_dq,theta,varargin)
% Default settings
Flag_PowerVariant = false; % Default, power invariant
Flag_DirectMatrixCalculation = true; % Default, direct calculation
% Check advanced settings
for n = 1:length(varargin)
if (strcmpi(varargin{n},'PowerVariant'))
Flag_PowerInvariant = varargin{n+1};
elseif (strcmpi(varargin{n},'DirectMatrixCalculation'))
Flag_DirectMatrixCalculation = varargin{n+1};
end
end
% Check the form of the input signal
[r,c] = size(u_dq);
if (r==2) && (c==1)
Flag_ZeroSequence = 0;
elseif (r==3) && (c==1)
Flag_ZeroSequence = 1;
else
error('Error: Input signal is not a 2*1 or 3*1 vector.')
end
% Get the transformation matrix directly
if Flag_DirectMatrixCalculation
if Flag_PowerVariant
T = [cos(theta), -sin(theta), 1;
cos(theta-2/3*pi), -sin(theta-2/3*pi), 1;
cos(theta-4/3*pi), -sin(theta-4/3*pi), 1];
else
T = sqrt(2/3)*[cos(theta), -sin(theta), 1/sqrt(2);
cos(theta-2/3*pi), -sin(theta-2/3*pi), 1/sqrt(2);
cos(theta-4/3*pi), -sin(theta-4/3*pi), 1/sqrt(2)];
end
% Check zero sequence
if Flag_ZeroSequence
T_dq2abc = T;
else
T_dq2abc = T(:,1:2);
end
% Frame transformation
u_abc = T_dq2abc * u_dq;
% Call "abc2alphabeta" and "alphabeta2dq" to acheive two-step
% transformation.
else
% Frame transformation
u_alphabeta = SimplusGT.dq2alphabeta(u_dq,theta);
u_abc = SimplusGT.alphabeta2abc(u_alphabeta,'PowerVariant',Flag_PowerVariant,'ZeroSequence',Flag_ZeroSequence);
end
end