%noncoherent.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 ')
%Non-coherent detection using correlators
phase=2*pi*rand;
LO11=sqrt(2/Tb)*cos(2*pi*f1*t+phase);
LO12=sqrt(2/Tb)*sin(2*pi*f1*t+phase);
LO21=sqrt(2/Tb)*cos(2*pi*f2*t+phase);
LO22=sqrt(2/Tb)*sin(2*pi*f2*t+phase);
BINSEQDET=[];
for n=1:1:200
temp=RX([(n-1)*1001+1:1:(n-1)*1001+1001]);
S11=sum(temp.*LO11);
S12=sum(temp.*LO12);
CS1=[CS1 sqrt(S11^2+S12^2)];
S21=sum(temp.*LO21);
S22=sum(temp.*LO22);
CS2=[CS2 sqrt(S21^2+S22^2)];
if(CS1(n)>CS2(n))
BINSEQDET=[BINSEQDET 0];
else
BINSEQDET=[BINSEQDET 1];
end
end
figure
subplot(1,3,1)
stem(CS1)
title('Output of the correlation receiver 1 (Non-coherent detection)')
subplot(1,3,2)
stem(CS2)
title('Output of the correlation receiver 2 (Non-coherent detection)')
subplot(1,3,3)
scatter(CS1,CS2)
title('Signal-space diagram for the received FSK signal (Non-coherent detection)' );
figure
subplot(2,1,1)
stem(BINSEQ)
title('Transmitted binary sequence')
subplot(2,1,2)
stem(BINSEQDET,'r')
title('Received binary sequence (Non-coherent detection)')
%Non-coherent detection using matched filter and envelopedetector
%Impulse response of the matched filter
ED1=[];
ED2=[];
h1=sqrt(2/Tb)*cos(2*pi*f1*t+phase);
h1=h1(end:-1:1);
h2=sqrt(2/Tb)*cos(2*pi*f2*t+phase);
h2=h2(end:-1:1);
BINSEQDET=[];
for n=1:1:200
temp=RX([(n-1)*1001+1:1:(n-1)*1001+1001]);
S1=conv(temp,h1);
ED1=[ED1 abs(S1(1001))];
S2=conv(temp,h2);
ED2=[ED2 abs(S2(1001))];
if(ED1(n)>ED2(n))
BINSEQDET=[BINSEQDET 0];
else
BINSEQDET=[BINSEQDET 1];
end
end
figure
subplot(1,3,1)
stem(ED1)
title('Output of the sampled version of the Envelope detector (ED) 1')
subplot(1,3,2)
stem(ED2)
title('Output of the sampled version of the ED 2')
subplot(1,3,3)
scatter(CS1,CS2)
title('Signal-space diagram for the FSK signal(Non-coherent detection using ED)');
figure
subplot(2,1,1)
stem(BINSEQ)
title('Transmitted binary sequence')
subplot(2,1,2)
stem(BINSEQDET,'r')
title('Received binary sequence (Non-coherent detection using ED')


