how to make a square wave as input of transfer function in MATLAB ?

3 次查看(过去 30 天)
i'm trying to convert this simple simulink block to matlab program
function ydot = fslve(y)
kd1=6.4;
kp1=16;
phi_c=10;
ydot(1)=y(2);
ydot(2)=kp1*(phi_c-y(1))-kd1*y(2);
ydot=[ydot(1);ydot(2)];
ydot=ydot(:);
end
-----------------------------------
[t,y]=ode45(@(t,y)fslve(y),[0 10],[0 0]);
figure
plot(y(:,1))
figure
plot(y(:,2))
in matlab program i want to make phi_c as a square wave any help i appreciate it .

回答(1 个)

Amir Xz
Amir Xz 2018-9-2
h=2;TimeEnd=20; % inputs
t=0:0.01:TimeEnd;
x=h/2:2*h:t(end);
n=length(x);
win=h*rectpuls(t-x(1),h);
for i=2:n
win=win+h*rectpuls(t-x(i),h);
end
plot(t,win),grid on
axis([t(1) t(end) -1 2*h])

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by