Matlab program for Quadrature amplitude modulation.
Matlab code
clc;clear all;close all;
A1=.5; %Amplitude of Carrier Wave when MSB bit = 0
fc=input('Enter the frequency of carrier wave (fc) = ');
n=input('Enter the no of bit (Multiples of 3) = ');
r=input('Enter the Bite Rate (In bits/sec) = ');
tpb=1/r; %Time duration for per bit
x=rand(1,n); x
fori=1:length(x)
ifx(i)>=0.5
B(i)=1;
else
B(i)=0;
end;
end;
B
t1=0; %Temporary variable for time
st1=[]; %Variable for store time of bit stream
st2=[]; %Variable for store time of qam wave
Sbs=[]; %Variable for store Bit stream
Sqam=[]; %Variable for store qam signal
for i=1:length(B)
ifB(i)==0 % When bit is 0 --
t=t1:0.001:t1+tpb; % for time duration tpb behaviour of--
Bs=zeros(1,length(t));% Bit stream and--
else
t=t1:0.001:t1+tpb;
Bs=ones(1,length(t));
end;
st1=[st1 t]; % storing tpb duration of time
Sbs=[Sbs Bs]; % storing Bit stream in tpb duration
t1=t1+tpb; % initial value of next tpb duration for iteration
end;
t1=0;
for i=1:3:length(B)
ifB(i)==0&&B(i+1)==0&&B(i+2)==0
t=t1:0.001:t1+3*tpb;
qam=A1*cos(2*pi*fc*t);
elseif B(i)==0&&B(i+1)==0&&B(i+2)==1
t=t1:0.001:t1+3*tpb;
qam=A1*cos(2*pi*fc*t+pi/2);
elseifB(i)==0&&B(i+1)==1&&B(i+2)==1
t=t1:0.001:t1+3*tpb;
qam=A1*cos(2*pi*fc*t+pi);
elseifB(i)==0&&B(i+1)==1&&B(i+2)==0
t=t1:0.001:t1+3*tpb;
qam=A1*cos(2*pi*fc*t+3*pi/2);
elseifB(i)==1&&B(i+1)==0&&B(i+2)==0
t=t1:0.001:t1+3*tpb;
qam=A2*cos(2*pi*fc*t);
elseifB(i)==1&&B(i+1)==0&&B(i+2)==1
t=t1:0.001:t1+3*tpb;
qam=A2*cos(2*pi*fc*t+pi/2);
elseifB(i)==1&&B(i+1)==1&&B(i+2)==1
t=t1:0.001:t1+3*tpb;
qam=A2*cos(2*pi*fc*t+pi);
elseifB(i)==1&&B(i+1)==1&&B(i+2)==0
t=t1:0.001:t1+3*tpb;
qam=A2*cos(2*pi*fc*t+3*pi/2);
end;
st2=[st2 t]; % storing tpb duration of time
Sqam=[Sqam qam]; % storing qpsk signal in tpb duration
t1=t1+3*tpb; % initial value of next tpb duration for iteration
end;
Sc1=A1*cos(2*pi*fc*st2); %Carrier wave for MSB = 0
Sc2=A2*cos(2*pi*fc*st2); %Carrier wave for MSB = 1
subplot(5,1,1);
plot(st1,Sbs);
axis([0 tpb*n -2 2])
xlabel('Time');ylabel('Amplitude');title('Bit stream');
subplot(5,1,2);
plot(st2,Sc1);
axis([0 tpb*n -1 1]);
xlabel('Time');ylabel('Amplitude');title('Carrier wave for MSB=0');
subplot(5,1,3);
plot(st2,Sc2);
xlabel('Time');ylabel('Amplitude');title('Carrier wave for MSB=1');
subplot(5,1,4);
plot(st2,Sqam);
xlabel('Time');ylabel('Amplitude');title('QAM Signal');
subplot(5,1,5);
plot(st1,Sbs,'r');
axis([0 tpb*n -2 2]);
j=0;
for i=1:length(B)
ifB(i)==0 % When bit is 0
text(j+.5,.5,'0') % Display text '0' on figure
else % When bit is 1
text(j+.5,.5,'1') % or Display text '1' on figure
end;
j=j+1;
end;
hold on;
plot(st2,Sqam);
xlabel('Time');ylabel('Amplitude');title('Bit stream and QAM Signal');
h=legend('Bit stream','QAM Signal');
Command window
Enter the frequency of carrier wave (fc) = 2
Enter the no of bit (Multiples of 3) = 12
Enter the Bite Rate (In bits/sec) = 1
x =
Columns 1 through 10
0.5752 0.0598 0.2348 0.3532 0.8212 0.0154 0.0430 0.1690 0.6491 0.7317
Columns 11 through 12
0.6477 0.4509
B =
1 0 0 0 1 0 0 0 1 1 1 0
No comments:
Post a Comment