Wireless Networking Assignment-MAH_070115_24846_1_48747

 Solution 1.

Symbol Mapper for 16QAM.

 

a)Sketch the constellation for 16QAM.

 

Or

 

b)

 

Now for dmin

For square signal constellations, where si1 and si2 take values on

,

The minimum distance between signal points reduces to,

c)

The constellation mapping is usually done by Gray encoding, where the messages associated with signal amplitudes that are adjacent to each other differ by one bit value.

With this encoding method, if noise causes the demodulation process to mistake one symbol for an adjacent one (the most likely type of error), this results in only a single bit error in the sequence of Kbits. Gray codes can be designed for square MQAM constellation but not rectangular MQAM.

Hence cannot be applied for the 16 QAM constellations.

Solution 2

a)

Rate of code is

Intuitively, the greater the distance between code words in a given code, the less chance that errors introduced by the channel will cause a transmitted codeword to be decoded as a different codeword. We define the Hamming distance between two code words Ci and Cj, denoted as d(Ci,Cj) or dij, as the number of elements in which they differ:

 

b)

The rate of the code is information bits per codeword symbol. If we assume that codeword symbols are transmitted across the channel at a rate of Rs symbols/second , then the information rate associated with an(n, k) block code is

 Thus we see that block coding reduces the data rate compared to what we obtain with uncoded modulation by the code rate Rc.

 

Solution 3

QPSK modulation consists of BPSK modulation on both the in-phase and quadrature components of the signal. With perfect phase and carrier recovery, the received signal components corresponding to each of these branches are orthogonal. Therefore, the bit error probability on each branch is the same as for BPSK

MATLAB CODE

clear all

N=10^3;

tx_sym=1+j;

M=4;

n=[0:M-1];

p=[0:5:35];

count1=zeros(1,36);

count2=zeros(1,36);

for EbNo_dB=0:5:25

    Gno=1/sqrt(2)*10^(-EbNo_dB/20);

    for   i=1:N

          y=zeros(1,M);

          z1=zeros(1,M);

          noise=(randn(1,M)+j*randn(1,M))*Gno;

    for   k=0:M-1

          y=y+(1/sqrt(M))*tx_sym*exp((j*2*pi*k.*n)/M);

    end

    h = 1/sqrt(2)*[randn(1,1) + j*randn(1,1)];

    sig_no=h.*y+noise;

    sig_no1=sig_no.*conj(h)

    for k=0:M-1

       z1=z1+(1/sqrt(M))*sig_no1(k+1)*exp((-j*2*pi*k.*n)/M);

    end

   for t=1:M

       if (real(z1(t))<0)

       count1(EbNo_dB+1)=count1(EbNo_dB+1)+1;

       end

       if (imag(z1(t))<0);

       count2(EbNo_dB+1)=count2(EbNo_dB+1)+1;

       end

   end

   end

end

tmp_ber=(count1+count2)/2/(4*N);

ber=tmp_ber(1,1:5:end);

semilogy(p,ber,’mx-‘,’linewidth’,2);

xlabel(‘E/b in dB———–>’);

ylabel(‘BER——–>’)

axis([0 25 10^-5 0.5])

grid on

OUTPUT

 

MATLAB CODE

KC=1;

gamma=0.01; % Stepsize of adjusting the phase estimate

eth=0.5; % Error threshold

b=2; M=2^b; % Number of bits and symbols

Tb=1e-5; Ts=b*Tb; % Bit/Symbol time

Nb=40; Ns=b*Nb; % Number of sample times in Tb and Ts

T=Ts/Ns;        % Sampling interval

LB=4*Ns; Ns_2=Ns/2; % Buffer size

g=[0.1 -0.2 0.6 0.9 1 0.9 0.6 -0.2 0.1]; g=g/norm(g)^2;

Ng=length(g); zi_XMTR=zeros(1,Ng-1);

ndd=1; % Detection delay due to XMTR and channel

% QPSK signal waveforms

ss=[0 0; 0 1; 1 1; 1 0];

wc=2*pi/Ts; wcT=wc*T; t=[0:Ns-1]*T; wct=wc*t;

pi2=pi*2;  phases=[0:M-1]*(pi2/M);

su=sqrt(2/Ts)*[cos(wct);-sin(wct)]; suT=su*T; % Basis signal Eq.(7.3.2)

thd=-pi/10; % Phase offset between XMTR and RCVR

Es=2; % Energy of signal waveform representing the symbols

for m=1:M  % PSK signal waveforms

   sw(m,:)=sqrt(2*Es/Ts)*cos(wct+phases(m)+thd); % PSK signal (7.3.1)

end

interval=2*Ns+[1:Ns-1]; % Regular integration interval [k-2,k-1]*Ts

interval1=interval+Ns_2; % Later integration interval [k-3/2,k-1/2]*Ts

SNRbdB=9; SNRb=10^(SNRbdB/10); N0=2*(Es/b)/SNRb; sgmsT=sqrt(N0/2/T);

pobet= prob_error(SNRbdB,’PSK’,b,’bit’) % Theoretical BER

yr= zeros(2,LB); % Multiplier output buffer

s0s=zeros(ndd,size(ss,2)); % Transmitted symbol buffer

MaxIter=4; % # of iterations for getting the probability of error

nobe= 0; % Number of bit errors to be accumulated

thh(1)=0; nh(1)=-1; % Initial estimate of phase offset/sampling instant

ycsk0=[0  0]; % Previous correlator output samples initialized

rand(‘twister’,5489); randn(‘state’,0);

for k=1:MaxIter

i= ceil(rand*M); s=ss(i,:); % Signal index, Data bits to transmit

[ch_input,zi_XMTR]= filter(g,1,sw(i,:),zi_XMTR);

wct=wc*T*[0:Ns-1];

noise= sgmsT*(randn(1,Ns).*cos(wct)-randn(1,Ns).*sin(wct));

r = ch_input + noise; % Received signal

yr=[yr(:,Ns+1:LB) suT.*[r;r]]; % Multiplier output (buffer)

ycsk=sum(yr(:,interval+nh(k))’); % Correlator output at (k-1)Ts

ycsk1=sum(yr(:,interval1+nh(k))’); % Correlator output at (k-1/2)Ts

e(k)=ycsk*(ycsk1-ycsk0).’;  % Eq.(8.5.3a)

dnh=0; % Stepsize of adjusting the sampling instant

if KC>1 % For timing recovery

     if e(k)>eth, dnh=1; elseif e(k)<-eth, dnh=-1; end

end

nh(k+1)=nh(k)+dnh; % Eq.(8.5.2) for timing recovery

ycsk0=ycsk1; % Correlator output sample buffer updated

ynejth= ycsk(1)+j*ycsk(2);

if KC>0, ynejth=ynejth*exp(-j*thh(k)); end % Phase compensation

th=angle(ynejth); % Compensated phase of received signal waveform

if th<-pi/M, th=th+2*pi; end

[themin,imin]=min(abs(th-phases)); D=ss(imin,:); % Detected data

thh(k+1)=thh(k)+gamma*imag(exp(-j*phases(imin))*ynejth); %(8.4.10)

if k>ndd,  nobe=nobe+sum(s0s(1,:)~=D);  end

if nobe>100, break; end

s0s=[s0s(2:end,:); s]; % Transmitted symbol buffer updated

end

pobe= nobe/((k-ndd)*b) % The BER

 

OUTPUT

 

 

pobet =  0.0024

 

pobe =    0.1667

 

 

 

 

 

Section 2

PART A, B, C, D

SEQUENCE GENERATION

clc

clear

% Generating the bit pattern with each bit 6 samples long

b=round(rand(1,20));

pattern=[];

for k=1:20

    if b(1,k)==0

        sig=zeros(1,6);

    else

        sig=ones(1,6);

    end

    pattern=[pattern sig];

end

plot(pattern);

axis([-1 130 -.5 1.5]);

title(‘\bf\it Original Bit Sequence’);

% Generating the pseudo random bit pattern for spreading

spread_sig=round(rand(1,120));

figure,plot(spread_sig);

axis([-1 130 -.5 1.5]);

title(‘\bf\it Pseudorandom Bit Sequence’);

% XORing the pattern with the spread signal

hopped_sig=xor(pattern,spread_sig);

% Modulating the hopped signal

dsss_sig=[];

