# Is my Matlab solution to the below question correct?

I am not experienced at all with Matlab and I just wanted to verify that I am doing this correctly. The question is:

Consider the case of a sinusoidal signal whose amplitude is modulated by a train of pulses:

$$S(t) = \sin(\omega_0 t)P(t)$$ where $$P(t)$$ is a train of pulses with pulsed values of $$0$$ and $$1$$. Lets us set $$\omega_0 = 10^9 \cdot 2\pi \,\texttt{rad/s}$$, and period of $$P(t)=10^{-6} \,\texttt{s}$$ with a duty cycle $$D = 10 \%$$.

Plot $$S(t)$$ as function of $$t$$ for at least $$10 \,\texttt{s}$$

The rest of the assignment deals with plotting spectrums but I need to make sure that the first portion is correct. My solution to this is:

t = linspace(0,10e-6,1000);

x=0.5*(square(2*pi*1000000.*t,10)+1);
% change square wave to go from 0 to 1 vs -1 to 1

Amp = 1;

y = Amp*sin(2*pi*1e9.*t);
%1 GHz signal

S = x.*y;

plot(t,S);

xlabel('time');

ylabel('product wave');

I ended up getting a plot that had no negative samples of the sinusoid.

• Hi Michael, I've edited your question for better formatting. Make sure everything looks right please.
– Jdip
Oct 23, 2023 at 19:39
• It seems that you're trying to plot $10^{10}$ periods of the sine wave -- are you sure you want to do that?
– MBaz
Oct 23, 2023 at 21:11
• Yes, the assignment specifically asks that we plot the product of the sine wave and the PWM signal for 10 microseconds, it just got edited out. Oct 23, 2023 at 21:12
• Also, the sampling frequency in your code is $10^5$. Does that agree with the sampling theorem?
– MBaz
Oct 23, 2023 at 21:12
• 10 microseconds is more reasonable, but still $10^4$ periods...
– MBaz
Oct 23, 2023 at 21:15