Generate repeated sequence block uisng matlab code
Show older comments
Hello, please I want to generate repeated sequence plot using MATLAB codes but not simulink. I have written the code and the interpolation. However, I think my 'for loop' to pick all the points in the sequence is not capturing all. I have given the scripts below and I have attached one of the similar plots I have genrated using SIMULINK's repeating sequence block.
dt=1e-4;
T = 200;
n0=1;
time=0:dt:T;
nt=length(time);
ref=zeros(nt,1);
%time_point=[0 100 700 1000 1300 1600 1780 2080 2260 2560 2680 2980 3040 3340 3400 3700]
%pow_point=[1 1 0.9 0.9 0.8 0.8 0.65 0.65 0.95 0.95 0.55 0.55 0.15 0.15 0.95 0.95]
%time_point=[0 20 30 50 60 80 90 110 130 150];%work with only this time
%time_point=[0 10 40 70 80 100 110 130 140 150];
%time_point=[0 30 40 50 60 70 90 100 140 150];
time_point=[0 20 30 50 60 80 90 110 130 200];
%pow_point=[0.8 0.8 0.4 0.4 0.8 0.8 0.4 0.4 0.8 0.8];power Transient
%pow_point=[1 1 0.4 0.4 1 1 0.4 0.4 1 1];
%pow_point=[1 1 0.4 0.4 0.6 0.6 0.8 0.8 1 1];
%pow_point=[0.9 0.9 0.3 0.3 0.9 0.9 0.3 0.3 0.9 0.9];
pow_point=[0.7 0.7 0.4 0.4 0.4 0.4 0.6 0.6 0.7 0.7];
%pow_point=[0.5 0.5 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1];
ref_old=pow_point(1);
for it=1:nt %to vectorize nt or make each point of nt
if(it>1)
time(it)=time(it-1)+dt;%to be able to make equal time step of the time
ref_old=ref(it-1); %for each time slot
end
ref(it)=ref_old;
i1=1;
i2=1;
for ii=1:length(time_point)-1
if(time_point(ii)<=time(it) && time(it)<=time_point(ii+1))
i1=ii;
i2=ii+1;
frac1=(time_point(ii+1)-time(it))/(time_point(ii+1)-time_point(ii));
frac2=1.0-frac1;
ref(it)=frac1*pow_point(i1)+frac2*pow_point(i2);
break
end
end
end
ref(:)=ref(:);
yref=(ref.*n0);
for s =1:nt
setpoint=yref(s);
end
Accepted Answer
More Answers (0)
Categories
Find more on Signal Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!