No Title

02 June 2020

Views: 53

function pushplot_Callback(hObject, eventdata, handles)

global a0 a1 a2 a3 a4 b0 n m b1 b2 b3 b4
% hObject handle to pushplot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
n=str2num(get(handles.editn,'String'));
m=str2num(get(handles.editm,'String'));

if(n==1)
a2=0;
a3=0;
a4=0;
b2=0;
b3=0;
b4=0;
a0=str2double(get(handles.edita0,'String'));
a1=str2double(get(handles.edita1,'String'));
b0=str2double(get(handles.editb0,'String'));
b1=str2double(get(handles.editb1,'String'));
end
if(n==2)
a3=0;
a4=0;
b3=0;
b4=0;
a0=str2double(get(handles.edita0,'String'));
a1=str2double(get(handles.edita1,'String'));
a2=str2double(get(handles.edita2,'String'));
b0=str2double(get(handles.editb0,'String'));
b1=str2double(get(handles.editb1,'String'));
b2=str2double(get(handles.editb2,'String'));
end
if(n==3)
a4=0;
b4=0;
a0=str2double(get(handles.edita0,'String'));
a1=str2double(get(handles.edita1,'String'));
a2=str2double(get(handles.edita2,'String'));
a3=str2double(get(handles.edita3,'String'));
b0=str2double(get(handles.editb0,'String'));
b1=str2double(get(handles.editb1,'String'));
b2=str2double(get(handles.editb2,'String'));
b3=str2double(get(handles.editb3,'String'));
end
if(n==4)
a0=str2double(get(handles.edita0,'String'));
a1=str2double(get(handles.edita1,'String'));
a2=str2double(get(handles.edita2,'String'));
a3=str2double(get(handles.edita3,'String'));
a4=str2double(get(handles.edita4,'String'));

b0=str2double(get(handles.editb0,'String'));
b1=str2double(get(handles.editb1,'String'));
b2=str2double(get(handles.editb2,'String'));
b3=str2double(get(handles.editb3,'String'));
b4=str2double(get(handles.editb4,'String'));
end

if(m<4)
b4=0
end
if(m<3)
b3=0;
end
if(m<2)
b2=0;
end
if(m<1)
b1=0;
end

state=get(handles.popupmenu1,'Value');
switch state
case 1
%set(handels.popupmenu,'Value');
case 2
% Ns=100;
% T=0.1
t=-100:100;
L=length(t);
for i=1:L
if(t(i)>= 0) x(i)=1;
else x(i)=0;

end
end
%axes(handles.axes1);
figure;
plot(t,x);
title('Unit Step Input');
Ts=0.01;
t=0:Ts:20-Ts;
Ns=2000;
T=Ts;
x2=ones(1,Ns);
x1=zeros(1,0*Ns/4)
u=[x1 x2];
figure;
plot(t,u)
y=zeros(1,Ns);
% u=ones(1,Ns)*(t-1);
% figure;
% plot(u)
% xlim([-10 10])
A0=(4*a4/(T*T*T*T)+3*a3/(T*T*T)+2*a2/(T*T)+a1/T);
B0=(b4/(T*T*T*T)+b3/(T*T*T)+b2/(T*T)+b1/T+b0);
B1=(4*b4/(T*T*T*T)+3*b3/(T*T*T)+2*b2/(T*T)+b1/T);
B2=(6*b4/(T*T*T*T)+3*b3/(T*T*T)+b2/(T*T));
B3=(4*b4/(T*T*T*T)+b3/(T*T*T)) ;
B4=(b4/(T*T*T*T));
A1=(6*a4/(T*T*T*T)+3*a3/(T*T*T)+a2/(T*T));
A2=(4*a4/(T*T*T*T)+a3/(T*T*T));
A3=(a4/(T*T*T*T));
for(k=n+1:Ns)

num=y(k-1)*A0 +u(k)*B0 - u(k-1)*B1;
if(n==2)
num=num-y(k-2)*A1+u(k-2)*B2;
end
if(n==3)
num=num-y(k-2)*A1+ y(k-3)*A2+u(k-2)*B2 - u(k-3)*B3;
% h= u(k-2);

end
if(n==4)
num = num-y(k-2)*A1+y(k-3)*A2-y(k-4)*A3 +u(k-2)*B2-u(k-3)*B3+ u(k-4)*B4;
end
den=(a4/(T*T*T*T)+a3/(T*T*T)+a2/(T*T)+a1/T+a0);
y(k)=num/den;
end

%axes(handles.axes2);
figure;
plot(t,y);
xlim([0 10])
title('Output');
x1=zeros(1,Ns);
x2=zeros(1,Ns);
x3=zeros(1,Ns);
x4=zeros(1,Ns);
if(n==m)
if(n==4)
x1=-(b4/a4)*u+y;
x2;
x3;
x4;
elseif(n==3)
x1=-(b3/a3)*u+y;
x2;
x3;
elseif(n==2)
x1=-(b2/a2)*u+y;
x2;
elseif(n==1)
x1=-(b1/a1)*u+y;
end
end
if(n>m)
x1=y;
end

figure;
plot(t,x1)
title('x1')


case 3
Ns=100;
T=0.1;
y=zeros(1,Ns);
Ts=0.001;
t=-10:Ts:10-Ts;
Ns=20000;
T=Ts;
x2=ones(1,Ns/2);
x1=zeros(1,Ns/2)
u=[x1 x2]
% figure;
% plot(t,u)

for(k=n+1:Ns)
num=y(k-1)*(4*a4/(T*T*T*T)+3*a3/(T*T*T)+2*a2/(T*T)+a1/T)+u(k)*(b4/(T*T*T*T)+b3/(T*T*T)+b2/(T*T)+b1/T+b0)
-u(k-1)*(4*b4/(T*T*T*T)+3*b3/(T*T*T)+2*b2/(T*T)+b1/T);
if(n==2)num=num-y(k-2)*(a2/(T*T))+u(k-2)*(b2/(T*T));

elseif(n==3)num=num -y(k-2)*(3*a3/(T*T*T)+a2/(T*T))
+y(k-3)*(a3/T*T*T)
+u(k-2)*(3*b3/(T*T*T)+ b2/(T*T))
-u(k-3)*( b3/(T*T*T));

elseif(n==4) num = num-y(k-2)*(6*a4/(T*T*T*T)+3*a3/(T*T*T)+a2/(T*T))
+y(k-3)*(4*a4/(T*T*T*T)+a3/T*T*T)-y(k-4)*(a4/(T*T*T*T))
+u(k-2)*(6*b4/(T*T*T*T)+3*b3/(T*T*T)+b2/(T*T))
-u(k-3)*(4*b4/(T*T*T*T)+b3/(T*T*T))+u(k-4)*(b4/(T*T*T*T));
end
den=(a4/(T*T*T*T)+a3/(T*T*T)+a2/(T*T)+a1/T+a0);
y(k)=num/den;
end
for(k=2:Ns)
impulse(k)=(y(k)-y(k-1))/T;


end
%axes(handles.axes2);
figure;
plot(impulse)
title('Output')
t = (-10:0.01:10)';

impulse = t==0;
%axes(handles.axes1)
figure;
plot(t,impulse)
title('Unit Impulse Input');
end

Share