To test the simulation that has been done.
Activity
Test the simulation to gain the result that is needed. The test would be using various transfer function to gain the needed result.
Analysis
The result for the test can be seen below:
Result for transfer function:
0.009201 z + 0.005709
--------------------------
z^2 - 1.088 z + 0.2369
Result for the test |
% File Name : fyp.m
% A fuzzy controller is designed to control the system
% The inputs to the FLC are error and change in error.
% clear all;
% clc;
npoints = 1000;
d = 100;
vk = 0;
vk1 = 0;
tk = 0;
tk1 =0;
ref = 1.0;
perr = 0;
delerr = 0;
% Code for step input generation
ref = 1;
nfin = npoints;
step = nfin/d;
ni = 1;
nf = d;
flag = 1;
for i = 1:step
if(flag == 1)
r(ni:nf) = 1;
ni = nf+1;
nf = nf+d;
flag = 0;
else
r(ni:nf) = -1;
ni = nf+1;
nf = nf+d;
flag = 1;
end
end
fismat = readfis('try1.fis');
for i = 1:npoints
%ref = r(i);
ref = 1;
tk2 = 1.078*tk1-0.2426*tk+0.009201*vk1+0.005709*vk;
out(i) = tk2;
tk = tk1;
tk1 = tk2;
err = ref - tk2;
delerr = err - perr;
perr = err;
error(i) = err;
delerror(i) = delerr;
vk = vk1;
vk1 = evalfis([err delerr],fismat);
vkout(i) = vk1;
end;
figure(1);
grid on;
i=0:npoints-1;
plot(i,out(1:npoints),'k');
xlabel('k');
ylabel('Output');
title('Basic FLC : Attitude Response for Step Input');
The result shows the response curve of the motor system that is designed in the programming. The output should be 1 but for this result, the output is 0.9.
Result for transfer function:
1/s^2
Result for the test |
The programming:
% File Name : NSYS1.m
% Given system is
% theta(k+2) = 2*theta(k+1) - theta(k)+ 0.5*m(k+1) + 0.5*m(k)
% A fuzzy controller is designed to control the system
% The inputs to the FLC are error and change in error.
% clear all;
% clc;
npoints = 1000;
d = 100;
mk = 0;
mk1 = 0;
tk = 0;
tk1 =0;
ref = 1.0;
perr = 0;
delerr = 0;
% Code for step input generation
ref = 1;
nfin = npoints;
step = nfin/d;
ni = 1;
nf = d;
flag = 1;
for i = 1:step
if(flag == 1)
r(ni:nf) = 1;
ni = nf+1;
nf = nf+d;
flag = 0;
else
r(ni:nf) = -1;
ni = nf+1;
nf = nf+d;
flag = 1;
end
end
fismat = readfis('naga38.fis');
for i = 1:npoints
%ref = r(i);
ref = 1;
tk2 = 2*tk1-tk+0.5*mk1+0.5*mk;
out(i) = tk2;
tk = tk1;
tk1 = tk2;
err = ref - tk2;
delerr = err - perr;
perr = err;
error(i) = err;
delerror(i) = delerr;
mk = mk1;
mk1 = evalfis([err delerr],fismat);
mkout(i) = mk1;
end;
figure(1);
grid on;
i=0:npoints-1;
plot(i,out(1:npoints),'k');
xlabel('k');
ylabel('Output');
title('Basic FLC : Attitude Response for Step Input');
The result shows the response curve of the motor system that is designed in the programming. The output is the same with reference speed that have been set.