I was trying to generate a signal like this:
I have done this so far like this:
clc;
clear all;
close all;
t = 0:.1:10;
f=.5;
y=.2*sin(2*pi*f*t);
plot(t,abs(y));
axis([0 10 -2 2]);
grid on;
What can I do to get desired output?
I was trying to generate a signal like this:
I have done this so far like this:
clc;
clear all;
close all;
t = 0:.1:10;
f=.5;
y=.2*sin(2*pi*f*t);
plot(t,abs(y));
axis([0 10 -2 2]);
grid on;
What can I do to get desired output?
Well, so far using your code, you are getting the following:
clc;
clear all;
close all;
t = 0:.1:10;
f=.5;
y=.2*sin(2*pi*f*t);
plot(t,abs(y));
axis([0 10 -2 2]);
grid on;
So now, the only missing part is to zero-out all samples using PWM signal with 25% duty cycle. For example, this can be done using the square wave. Its values are between +1 and -1, so simply add 1 and use the signum function (or divide it by 2):
Putting all that together:
clc;
clear all;
close all;
t = 0:.1:10;
f=.5;
y=.2*sin(2*pi*f*t);
s=sign(square(t/2*pi, 25)+1);
x=y.*s;
plot(t,x);
axis([0 10 -2 2]);
grid on;