2
$\begingroup$

I was trying to generate a signal like this: enter image description here

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?

$\endgroup$
  • 1
    $\begingroup$ In general, I would recommend that you label your axes (in any diagram) because it is not immediately obvious what is depicted (I thought it was something like a signal flow graph but it turned out to be plain simple time domain, i.e. (time, amplitude) kind of thing). Also, the way this question is posed, makes it off topic for DSP.SE because it requests MATLAB code explicitly. If you think you would be benefited from more general responses about the generation of signals with the depicted waveform then please re-phrase the question. $\endgroup$ – A_A Jan 31 '18 at 23:09
4
$\begingroup$

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;

enter image description here

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):

enter image description here

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;

enter image description here

$\endgroup$

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.