Mostrando entradas con la etiqueta matlab. Mostrar todas las entradas
Mostrando entradas con la etiqueta matlab. Mostrar todas las entradas

Matlab script 16QAM simulation

2 comentarios

Matlab script to simulate a 16QAM modulation and demodulation, adding channel fading (path loss) and white Gaussian noise.

%---------------------------------------------------------------%
%                                                               %
%             16-QAM Modulation/Demodulation Script             %
%             -------------------------------------             %
%                                                               %
%      Guillermo Moraleda (guille.moraleda@gmail.com)           %
%      Xavier González                                          %
%                                                               %
%                                                               %
%          2010. Universidad Pompeu Fabra. DIT                  %
%                                                               %
%---------------------------------------------------------------%


clear
close all

N=160000;   %Number of bits to send. Must be multiple of 4
b=rand(1,N)>0.5; %Vector of N-random bits


%-----------------------%
%      MODULATION       %
%-----------------------%

b1=reshape(b,4,N/4);


%To decimal numbers
b2=8*b1(1,:)+4*b1(2,:)+2*b1(3,:)+b1(4,:)+1;

%Mapping of the constellation
A=[-1+3i,-1-3i,1+3i,1-3i,-1+1i,-1-1i,1+1i,1-1i,-3+3i,-3-3i,3+3i,3-3i,-3+1i,-3-1i,3+1i,3-1i];
x=A(b2);


%-----------------------%
%       PATHLOSS        %
%-----------------------%

L=0.02*((1/200)^4);


%-----------------------%
%         NOISE         %
%-----------------------%

K= 1.38e-23;  %Cte Bolzman
T= 300;  %Temp in Kelvin
F= 10;   %Noise figure in dB or W
BW = 1.25e6;  %Bandwidth in Hz 
Ptx = 10; %Power transmitted

N0_teor = K*T*F;  %N0 Analytic
SNR_teor = Ptx / (N0_teor*BW); %SNR Analytic
ES = 4/16*(norm(A(3))^2+
norm(A(11))^2+
norm(A(7))^2+norm(A(15))^2) %Symbol Energy of 16QAM using 1st Q
N0 = ES/SNR_teor  %Noise power 
n = randn(1,N/4)*sqrt(N0) + 
i*(randn(1,N/4)*sqrt(N0)); %Noise vector
variance = var(n)  %Variance of noise vector

y = x*sqrt(L)+n;  %Adding noise and path loss to the signal



%-----------------------%
%      DEMODULATION     %
%-----------------------%

bit1=abs(real(y))>2;
bit2=abs(imag(y))<2;
bit3=real(y)>0;
bit4=imag(y)<0;
z=reshape([bit1;bit2;bit3;bit4],1,N);

z1=reshape(z,4,N/4);
z2=8*z1(1,:)+4*z1(2,:)+2*z1(3,:)+z1(4,:)+1;
z3=A(z2);

%-----------------------%
%          BER         %
%-----------------------%

SNR=10*log(SNR_teor)
Error=abs(b-z);
BitError=sum(Error);
BER=(3/4)*erfc(sqrt((SNR_teor/5)/2))+ (1/2)*erfc(3*sqrt((SNR_teor/5)/2))- (1/4)*erfc(sqrt((SNR_teor*5)/2))


%-----------------------%
%         PLOT          %
%-----------------------%

figure(1)
hold on
plot(x,'b*')
plot(z3,'r+')
axis([-5 5 -5 5])
legend('Modulated Signal','Demodulated Signal');
title('Modulated/Demodulated Signal');

Note: Take care of break lines