Matlab Code
Matlab Code
clc;
clear all;
close all;
Ac=2; %carrier amplitude
fc=0.5; %carrier frequency
Am=.5; %message signal amplitude
fm=.05; %message signal frequency
Fs=100; %sampling rate/frequency
ka=1; %modulation coefficient
t=[0:0.1:50]; %defining the time range & disseminating it into samples
ct=Ac*cos(2*pi*fc*t); %defining the carrier signal wave
mt=Am*cos(2*pi*fm*t); %defining the message signal
AM=ct.*(1+ka*mt); %Amplitude Modulated wave, according to the standard definition
subplot(3,1,1); %plotting the message signal wave
plot(mt);
ylabel('Message signal');
subplot(3,1,2); %plotting the carrier signal wave
plot(ct);
ylabel('carrier');
subplot(3,1,3); %plotting the amplitude modulated wave
plot(AM);
ylabel('AM signal');
all
close
all
0:0.001:1; %upto
1000
samples
vm
input('Enter
Amplitude
(Message)
');
vc
input('Enter
Amplitude
(Carrier)
');
fM
input('Enter
Message
frequency
');
fc
input('Enter
Carrier
frequency
');
input('Enter
Modulation
Index
');
msg
vm*sin(2*pi*fM*t);
subplot(3,1,1); %plotting
message
signal
plot(t,msg);
xlabel('Time');
ylabel('Amplitude');
title('Message
carrier
subplot(3,1,2); %plotting
');
=
vc*sin(2*pi*fc*t);
carrier
signal
plot(t,carrier);
xlabel('Time');
ylabel('Amplitude');
title('Carrier
Signal');
vc*sin(2*pi*fc*t+m.*cos(2*pi*fM*t));
FM
subplot(3,1,3);%plotting
(Frequency
Modulated)
signal
plot(t,y);
xlabel('Time');
ylabel('Amplitude');
title('FM Signal');
Amplitude
(Message)
Enter
Amplitude
(Carrier)
Enter
Message
frequency
Enter
Carrier
frequency
100
clc;
close
all;
clear
all;
input('Enter
the
amplitude
');
input('Enter
the
frequency
');
0:0.02:2; %
for
total
x1
stem(t); %generation
x2
sin(2*pi*f*t); %generation
of
of
20
impulse
of
sine
x1.*x2; %modulation
subplot(3,1,1); %for
impulse
samples
signal
wave
step
signal
plot
stem(x1);
title('Impulse
Signal');
xlabel('Time');
ylabel('Amplitude
');
subplot(3,1,2)
%for
sine
wave
plot
plot(t,x2);
title('Sine
Wave');
xlabel('Time
');
ylabel('Amplitude
');
subplot(3,1,3)
%for
PAM
wave
plot
stem(t,y);
title('PAM
Wave');
xlabel('Time');
ylabel('Amplitude');
Sample Input At MATLAB Command Window:
Enter
the
amplitude
clearing
close
all %for
closing
clear
all %for
deleting
fc=input('Enter
the
fp=input('Enter
the
amp=input('Enter
the
the
all
the
all
of
amplitude
window
the
freq
freq
command
variables
of
Periodic
(For
except
Carrier
window
command
from
Sine
Wave
Binary
pulse
&
Binary
Pulse
the
window
memory
carrier:');
(Message):');
Message):');
t=0:0.001:1; %
For
setting
c=amp.*sin(2*pi*fc*t);%
For
subplot(3,1,1) %For
Plotting
the
sampling
Generating
Carrier
The
interval
Sine
wave
Carrier
wave
plot(t,c)
xlabel('Time')
ylabel('Amplitude')
title('Carrier
Wave')
m=amp/2.*square(2*pi*fp*t)+(amp/2);%For
subplot(3,1,2) %For
Plotting
The
Generating
Square
Square
Binary
wave
Pulse
message
(Message)
plot(t,m)
xlabel('Time')
ylabel('Amplitude')
title('Binary
Message
w=c.*m; %
The
subplot(3,1,3) %For
Pulses')
Shift
Plotting
The
Keyed
Amplitude
Shift
Wave
Keyed
Wave
plot(t,w)
xlabel('Time')
ylabel('Amplitude')
title('Amplitide Shift Keyed Signal')
INPUTS GIVEN TO GENERATE ASK MODULATED WAVE:
Enter
Enter
the
the
freq
freq
of
of
Periodic
Sine
Binary
Enter the amplitude (For Both Carrier & Binary Pulse Message):4
RESULT:
Wave
carrier:100
pulse
(Message):10
MATLAB Code FOR FSK (Frequency Shift Keying) BFSK in this case:
clc %for clearing the command window
close all %for closing all the window except command window
clear all %for deleting all the variables from the memory
fc1=input('Enter the freq of 1st Sine Wave carrier:');
fc2=input('Enter the freq of 2nd Sine Wave carrier:');
fp=input('Enter the freq of Periodic Binary pulse (Message):');
amp=input('Enter the amplitude (For Both Carrier & Binary Pulse Message):');
amp=amp/2;
t=0:0.001:1; % For setting the sampling interval
c1=amp.*sin(2*pi*fc1*t);% For Generating 1st Carrier Sine wave
c2=amp.*sin(2*pi*fc2*t);% For Generating 2nd Carrier Sine wave
subplot(4,1,1); %For Plotting The Carrier wave
plot(t,c1)
xlabel('Time')
ylabel('Amplitude')
title('Carrier 1 Wave')
subplot(4,1,2) %For Plotting The Carrier wave
plot(t,c2)
xlabel('Time')
ylabel('Amplitude')
title('Carrier 2 Wave')
m=amp.*square(2*pi*fp*t)+amp;%For Generating Square wave message
subplot(4,1,3) %For Plotting The Square Binary Pulse (Message)
plot(t,m)
xlabel('Time')
ylabel('Amplitude')
title('Binary Message Pulses')
for i=0:1000 %here we are generating the modulated wave
if m(i+1)==0
mm(i+1)=c2(i+1);
else
mm(i+1)=c1(i+1);
end
end
subplot(4,1,4) %For Plotting The Modulated wave
plot(t,mm)
xlabel('Time')
ylabel('Amplitude')
title('Modulated Wave')
The following INPUTS GIVEN TO GENERATE FSK MODULATED WAVE:
Enter the freq of 1st Sine Wave carrier:10
Enter the freq of 2nd Sine Wave carrier:30
Enter the freq of Periodic Binary pulse (Message):5
Enter the amplitude (For Both Carrier & Binary Pulse Message):4
Result:
clearing
the
close
all %for
closing
all
clear
all %for
deleting
all
t=0:.001:1; %
For
fc=input('Enter
frequency
fm=input('Enter
amp=input('Enter
the
of
&
except
variables
setting
the
Carrier
window
command
from
Plotting
wave:
:
Both
Carrier
The
window
memory
interval
Sine
Amplitude(Assuming
Generating
the
sampling
frequency
Message
c=amp.*sin(2*pi*fc*t);%
subplot(3,1,1) %For
window
the
Message
Carrier
command
Carrier
');
');
Equal):');
Sine
wave
plot(t,c)
xlabel('Time')
ylabel('Amplitude')
title('Carrier')
m=square(2*pi*fm*t);%
For
Plotting
Message
signal
subplot(3,1,2)
plot(t,m)
xlabel('time')
ylabel('ampmplitude')
title('Message Signal')% Sine wave multiplied with square wave in order to
generate
PSK
x=c.*m;
subplot(3,1,3) %
For
Plotting
PSK
(Phase
Shift
Keyed)
signal
plot(t,x)
xlabel('t')
ylabel('y')
title('PSK')
frequency
Message
of
Carrier
frequency
Sine
wave:
:
60
10