% Create an array of 1000 time instants, in steps of 0.001 s.
time=[0:999]*0.001;
% Create a carrier signal at frequency f
f=12; % Hz 
carrier=sin(2*pi*f*time);
% Create a modulating signal at frequency g
g=2; % Hz 
modulation=1+sin(2*pi*g*time);
% Modulation depth
m=1; % 100% modulation
% Multiply the modulating signal by the carrier
signal=m*modulation.*carrier;
% Plot the carrier
subplot(2,1,1);
plot(time,carrier);
hold on;
% Plot the modulating signal
plot(time,modulation,'-.r');
% Annotations
title('Carrier and Modulating Signal (--)');
ylabel('Amplitude (V)');
grid on;
% Plot the AM signal
subplot(2,1,2);
plot(time,signal);
hold on;
% Plot the envelope
plot(time,modulation,':b');
% Annotationse
title('AM Signal and Envelope (:)');
xlabel('Time (s)');
ylabel('Amplitude (V)');
grid on;