Filter löschen
Filter löschen

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

4 Ansichten (letzte 30 Tage)
Waleed new
Waleed new am 2 Sep. 2018
Beantwortet: Amir Xz am 2 Sep. 2018
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 .

Antworten (1)

Amir Xz
Amir Xz am 2 Sep. 2018
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])

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by