clc
clear

%==========================================================================
%==========================================================================

%Carrier Signal
CarrierAmplitude=5;
	CarrierHz=100;
CarrierFrequency=2*pi*CarrierHz;
	CarrierSamplingRate=300;
	CarrierDuration=2;
CarrierTime=0:1/CarrierSamplingRate:CarrierDuration;

%===========================================================================
%===========================================================================

%Modulator Signal
ModulatorAmplitude=2.5;
	ModulatorHz=5;
ModulatorFrequency=2*pi*ModulatorHz;
	ModulatorSamplingRate=300;
	ModulatorDuration=2;
ModulatorTime=0:1/ModulatorSamplingRate:ModulatorDuration;

%============================================================================
%============================================================================

%The Carrier Signal
for i=1:length(CarrierTime)
   
	CarrierSignal(i)=CarrierAmplitude*(sin(CarrierFrequency*CarrierTime(i)));
   
end

%============================================================================
%============================================================================

%The Modulator Signal
for i=1:length(ModulatorTime)
   
	ModulatorSignal(i)=ModulatorAmplitude*(sin(ModulatorFrequency*ModulatorTime(i)));
   
end

%============================================================================
%============================================================================

%The Modulated Signal
ModulatedSignal=CarrierSignal .* ModulatorSignal;

%============================================================================
%============================================================================

%The Left Envelope
for i=1:length(ModulatorTime)
   
	LeftEnvelope(i)=ModulatorAmplitude*(sin(ModulatorFrequency*ModulatorTime(i)));
   if LeftEnvelope(i)<0
      LeftEnvelope(i)=-LeftEnvelope(i);
   end
   
end

%============================================================================
%============================================================================

%The Right Envelope
for i=1:length(ModulatorTime)
   
	RightEnvelope(i)=ModulatorAmplitude*(sin(-ModulatorFrequency*ModulatorTime(i)));
   if RightEnvelope(i)>0
      RightEnvelope(i)=-RightEnvelope(i);
   end
   
end

%=============================================================================
%=============================================================================

%The Left SideBand
LeftAmplitude=5;
LeftHz=95;
LeftFrequency=2*pi*LeftHz;
LeftSamplingRate=300;
LeftDuration=2;
LeftTime=0:1/LeftSamplingRate:LeftDuration;

%The Left SideBand
for i=1:length(LeftTime)
   
	LeftSideBand(i)=LeftAmplitude*(sin(LeftFrequency*LeftTime(i)));
   
end

%====================================================================
%====================================================================

%The Right SideBand 
RightAmplitude=5;
RightHz=105;
RightFrequency=2*pi*RightHz;
RightSamplingRate=300;
RightDuration=2;
RightTime=0:1/RightSamplingRate:RightDuration;

%The Right SideBand 
for i=1:length(RightTime)
   
   RightSideBand(i)=RightAmplitude*(sin(RightFrequency*RightTime(i)));
      
end

%=============================================================================
%=============================================================================
%==============================  Display =====================================

%The Carrier Signal
figure(1);
plot(CarrierTime,CarrierSignal);
title('The Carrier Signal (Frequency = 100Hz)');
grid on

%The Modulator Signal
figure(2);
plot(ModulatorTime,ModulatorSignal);
title('The Modulator Signal (Frequency = 5Hz)');
grid on

%The Carrier and the Two SideBands
figure(3);
subplot(4,1,1),plot(ModulatorTime,LeftEnvelope);
ylabel('The Left Envelope');
grid on
subplot(4,1,2),plot(CarrierTime,CarrierSignal);
ylabel('The Carrier');
grid on
subplot(4,1,3),plot(ModulatorTime,RightEnvelope);
ylabel('The Right Envelope');
grid on
subplot(4,1,4),plot(ModulatorTime,ModulatedSignal);
xlabel('The Modulated Signal');
grid on

%The Left and Right SideBands
figure(4);
subplot(2,1,1),plot(LeftTime,LeftSideBand);
title('The Left SideBand');
grid on
subplot(2,1,2),plot(RightTime,RightSideBand);
title('The Right SideBand');
grid on

%The Dispersed Signal and the Frequency Spectrums
figure(5);
ModulatedFreqTime=0:LeftSamplingRate/(length(ModulatedSignal)-1):LeftSamplingRate;
plot(ModulatedFreqTime,abs(fft(ModulatedSignal,length(ModulatedSignal)))./length(ModulatedSignal),'r');
ylabel('Modulated');
grid on