t=[0:100];

fc=.1

c1=cos(2*pi*fc*t);

c2=cos(2*pi*fc*t+pi);

for k=1:120

    if hopped_sig(1,k)==0

        dsss_sig=[dsss_sig c1];

    else

        dsss_sig=[dsss_sig c2];

    end

end

figure,plot([1:12120],dsss_sig);

axis([-1 12220 -1.5 1.5]);

title(‘\bf\it DSSS Signal’);

% Plotting the FFT of DSSS signal

figure,plot([1:12120],abs(fft(dsss_sig)))

GRAPH

 

QPSK BER WITH TRANSMITTER AND RECEIVER

%TRANSMITTER

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear

nr_data_bits=1000000;% 0’s and 1’s, keep even number-Takes ~1 minute for a run of 1 million

nr_symbols=nr_data_bits/2;

b_data = (randn(1, nr_data_bits) > .5);%random 0’s and 1’s

b = (b_data);

%         |

d=zeros(1,length(b)/2);

%definition of the QPSK symbols using Gray coding.

for n=1:length(b)/2

    p=b(2*n);

    imp=b(2*n-1);

    if (imp==0)&&(p==0)

        d(n)=exp(j*pi/4);%45 degrees

    end

    if (imp==1)&&(p==0)

        d(n)=exp(j*3*pi/4);%135 degrees

    end

    if (imp==1)&&(p==1)

        d(n)=exp(j*5*pi/4);%225 degrees

    end

    if (imp==0)&&(p==1)

        d(n)=exp(j*7*pi/4);%315 degrees

    end

end

qpsk=d;

SNR=0:30;%change SNR values

BER1=[];

SNR1=[];

SER=[];

SER1=[];

sigma1=[];

%Rayleigh multipath/AWGN(Additive White Gaussian Noise)

for SNR=0:length(SNR);%loop over SNR-change SNR values (0,5,10 etc dB)

sigma = sqrt(10.0^(-SNR/10.0));

sigma=sigma/2;%Required a division by 2 to get close to exact solutions(Notes)-WHY?

%Is dividing by two(2) legitimate?

%sigma1=[sigma1 sigma];

%add Rayleigh multipath(no LOS) to signal(qpsk)

x=randn(1,nr_symbols);

y=randn(1,nr_symbols);

ray=sqrt(0.5*(x.^2+y.^2));%variance=0.5-Tracks theoritical PDF closely

mpqpsk=qpsk.*ray;

mpsnqpsk=(real(mpqpsk)+sigma.*randn(size(mpqpsk))) +i.*(imag(mpqpsk)+sigma.*randn(size(mpqpsk)));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Receiver

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

r=mpsnqpsk;%received signal plus noise and multipath

bhat=[real(r)<0;imag(r)<0];%detector

bhat=bhat(:)’;

bhat1=bhat;%0’s and 1’s

ne=sum(b~=bhat1);%number of errors

BER=ne/nr_data_bits;

SER=ne/nr_symbols;%consider this to be Ps=log2(4)*Pb=2*Pb

SER1=[SER1 SER];

BER1=[BER1 BER];

SNR1=[SNR1 SNR];

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Plots

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(1);

plot(d,’o’);%plot constellation without noise

axis([-2 2 -2 2]);

grid on;

xlabel(‘real’); ylabel(‘imag’);

title(‘QPSK constellation’);

figure(2);

semilogy(SNR1,BER1,’*’,SNR1,SER1,’o’);

grid on;

xlabel(‘SNR=Eb/No(dB)’); ylabel(‘BER/SER’);

title(‘Simulation of BER/SER for QPSK with Gray coding( Rayleigh multipath and AWGN)’);

legend(‘BER-simulated’,’SER-simulated’);

figure(3)

plot(real(qpsk));

grid on;

axis([1 200 -2 2]);

title(‘QPSK symbols’);

xlabel(‘symbols’);ylabel(‘Amplitude’);

figure(4)

plot(20*log10(abs(ray)));

grid on;

axis([1 200 -30 10]);

title(‘Rayleigh Fading Envelope(variance=0.5)’);

xlabel(‘symbols’);ylabel(‘Amplitude/RMS(dB)’);

GRAPH