Aim:
To generate a BFSK signal in the AWGN environment.

Program:
clc;
clear all;
close all;
f=200;
t=0:10^-4:10/f;
sig1=sin(2*pi*f*t);
subplot(331);
plot(t,sig1);
xlabel('time');
ylabel('amplitude');
title('input sinusoidal signal');
fs=3000;
ts=1/fs;
t2=0:ts:10/f;
sig2=sin(2*pi*f*t2);
subplot(332);
stem(t2,sig2);
xlabel('time');
title('sampled signal');
vh=max(sig2);
vl=min(sig2);
n=4;
m=2^n;
s=(vh-vl)/m;
partition=[vl+s:s:vh-s];
codebook=[vl+s/2:s:vh-s/2];
[index,quantized_sig2] = quantiz(sig2,partition,codebook);
subplot(333);
stem(t2,quantized_sig2);
xlabel('time');
ylabel('amplitude');
title('quantized signal');
codedsig2=de2bi(index,'left-msb');
codedsig2=codedsig2';
txbits=codedsig2(:);
tt=[0:n*length(t2)-1];
figure
subplot(3,1,1);
stairs(tt,txbits);
axis([0 30 -2 3]);
xlabel('time');
ylabel('amplitude');
title('PCM waveform');
bp=.000001;
br=1/bp;
f1=br*8;

f2=br*2;
t1=bp/99:bp/99:bp;
ss=length(t1)
A=5;
pi=3.14;
m=[];
i=1;
for (i=1:1:length(txbits))
if (txbits(i)==1)
y=A*cos(2*pi*f1*t1);
else
y=A*cos(2*pi*f2*t1);
end
m=[m y];
end
subplot(3,1,2);
plot(m);
M=length(m);
disp(M);
axis([0 3000 -8 8])
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y1=cos(2*pi*f1*t);
y2=cos(2*pi*f2*t);
m1=y1.*m((n-(ss-1)):n);
m2=y2.*m((n-(ss-1)):n);
z1=trapz(t1,m1)
z2=trapz(t1,m2)
zz1=round(2*z1/bp)
zz2= round(2*z2/bp)
if(zz1>A/2)
a=1;
else(zz2>A/2)
a=0;
end
mn=[mn a];
end
disp(mn);
bit=[];
for n=1:length(mn)
if mn(n)==1
se=ones(1,100);
else mn(n)==0
se=zeros(1,100);
end
bit=[bit se];
end
subplot(3,1,3)
plot(bit);
axis([ 0 3000 -1 2]);

Algorithm:
1.Generate the sinusoidal expression with frequency(f) to 200/300/400/500/600 Hz
and time(t) from 0 to 5/f, 10/f, 15/f, 20/f, 25/f in an interval of sec.
2.Generate the expression for samples with time(t) from 0 to 5/f, 10/f, 15/f, 20/f,
25/f in an interval of the sampling frequency of 2500/3500/4500/5500/6500 Hz
3.Determine maximum and minimum of the sampled signal
4.Determine the N value for N-bit uniform quantizer and also step size S
5.Determine the no. of intervals, possibly M-1 (M=2N)
6.Determine the no. of entries in each interval, possibly M
7.Codebook Length M, one entry for each interval
8. Perform the quantization process of the sampled signal, determine the
quantization levels and quantized values
9. Plot the quantized values
10. Convert the quantization levels from decimal to binary and transpose it
11. Determine the time duration for PCM encoded signal possibly from 0 to N*(length
of a sampled interval)- 1
12. Plot the PCM encoded signal using the stairs command
13. If the encoded bits is 0, then multiplied with frequency component f1 and
transmitted bits is 1, then multiplied with frequency component f2.
14. The FSK modulated signal is transmitted through the fading channel.
15. The faded signal will be received and undergo coherent demodulation
16. The approximation of the integral of Y via the trapezoidal method is executed
17. The integral value if greater than the threshold value, then the received bit is 1, the
integral value is less than the threshold, then the received bit is zero
18. After the decision, the detected bits are made to zeroes and ones for a particular bit
duration.