# Trying to find square of "control system"

1 view (last 30 days)
Milan Hrstka on 22 Apr 2022
Commented: Milan Hrstka on 23 Apr 2022
Hello,
I am working on my bachelor's thesis and I am trying to implement one of the PID tuning method where is required to get "control system" - "square of control system".
I have code where i get transfer function with time delay -> G(s) = (1/(6s+1))*exp(-0.5s)
Then i have controller (PID controller) -> R(s) = kp + (kp/T_I*s) + kp*T_D*s
So the "control system" is -> W(s) = G*R / (1 + G*R)
Then i need to substitute 's' for 'omega*j' and calculate (W(omega*j))^2 which should be -> W(omega*j) * W(-omega*j) as my teacher said. After that I should get something where imaginary part 'j' shouldn't be .. but in my code after this process there are still 'j' in the "equation".
My code is:
syms P_slozka; % kp
syms I_slozka; %T_I
syms D_slozka; %T_D
syms s;
syms omega;
% just getting num and den of transfer function
pre = tf([1], [6 1]); %transfer function (input)
zpozdeni = 0.5; %time delay
[n, d] = tfdata(pre);
pomocna_1 = cell2mat(d);
pomocna_2 = cell2mat(n);
jmenovatel = 0;
for c = length(pomocna_1):-1:1
jmenovatel = jmenovatel + pomocna_1(c)*(s).^(length(pomocna_1)-c);
end
citatel = 0;
for c = length(pomocna_2):-1:1
citatel = citatel + pomocna_2(c)*s.^(length(pomocna_2)-c);
end
% now citatel (num) = 1
% jmenovatel (den) = 6*s+1
%
prenos = (citatel / jmenovatel) * exp(-zpozdeni*(s)); % G(s)
regulator = P_slozka + (P_slozka/(I_slozka*(s))) + P_slozka*(D_slozka*(s)); % R(s)
rizeni = (prenos*regulator) / (1 + (prenos*regulator)); % W(s)
% substitution of s for omega*j and -omega*j
rizeni1 = subs(rizeni, s, str2sym('1j*omega'));
rizeni2 = subs(rizeni, s, str2sym('-1j*omega'));
rizeni = rizeni1*rizeni2 % result which still obtains imaginary parts 'j' as you can see below
Result:
rizeni = ((P_slozka - (P_slozka*1i)/(I_slozka*omega) + D_slozka*P_slozka*omega*1i)*(P_slozka + (P_slozka*1i)/(I_slozka*omega) - D_slozka*P_slozka*omega*1i))/((- 1 + omega*6i)*(1 + omega*6i)*((exp(-(omega*1i)/2)*(P_slozka - (P_slozka*1i)/(I_slozka*omega) + D_slozka*P_slozka*omega*1i))/(1 + omega*6i) + 1)*((exp((omega*1i)/2)*(P_slozka + (P_slozka*1i)/(I_slozka*omega) - D_slozka*P_slozka*omega*1i))/(- 1 + omega*6i) - 1))
My teacher says that there must be mistake somewhere and the result shouldn't obtain imaginary parts at all (it should be eliminated by that "square process"). But I don't know where might be the mistake.
I would be glad for help with this issue nad I am really sorry for my English because I don't know how to express this in that language.

Paul on 23 Apr 2022
Declare the control gains and frequency as real.
syms P_slozka real; % kp
syms I_slozka real; %T_I
syms D_slozka real; %T_D
syms s;
syms omega real;
Continue with the rest of the code
% just getting num and den of transfer function
pre = tf([1], [6 1]); %transfer function (input)
zpozdeni = 0.5; %time delay
[n, d] = tfdata(pre);
pomocna_1 = cell2mat(d);
pomocna_2 = cell2mat(n);
jmenovatel = 0;
for c = length(pomocna_1):-1:1
jmenovatel = jmenovatel + pomocna_1(c)*(s).^(length(pomocna_1)-c);
end
citatel = 0;
for c = length(pomocna_2):-1:1
citatel = citatel + pomocna_2(c)*s.^(length(pomocna_2)-c);
end
% now citatel (num) = 1
% jmenovatel (den) = 6*s+1
%
prenos = (citatel / jmenovatel) * exp(-zpozdeni*(s)); % G(s)
regulator = P_slozka + (P_slozka/(I_slozka*(s))) + P_slozka*(D_slozka*(s)); % R(s)
rizeni = (prenos*regulator) / (1 + (prenos*regulator)); % W(s)
% substitution of s for omega*j and -omega*j
rizeni1 = subs(rizeni, s, str2sym('1j*omega'));
rizeni2 = subs(rizeni, s, str2sym('-1j*omega'));
rizenisq = rizeni1*rizeni2 % result which still obtains imaginary parts 'j' as you can see below
rizenisq =
Check the imaginary part
imag(rizenisq)
ans =
0
Because that's zero, we only need the real part
rizenisq = simplify(real(expand(rizenisq)))
rizenisq =
The code can be much simplified
syms P_slozka real; % kp
syms I_slozka real; %T_I
syms D_slozka real; %T_D
syms s;
syms omega real;
prenos(s) = 1/(6*s + 1)*exp(-sym(1/2)*s);
regulator(s) = P_slozka + (P_slozka/(I_slozka*(s))) + P_slozka*(D_slozka*(s)); % R(s)
rizeni(s) = (prenos*regulator) / (1 + (prenos*regulator)); % W(s)
% substitution of s for omega*j and -omega*j
rizeni1 = rizeni(1j*omega);
rizeni2 = rizeni(-1j*omega);
rizenisq = rizeni1*rizeni2 % result which still obtains imaginary parts 'j' as you can see below
rizenisq =
imag(rizenisq)
ans =
0
rizenisq = simplify(real(expand(rizenisq)))
rizenisq =
Milan Hrstka on 23 Apr 2022
Thank you very much!

R2022a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!