4-PSK Code: All All
4-PSK Code: All All
CODE:
clc
clear all
close all
a_db=2;
for k=1:10
total_bits=10; % total no of bits for simulation
display(' Binary information at Transmitter :');
b=(randn(1,total_bits)>0.5); %data generator to generate bits
disp(b);
u1=b(1:2:end); %split data into two data streams
u2=b(2:2:end);
c=cat(2,u1',u2'); %concatenate data into total_bits/2 rows and 2 columns
bp=0.000001;
A=5; % Amplitude of carrier signal
br=1/bp; % bit rate
f=br*2; % carrier frequency
t=bp/99:bp/99:bp;
s=[];
for i=1:total_bits/2 %modulate 1s and 0s into qpsk
if(c(i,:)==[1 0])
y=A*cos(2*pi*f*t+(pi/4));
elseif(c(i,:)==[0 0])
y=A*cos(2*pi*f*t+((3*pi)/4));
elseif(c(i,:)==[0 1])
y=A*cos(2*pi*f*t+((5*pi)/4));
else
y=A*cos(2*pi*f*t+((7*pi)/4));
end
s=[s y];
end
a=10^(a_db/10); % convert it into linear
n=(randn(1,length(s))+j*randn(1,length(s)))/sqrt(2*a); %noise
r = awgn(m,10);
r=s+n; %received signal
b1=cos(2*pi*f*t); % basis functions
b2=sin(2*pi*f*t);
d=[];
ss=length(t);
for n=ss:ss:length(s)
m1=b1.*s((n-(ss-1)):n);
m2=b2.*s((n-(ss-1)):n);
z1=trapz(t,m1); % integration
z2=trapz(t,m2);
if(z1>0 & z2>0)
a=[1 1];
elseif (z1>0 & z2<0)
a=[1 0];
elseif (z1<0 & z2>0)
a=[0 1];
else
a=[0 0];
end
d=[d a];
end
disp(' Binary information at Receiver :');
disp(d);
ber=sum(d~=b)/total_bits; % Count error and BER calculation
a_db=a_db+2; % increase the linear no to vary noise power
end