%fsk.m
t=0:1/1000:1;
Eb=2;
Tb=1;
nc=1;
fc=nc/Tb;
f1=fc+(1/Tb);
f2=fc+(2/Tb);
CS1=[];
CS2=[];
TX=[];
BINSEQ=abs(round(rand(1,200)*2-1));
for m=1:1:200
if(BINSEQ(m)==0)
TX=[TX sqrt(2*Eb/Tb)*cos(2*pi*f1*t)];
else
TX=[TX sqrt(2*Eb/Tb)*cos(2*pi*f2*t)];
end
end
%Adding noise to the band pass signal
RX=TX+sqrt(40)*randn(1,length(TX));
figure
subplot(2,1,1)
plot(TX)
title('FSK signal')
subplot(2,1,2)
plot(RX)
title('FSK with noise ')
%Coherent detection
LO1=sqrt(2/Tb)*cos(2*pi*f1*t);
LO2=sqrt(2/Tb)*cos(2*pi*f2*t);
BINSEQDET=[];
for n=1:1:200
temp=RX([(n-1)*1001+1:1:(n-1)*1001+1001]);
S1=sum(temp.*LO1);
CS1=[CS1 S1];
S2=sum(temp.*LO2);
CS2=[CS2 S2];
if(S1>S2)
BINSEQDET=[BINSEQDET 0];
else
BINSEQDET=[BINSEQDET 1];
end
end
figure
subplot(1,3,1)
stem(CS1)
title('Output of the correlation receiver 1')
subplot(1,3,2)
stem(CS2)
title('Output of the correlation receiver 2')
subplot(1,3,3)
scatter(CS1,CS2)
title('Signal-space diagram for the FSK signal');
figure
subplot(2,1,1)
stem(BINSEQ)
title('Transmitted binary sequence')
subplot(2,1,2)
stem(BINSEQDET,'r')
title('Received binary sequence')

