clear;clc;clf;warning off all;close all;format long
fm=1;fc=100;fs=4*fc;Ac = 1; Am = 0.5;
t=0:1/fs:4;
mt = Am*sin(2*pi*fm*t);
ct = Ac*sin(2*pi*fc*t);
y_full_am = (1+mt).*ct;
y_DSBSC_am = mt.*ct;
figure(1)
subplot(2,1,1)
plot(t,mt)
xlabel('t in seconds')
ylabel('amplitude')
title('m(t)')
subplot(2,1,2)
plot(t,ct)
xlabel('t in seconds')
ylabel('amplitude')
title('c(t)')
figure(2)
subplot(2,1,1)
plot(t,y_full_am)
title('Full AM')
xlabel('t in seconds')
ylabel('amplitude')
subplot(2,1,2)
plot(t,y_DSBSC_am)
xlabel('t in seconds')
ylabel('amplitude')
title('DSBSC')
Fspec_AM = fft(y_DSBSC_am);
% Fspec_AM = fft(y_DSBSC_am);
L=length(t);
f = fs*(0:(L))/L;
figure(3)
plot(f(2:end),Fspec_AM)
axis([90 110 0 500])
xlabel('f in Hertz')
ylabel('amplitude')
title('Frequency spectrum of AM')


%section for FM

mti = -Am*cos(2*pi*fm*t)./(2*pi*fm);
kf=125;
Y_fm = Ac*sin(2*pi*fc*t+2*pi*kf*mti);
figure(4)
subplot(2,1,1)
plot(t,mt)
subplot(2,1,2)
plot(t,Y_fm)
xlabel('t in seconds')
ylabel('amplitude')
title('FM')

t1=0:1/fs:3*pi;syms x;
mts = 2*floor(x)-floor(2*x)+1;
figure(5)
subplot(2,1,1)
kp=12;
% ezplot(mts)
mtsit = [];%mtsi = int(mts,0,t1(1));mtsit=[mtsit mtsi];
for i=1:length(t1)
    t1i=t1(i);
mtsi = int(mts,0,t1i);
mtsit=[mtsit mtsi];
end
subplot(2,1,1)
ezplot(mts)
xlabel('t in seconds')
ylabel('amplitude')
title('Message')
kf = 125;
Y_fms = Ac*sin(2*pi*25*t1+2*pi*kf*mtsit);
subplot(2,1,2)
plot(t1,Y_fms)
xlabel('t in seconds')
ylabel('amplitude')
title('FM')

Fspec_FM = fft(Y_fm);
% Fspec_AM = fft(y_DSBSC_am);
L=length(t);
f1 = fs*(0:(L))/L;
figure(6)
plot(f1(2:end),Fspec_FM)
xlabel('f in Hertz')
ylabel('amplitude')
title('Frequency spectrum of FM')


%section for PM
t1=0:1/fs:3*pi;
mts = square(t1);
figure(7)
subplot(2,1,1)
kp=12;
% mtsi = integral(mts,0,max(t1));
plot(t1,mts)
Y_pms = Ac*sin(2*pi*10*t1+kp*mts);
subplot(2,1,2)
plot(t1,Y_pms)
xlabel('t in seconds')
ylabel('amplitude')
title('PM')

Fspec_PM = fft(Y_pms);
% Fspec_AM = fft(y_DSBSC_am);
L=length(t1);
f1 = fs*(0:(L))/L;
figure(8)
plot(f1(2:end),Fspec_PM)
xlabel('f in Hertz')
ylabel('amplitude')
title('Frequency spectrum of PM')
axis([0 23 0 800])