16 Nov 2010

Quadrature Phase Shift Keying

Quadrature Phase Shift Keying


clc;clear all;close all;


% Getting Input binary bits and frequency

g=[1 0 1 1 0 0 0 1];

f=10;;


t=0:2*pi/99:2*pi;

binary=[];

carrier1=[];carrier2=[];

mult=[];

c=cos(f*t);s=sin(f*t);


% QPSK algorithm

for n=1:2:length(g)

if g(n)==0 && g(n+1)==1

x=[zeros(1,50) ones(1,50)];

y=ones(1,100);

end

if g(n)==0 && g(n+1)==0

x=[zeros(1,50) zeros(1,50)];

y=-ones(1,100);

end

if g(n)==1 && g(n+1)==0

x=[ones(1,50) zeros(1,50)];

y=-ones(1,100);

end

if g(n)==1 && g(n+1)==1

x=[ones(1,50) ones(1,50)];

y=ones(1,100);

end

mult=[mult y];

carrier1=[carrier1 c];

carrier2=[carrier2 s];

binary=[binary x];

end


bpsk=mult.*carrier1+mult.*carrier2;


% Plotting

subplot(211);plot(binary);grid on;

title('Input Binary Signal');

axis([0 50*length(g) -1.5 1.5]);

subplot(2,1,2);plot(bpsk);grid on;

title('QPSK Modulated Signal');

axis([0 50*length(g) -1.5 1.5]);


% Calculation of BER

N=10^5;

Es_No_db=[-3:20];

iphat=zeros(1,N);

for ii=1:length(Es_No_db)

ip=(2*(rand(1,N)>0.5)-1)+j*(2*(rand(1,N)>0.5)-1);

s=(1/sqrt(2))*ip;

n=1/sqrt(2)*[randn(1,N)+j*randn(1,N)];

y=s+10^(-Es_No_db(ii)/20)*n;

y_re=real(y);

y_im=imag(y);

iphat(find(y_re<0&y_im<0))=-1+-1*j;

iphat(find(y_re>=0&y_im>0))=1+1*j;

iphat(find(y_re<0&y_im>=0))=-1+1*j;

iphat(find(y_re>=0&y_im<0))=1-1*j;

nerr(ii)=size(find([ip-iphat]),2);

end

simser_qpsk=nerr/N;

theoryser_qpsk=erfc(sqrt(0.5*(10.^(Es_No_db/10))))-(1/4)*(erfc(sqrt(0.5*(10.^(Es_No_db/10))))).^2;

figure

semilogy(Es_No_db,theoryser_qpsk,'b.-');hold on;

semilogy(Es_No_db,simser_qpsk,'mx-');

axis([-3 15 10^-5 1]);grid on;

legend('theory','sim');

xlabel('Es/No,db');ylabel('Symbol Error rate');

title('Symbol Error Probability for QPSK');

No comments: