Vous êtes sur la page 1sur 3

clc

close all

a=[1 2 3 4 5 6 7 8];%sequence
map1=[];
l=length(a);%length of messege sequence
a1=[];
a2=[];
k=4;%[ME (n,k)]
for i=1:l
a1=de2bi(a(i),[k],'left-msb');%decimal to bit conversion
a2=[a2 a1];%concatination
end
x=a2;

%mapping
z = bi2de(reshape(x,k,length(x)/k).','left-msb');
%binary to decimal conversion with left bit as msb
z=z';
%row to coloumn
loop= length(x)/k;%no of iterations
for i=1:loop
if z(i)==0 %maps 0
map(i)=0;
else
n=z(i); %maps any other value other than 0
map(i)= 2^(n-1);
end
end
%concatination of mapped sequence
for i=1:loop
kk = de2bi(map(i),[((2^k)-1)],2,'left-msb');
map1=[map1 kk ];
end

% Enter the two Amplitudes


% Amplitude for 0 bit
A1 = 0;
% Amplitude for 1 bit
A2 = 5;
% Frequency of Modulating Signal
f = 100;
% Sampling rate - This will define the resoultion
fs = 1000;

% Time for one bit


t = 0: 1/fs : 1;
% This time variable is just for plot
time = [];
ASK_signal = [];
Digital_signal = [];
for ii = 1: 1: length(map1)
% The ASK Signal
ASK_signal = [ASK_signal (map1(ii)==0)*A1*sin(2*pi*f*t)+...
(map1(ii)==1)*A2*sin(2*pi*f*t)];
% The Original Digital Signal
Digital_signal = [Digital_signal (map1(ii)==0)*...
zeros(1,length(t)) + (map1(ii)==1)*ones(1,length(t))];
time = [time t];
t = t + 1;
end
% Plot the ASK Signal
subplot(2,1,2);
plot(time,ASK_signal,'LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('ASK Signal with two Amplitudes');
grid on;
% Plot the Original Digital Signal
subplot(2,1,1);
plot(time,Digital_signal,'r','LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('Original Digital Signal');
axis([0 time(end) -0.5 1.5]);
grid on;

noise_signal=awgn(ASK_signal,10)
figure(2);
n_signal=awgn(map1,10);
plot(noise_signal);
tx=map1;
SNR = 0:1:20; % Range of SNR values, in dB.
numSNR = length(SNR);
BER = zeros(1, numSNR);
for n = 1:numSNR
rx= awgn(tx,SNR(n));
k=SNR(n)% Add Gaussian noise
w=max(rx);
for i=1:length(tx)

if rx(i)>.5
rx(i)=1;
else
rx(i)=0;
end
end
h=rx;
% Compute error rate.
[nErrors, BER(n)] = biterr(tx,rx);
end
% Plot BER results.
figure(3)
semilogy(SNR,BER,'r-');grid on;
legend('BER');
xlabel('SNR (dB)'); ylabel('BER');
title('Binary ook over noisey Channel');

Vous aimerez peut-être aussi