%msk.m
bindata=[1 1 0 0 1 0 0 1 0 0 1];
basis1coef=[1 -1 1 1 1 -1]*sqrt(Eb);
basis2coef=[1 1 1 -1 -1 -1]*sqrt(Eb);
Eb=1/2;
Tb=1;
fc=2;
t1=-1:1/100:1;
phi1=sqrt(2/Tb)*cos(pi*t1/(2*Tb)).*cos(2*pi*fc*t1);
t2=0:1/100:2;
phi2=sqrt(2/Tb)*sin(pi*t2/(2*Tb)).*sin(2*pi*fc*t2);
temp1=[phi1 -1*phi1 phi1 phi1 phi1 -1*phi1 zeros(1,100)]*sqrt(Eb);
temp2=[zeros(1,100) phi2 phi2 phi2 -1*phi2 -s1*phi2 -1*phi2]*sqrt(Eb);
txsignal=temp1+temp2;
figure
subplot(3,1,1)
xval=[-100:1:length(temp1)-101]./100;
plot(xval,temp1)
subplot(3,1,2)
plot(xval,temp2)
subplot(3,1,3)
plot(xval,txsignal)
rxsignal=txsignal+sqrt(4)*randn(1,length(txsignal));
subplot(2,1,1)
plot(txsignal)
title('Typical MSK signal ')
subplot(2,1,2)
plot(rxsignal)
title('MSK signal with additive guassian noise (variance=4) ')
%Correlation receiver for MSK modulation
L1=length(phi1)
OUTPUTCR1=[];
OUTPUTCR2=[];
rxsignal1=rxsignal(1:1:6*201);
rxsignal2=rxsignal(101:1:length(rxsignal));
for i=1:1:6
temp1=rxsignal1((i-1)*L1+1:1:(i-1)*L1+L1);
temp2=rxsignal2((i-1)*L1+1:1:(i-1)*L1+L1);
OUTPUTCR1=[OUTPUTCR1 sum(temp1.*phi1)];
OUTPUTCR2=[OUTPUTCR2 sum(temp2.*phi2)];
end
figure
subplot(2,2,1)
stem(OUTPUTCR1)
title('Output of the correlation receiver 1')
subplot(2,2,2)
stem(OUTPUTCR2)
title('Output of the correlation receiver 2')
subplot(2,2,3)
stem(acos(sign(OUTPUTCR1)))
title('Identified phase using the correlation receiver 1')
subplot(2,2,4)
stem(asin(sign(OUTPUTCR2)))
title('Identified phase using the correlation receiver 2')
%title(’Inverse sine of the sign of the output of the correlation receiver 2’)
deg1=acos(sign(OUTPUTCR1));
deg2=asin(sign(OUTPUTCR2));
SEQ=reshape([deg1;deg2],1,12);
figure
subplot(4,1,1)
stem(SEQ)
title('detected sequence of phase angle in degree')
subplot(4,1,2)
SEQ1=diff(SEQ);
stem(SEQ1)
title('difference between the cosecutive binary stream')
subplot(4,1,3)
stem(bindata*2-1)
title('Transmitted binary sequence')
subplot(4,1,4)
P=sin(SEQ1);
stem(P)
title('Corresponding detected binary sequence');

