hello,
I am getting wrong plot for ber vs snr curve for fsk. My matlab code is as follows:
clc;
close all;
clear all;
no_of_bits=1000;
M=100;
no_of_samples=5000;
threshold = 0.5;
snr=[-3:1:20];
Tb = 1; % Bit duration
fc = 3/Tb; % Carrier frequency
t1=linspace(0, 1, no_of_samples);
f1=cos(2*pi*1000*t1);
f2=cos(2*pi*2000*t1);
n=50; % order of the filter
fsamp=5000; % sampling frequency
fc1=1000;
fc2=2000;
delta=500;
w1=fc1-delta;
w2=fc1+delta;
w3=fc2-delta;
w4=fc2+delta;
w11=w1/fsamp; % Frequency normalization
w22=w2/fsamp;
w33=w3/fsamp;
w44=w4/fsamp;
b1=fir1(n,[w11 w22]); % filter centered at fc1 where w22 is greater than w11
b2=fir1(n,[w33 w44]); % filter centered at fc2 where w33 is greater than w44
for i=1:10
ber(i)=0;
end
for k=1:length(snr)
sn(k)=snr(k)+6;
err(k)=0;
for m=1:M
A = rand(1,no_of_bits); % Generate a random sequence
for i=1:no_of_bits
if (A(i)>=threshold)
A(i)=1;
else
A(i)=0;
end
end
d = A(1:no_of_bits); % Binary sequence
for i=1:no_of_bits
for j = 1:length(d)
if d(j)==1
fskmod=fc1;
else
fskmod=fc2;
end
end
%Receiver side
received=fskmod; % FSK modulated signal
if (b1>b2)
fskdmod=1;
else
fskdmod=0;
end
fskout(i)=fskdmod;
if (d(i)~=fskout(i))
err(k)=err(k)+1;
end
end
d;
fskout;
err(k);
end
ber(k)=err(k)/(no_of_bits*M)
sn(k)
end
% plot
close all
figure
semilogy(sn,ber);
axis([3 26 10^-10 10^0]);
grid on;
xlabel('snr');
ylabel('Bit Error Rate');
title('Bit error probability curve for FSK modulation');
The plot I am getting after running the above program is as follows:
Kindly help me in getting the correct plot.. The correct plot should be as snr increases, ber decreases....