close all; clear all;

% Time
t = [0:1e-5:5]*1e-3;
% Message
m = [0 0 1 1 0 0]*40; tm = [0 0.5 2 3 4.5 5]*1e-3; 
m = interp1(tm,m,t); % connecting the dots
% Carrier Frequency
fc = 0.7e4;

n = 5; % number of plots to show

% message plot
subplot(n,1,1)
plot(t,m)
ylabel('m(t)'); xlabel('t');

% carrier plot
phi = 0;
subplot(n,1,2)
c = cos(2*pi*fc*t + phi);
plot(t,c)
ylabel('cos(2 \pi f_c t)'); xlabel('t');

% AM plot
subplot(n,1,3)
A = 10;
xAM = (A+m).*cos(2*pi*fc*t + phi);
plot(t,xAM,'r')
hold on
plot(t,A+m,'b--')
ylabel('x_{AM}(t)'); xlabel('t');

% PM plot
subplot(n,1,5)
A = 1; kp = 1;
xPM = A*cos(2*pi*fc*t + phi + kp*m);
plot(t,xPM,'r')
ylabel('x_{PM}(t)'); xlabel('t');

% FM plot
subplot(n,1,4)
A = 1; kf = 250;
dt=t(2)-t(1);
intm = cumsum(m)*dt;
xFM = A*cos(2*pi*fc*t + phi + 2*pi*kf*intm);
plot(t,xFM,'r')
ylabel('x_{FM}(t)'); xlabel('t');


