Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

C:\Users\Communication Lab PC\Desktop\ASK_Mod_Demod.

m Page 1

clc;
clear;
close all;

% Define binary message signal

Tb=1; % bit duration in secs


N=10; % total number of binary symbols
binary_message=randi([0, 1],1,N);
subplot(5,1,1);
stem(binary_message,"filled","m");
title("binary message signal");
xlabel("time");
ylabel("b(n)");
grid on;
hold on;

% Generate Carrier Signal

fc=10; % carrier frequency


t=0:0.01:Tb; % define time interval and spacing
c=sqrt(2/Tb)*sin(2*pi*fc*t); % Carrier signal
subplot(5,1,3);
plot(t,c);
grid on;
title("carrier signal");
xlabel("time");
ylabel("c(t)");
hold on;

% Converting binary message signal to unipolar message signal


t1=0;
t2=Tb;
for n=1:length(binary_message)
t=t1:.01:t2;
if binary_message(n)==1
digital_message=ones(1,length(t));
else binary_message(n)==0
digital_message=zeros(1,length(t));
end
message(n,:)=digital_message;
subplot(5,1,2);
axis([0 N -2 2]);
plot(t,message(n,:),'r');
grid on
title(" digital message signal");
xlabel("time");
C:\Users\Communication Lab PC\Desktop\ASK_Mod_Demod.m Page 2

ylabel("m(t)");
hold on
% ASK Signal Generation
ask_sig(n,:)=c.*digital_message;
subplot(5,1,4);
plot(t,ask_sig(n,:));
title('ASK signal');
xlabel('time');
ylabel('s(t)');
grid on
hold on
t1=t1+(Tb+.001);
t2=t2+(Tb+.001);
end
hold off

% Coherent ASK Demodulation

for i=1:N
t=t1:Tb/100:t2;
x=sum(c.*ask_sig(i,:));

%decision device
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
end
subplot(5,1,5);
stem(demod,"filled","r");
title('ASK demodulated signal');
xlabel('n');
ylabel('b(n)');
grid on

You might also like