Electrical – How to generate the described pulse signal in Matlab (Simulink)

codeMATLABsignalsimulinkwaveform

I want to implement the following signal:

enter image description here

I(t) = 500*(sin(pi.t/0.3))^2, t belongs {0,Ts}

= 0, t belongs {Ts,T}

Here, T = 0.8 and Ts = 0.3

The code I tried:

t = 0 : 0.001 : 25;         
d = 0 : 0.8 : 25;           
y = pulstran(t,d,'rectpuls',0.3);
ut = 500.*((sin(pi*t/0.3)).^2).*y;
plot(t,ut)
xlabel 'Time (s)', ylabel Waveform

The generated waveform deforms greatly, for example the generated waveform does not consist of uniformly spaced peaks.

Edit: Modified the code but still issues remain.

    t = 0.01 * [0:3000]';         
    d = 0.8 * [0:1500]';           
    y = pulstran(t,d,'rectpuls',0.3);
    ut = 500.*((sin(pi*(t-floor(t/0.8)*0.8)/0.3)).^2).*y;
    plot(t,ut)

Mainly, instead of 1 peak for the 0.3s ON state, there are two peaks.

enter image description here

Best Answer

I still don't understand what your period is, so I generated two ways to do this. The first method creates a mod vector of the time and generates a zero vector, the zero vector zeros out the data. As shown in the first figure.

t = 0 : 0.001 : 2;
T = 0.8;
Tz = 0.4; %this is T = Tz + Ts
yy = mod(t,T) %create mod vector to periodize time vector
yy(yy>Tz) = 0; %zero out unwanted portion of vector
ut = 500.*((sin(pi*t/T)).^2);
utt = ut.*(yy>0); %this is the zeroed out sine wave
figure,plot(t,ut),hold on,plot(t,(yy>0)*500,'g');
plot(t,utt,'r+')
xlabel 'Time (s)', ylabel Waveform
legend('i(t)','Mod time vector','sin^2(t) zeroed out')

enter image description here

td = 0.001; %time vector resoult
T = 0.8;
Tgap = 0.34; %vector gap
Tend = 2;
t = 0:td:Tend;
ttt = [0:td:T-td zeros(1,round(Tgap/td))]; %create vector with zero gap
tt = repmat(ttt,1,1+round(length(t)/length(ttt))); % repeat the vector for as long as the time vector is +1
tt = tt(1:length(t)); %truncate it to be the same size as the time vector
ut = 500.*((sin(pi*tt/T)).^2);

figure;plot(t,ut),xlabel 'Time (s)', ylabel Waveform

This one creates a gap in between each \$ sin^2(t)\$ function, it does this by creating an time vector with zeros in it and then replicating the vector. I didn't use the same time periods so you would have to go through the code and figure it out for yourself.

enter image description here

Related Topic