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;
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;

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

enter image description here

  • \$\begingroup\$ Its not possible with the information you supplied, \$ sin^2(\theta) \$ has a period of 0.3 (for T) and your T is 0.8 edit the question. If you want to transfer the period use \$ sin^2(\theta) = (1 - cos[2\theta])/2\$ \$\endgroup\$ – Voltage Spike Aug 23 '16 at 18:47
  • \$\begingroup\$ The function results such that for 0-0.3s, the sin^2 wave is generated. For 0.3-0.8s, the value is 0. Then again, for next 0.3s, the sin^2 wave is generated as it t = 0 to 0.3. Then 0 for for next 0.5s. And so on. \$\endgroup\$ – Rachit Ajitsaria Aug 25 '16 at 12:15
  • \$\begingroup\$ Its unclear to me what kind of period you want to cutoff the \$ sin^2\$ wave. The \$ sin^2\$ wave has a period of 0.3 on the scale of 0 to 0.3 where do you want the \$ sin^2\$ wave to be cutoff to zero? \$\endgroup\$ – Voltage Spike Aug 25 '16 at 15:59
  • \$\begingroup\$ After one time period (0.3s), the input should go to 0 for the next 0.5s. After that it should resume for one time period (0.3s). And reduce to 0 again. And so on. @laptop2d \$\endgroup\$ – Rachit Ajitsaria Aug 28 '16 at 9:44
  • \$\begingroup\$ If you zero out the \$ sin^2\$ wave out for 0.5 seconds , it will cut out more than one of the \$ sin^2\$ periods \$\endgroup\$ – Voltage Spike Aug 29 '16 at 15:25

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');
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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.