You are on page 1of 3

MATLAB CODE:(QPSK-MODULATION)

clc;
clear all;
close all;
data=randi([0,1],1,8);%using this we are genrating the data bits
figure(1)
stem(data,"LineWidth",2);%using this we are plotting data bits to impulses
ylabel("amplitude");
xlabel("n");
title("Randomly genrated input data sequence");
data_NRZ=(data*2)-1;%using this we are performing line coding
s_p_data=reshape(data_NRZ,2,length(data)/2);
br=10.^6;
f=br;
T=1/br;
t=T/99:T/99:T;
y=[];
y_in=[];
y_qd=[];
for (i=1:length(data)/2) In this for loop
y1=s_p_data(1,i)*cos(2*pi*f*t); the data stream divide
y2=s_p_data(2,i)*sin(2*pi*f*t); into two different
y_in=[y_in y1]; vectors i.e; in-phase
and
y_qd=[y_qd y2]; quadrature phase.
y=[y y1+y2];

end
tx_sig=y;
tt=T/99:T/99:(T*length(data)/2);
figure;
subplot(3,1,1);
plot(tt,y_in);
title('wave form for inphase component');
xlabel('time');
ylabel('amp');
subplot(3,1,2);
plot(tt,y_qd);
title('quadrature comp');
xlabel('time');
ylabel('amp');
subplot(3,1,3);
plot(tt,tx_sig);
title('QPSK modulated signal(sum of inphase and quadrature phase
component)');
xlabel('time');
ylabel('amplitude');
MATLAB CODE:(QPSK-DEMODULATION)

Rx_data=[];
Rx_sig=tx_sig; % Received signal
rx_qd_data=[];
for(i=1:1:length(data)/2)
%this is the coherent inphase detector
Z_in=Rx_sig((i-1)*length(t)+1:i*length(t)).*cos(2*pi*f*t);
Z_in_intg=(trapz(t,Z_in))*(2/T);% integration using trapizodial rule
if(Z_in_intg>0) %Here if statement is used as a threshold
controller(Decision maker)
Rx_in_data=1;
else
Rx_in_data=0;
end
%This is the Quadrature coherent dector
Z_qd=Rx_sig((i-1)*length(t)+1:i*length(t)).*sin(2*pi*f*t);
Z_qd_intg=(trapz(t,Z_qd))*(2/T);%integration using trapizodial rule
if (Z_qd_intg>0)% Decision Maker
Rx_qd_data=1;
else
Rx_qd_data=0;
end
Rx_data=[Rx_data Rx_in_data Rx_qd_data]; % Received Data vector
rx_qd_data = [rx_qd_data Rx_qd_data];
end
disp(Rx_data);
disp(length(Rx_data));
disp("data is: "+data(i));
disp("Received data is: "+Rx_data(i));

figure(3)
stem(Rx_data,'linewidth',2)
xlabel("n");
ylabel("amplitude")
title('demodulated output');

You might also like