Amplitude Shift Keying
clc;clear all;close all;
% Getting Input binary bits and frequency
g=[1 0 0 1 1 0];
f=10;
t=0:2*pi/99:2*pi;
binary=[];carrier=[];
c=sin(f*t);
% ASK algorithm
for n=1:length(g)
if g(n)==0
x=zeros(1,100);
else g(n)==1
x=2*ones(1,100);
end
binary=[binary x];
carrier=[carrier c];
end
ask=binary.*carrier;
% Plotting
subplot(211);plot(binary);grid on;
title('Input Binary Signal');
axis([0 100*length(g) -2.5 2.5]);
subplot(2,1,2);plot(ask);grid on;
title('ASK Modulated Signal');
axis([0 100*length(g) -2.5 2.5]);
% Calculation of BER
N=10^6;
rand('state',100);
randn('state',200);
ip=rand(1,N)>0.5;
s=2*ip-1;
n=1/sqrt(2)*[randn(1,N)+j*randn(1,N)];
Eb_No_db=[-3:10];
for ii=1:length(Eb_No_db)
y=s+10^(-Eb_No_db(ii)/20)*n;
iphat=real(y)>0;
nerr(ii)=size(find([ip-iphat]),2);
end
simber=nerr/N;
theoryber=0.5*exp(-0.5*10.^(Eb_No_db/10));
figure
semilogy(Eb_No_db,theoryber,'b.-');
hold on;
semilogy(Eb_No_db,simber,'mx-');
axis([-3 10 10^-5 0.5]);grid on;
legend('Theory','Sim');
xlabel('Eb/No,db');ylabel('Bit Error Rate');
title('Bit error probability curve for ASK');
No comments:
Post a Comment