Escolar Documentos
Profissional Documentos
Cultura Documentos
Labs
12/8/2014
Constellation Diagram:
A constellation diagram is a representation of a signal modulated by a digital modulation scheme
such as quadrature amplitude modulation or phase-shift keying. It displays the signal as a twodimensional scatter diagram in the complex plane at symbol sampling instants. In a more abstract
sense, it represents the possible symbols that may be selected by a given modulation scheme as
points in the complex plane. Measured constellation diagrams can be used to recognize the type of
interference and distortion in a signal.
3.1 Description of different MATLAB functions which are used in this lab manual.
No:
Function
Working
modulate()
demodulate()
modem()
awgn()
biterr()
rayleighchan()
symerr()
fec()
There are some generic functions which are useful for this lab manual description for these
functions is given as:
No:
Function
Working
reshape()
randn()
randi()
de2bi()
bi2de()
imread()
imshow()
3.2 Use the reshape function to re-arrange a matrix as illustrated in the figure below.
3.3 Please analyze in detail the operation of de2bi (), how can we obtain a fixed size binary Output
for given number.
Amplitude
1
0.8
0.6
0.4
10
12
n Values
Real Values PSK
14
16
18
20
Quadrature
-1
0
-0.2
-0.4
1
Amplitude
0.2
-0.6
-0.8
-1
-1
-1
0
10
12
n Values
14
16
18
-0.5
0
In-Phase
0.5
20
3.4 For now consider that we are simulating just 1000 QPSK modulated symbols using toolbox
functions. So we can set up some constants at the start of our simulation code.
clear all;
M=4; %Constellation size
Nsym=10000; %Number of symbols to be simulated
mpsk=modem.pskmod(M);
u=randi([0,M-1],1,Nsym);
s=modulate(mpsk,u);
scatterplot(s)
dmpsk=modem.pskdemod(M);
u_hat=demodulate(dmpsk,s);
figure (2)
subplot(2,1,1)
plot(imag(s(1:20)));
xlabel('n Values')
ylabel('Amplitude')
title('Imaginary Values PSK');
axis([0 20 -1.5 1.5])
subplot(2,1,2)
plot(real(s(1:20)));
xlabel('n Values')
ylabel('Amplitude')
title('Imaginary Values PSK');
axis([0 20 -1.5 1.5])
3.5 Now that we have an operational M-PSK transmission system, the same steps can be taken to
simulate an M-QAM modulation scheme by using appropriate sub-funtions of modem command.
Please sketch the constellation diagram for M-QAM and also plot the time domain waveform.
Code : 3.5
M=8;
%M=4;
Nsym=1000;
mqam=modem.qammod(M);
u=randi([0,M-1],1,Nsym); %symbols
s=modulate(mqam,u);
scatterplot(s); %Constellation Diagram
dmqam=modem.qamdemod(M);
u_hat=demodulate(dmqam,s);
figure (2)
subplot(2,1,1)
plot(imag(s(1:20)));
xlabel('n Values')
ylabel('Amplitude')
title('8 QAM modulation Imaginary Values')
axis([0 20 -1.5 1.5])
subplot(2,1,2)
plot(real(s(1:20)));
8 QAM modulation Imaginary Values
Scatter plot
Amplitude
1
3
0
2
-1
2
10
12
14
n Values
8 QAM modulation Real Values
16
18
20
Amplitude
Quadrature
-1
-2
-1
-3
10
12
n Values
14
16
18
20
-3
-2
-1
0
In-Phase
xlabel('n Values')
ylabel('Amplitude')
title('8 QAM modulation Real Values')
axis([0 20 -1.5 1.5])
4.3 Now we can extend this problem to study flat fading rayleigh channel. Flat fading
process can be conveniently realized as h=sqrt(0.5)*(randn()+1i*randn());
y=h*s+n;
The received signal can be equalized using ZF equalizer as
In a typical wired digital communication link the channel impulse response can be assumed
to be fixed or very slowly varying as a function of time. In this simulation we consider a
sample channel impulse response h which is defined in the subsequent psuedo-code.
Task 4_3
clear all
clc
M=2;
Nsym=1000;
mpsk=modem.pskmod(M);
%Creating object of modulation
dmpsk=modem.pskdemod(M);
%Creating object of demodulation
snr=-4:20;
%Defining the range of SNR
tic();
for j=1:length(snr)
ratio=[];
RATIO=[];
for i=1:100
u=randi([0,M-1],1,Nsym);%Generating Random Sequence
bits=de2bi(u); %Converting from decimal to binary
s=modulate(mpsk,u); %Modulating the Signal
s1=awgn(s,snr(j));%Adding Additive White Guassian
y1=demodulate(dmpsk,s1);
%Demodulating data
bits_y1=de2bi(y1);
h=sqrt(0.5)*(randn()+1i*randn());
s2=h.*s;
y=awgn(s2,snr(j));
h_star=conj(h);
s_hat=(h_star.*y)./((abs(h))^2);
u_hat=demodulate(dmpsk,s_hat);
bits_hat=de2bi(u_hat);
[symbol ratio(i)]=biterr(bits,bits_hat);
[symb RATIO(i)]=biterr(bits,bits_y1);
end
ber(j)=mean(ratio);
BER(j)=mean(RATIO);
end
toc()
semilogy(snr,ber,'r',snr,BER,'g')
legend('Rayleigh fading','AWGN','Location','NorthEastOutside')
xlabel('SNR in dB')
ylabel('BitErrorRate')
title('Comparison between Rayleigh Fading and AWGN')
10
Rayleigh fading
AWGN
-1
10
-2
10
-3
10
-4
10
-5
10
-5
5
10
SNR in dB
15
20
4.4 In the next we use matlab builtin function to perform adaptive least mean square (LMS)
equalization using a certain initial symbols as pilot. The initial pilot symbols are used to train
the equalization filter. The idea is illustrated in the figure below
10
-2
10
-4
10
10
15
20
25
30
35
40
10
15
20
25
30
35
40
-0.31
10
-0.39
10
-0.47
10
SER(i)=mean(ser);
SER_noeq(i)=mean(req);
end% for ebnov
clear figure
subplot(2,1,1)
semilogy(snr,SER)
subplot(2,1,2)
semilogy(snr,SER_noeq)
10
-1
10
-3
10
-4
10
-5
10
-6
10
-4
-2
4
6
SNR in dB
10
12
14
12
14
10
-1
10
-2
10
-2
10
-3
10
-4
10
-5
10
-6
10
-4
-2
4
6
SNR in dB
10
-1
10
-2
-3
10
-4
10
-5
10
-5
5
10
Eb/No in dB
15
20
-1
10
10
-2
10
-3
10
-4
10
-5
5
10
Eb/No in dB
15
20
10
M=2
M=4
M=8
M=16
M=32
M=64
-1
10
-2
-3
10
-4
10
-5
10
-6
10
10
15
Eb/No in dB
20
25
10
M=2
M=4
M=8
M=16
M=32
M=64
-1
10
10
-2
10
-3
10
-4
10
-5
10
10
15
Eb/No in dB
20
25
4.2
clear all
clc
clear figure
M=4;
mpsk=modem.pskmod(M);
%Creating object of
modulation
dmpsk=modem.pskdemod(M);
%Creating object of
demodulation
snr=-5:5:20;
image_data=imread('abc','jpg'); %Loading the image in
MATLAB
[r c]=size(image_data);
size(image_data)
img_array=reshape(double(image_data),r*c,1);
img_bits=de2bi(img_array,8);
img_vector=reshape(img_bits,1,r*c*8);
w=img_vector;
for i=1:length(w)/2
s(i)=bi2de(img_vector(1:log2(M)),log2(M));
img_vector(1:log2(M))=[];
end
q=1:length(snr);
for j=1:length(snr)
modulated_signal=modulate(mpsk,s); %Modulating Image
data
y=awgn(modulated_signal,snr(j));
%Adding
Additive White Guassian Noise
demodulated_Signal=demodulate(dmpsk,y);%Demodulating
Image data
img_vector_hat=de2bi(demodulated_Signal);
h_hat_vector=reshape(img_vector_hat',1,r*c*8);
img_bits_hat=reshape(h_hat_vector',r*c,8);
img_array_hat=bi2de(img_bits_hat);
imga_Data_hat=reshape(img_array_hat,r,c);
intArray = uint8(imga_Data_hat);
%Converting data
from double to unsigned integer
approximated_Signal=reshape(intArray,60,60,3);
q(j)=subplot(3,3,j);
imshow(approximated_Signal)
title('Received Image ')
end
subplot(3,3,7:9)
imshow(image_data)
title('original image')
Received Image
Received Image
Received Image
Received Image
Received Image
Received Image
original image
4.5
Least mean squares (LMS) algorithms are a class of adaptive filter
used to mimic a desired filter by finding the filter coefficients that
relate to producing the least mean squares of the error signal
(difference between the desired and the actual signal). It is a
stochastic gradient descent method in that the filter is only
adapted based on the error at the current time.
10
Bit error rate
M=2
M=4
M=8
M=16
-5
10
10
20
SNR in dB
30
40
10
M=2
M=4
M=8
M=16
-1
10
10
20
SNR in dB
30
40
4.6
Forward Error Correction (FEC)
This page describes forward error correction and its application and
mention matlab codes for different forward error correction techniques.
Forward Error Correction is the module used in wireless communication
to correct errors at the receiver end. These errors must have occurred
due to interference, noise or various impairments in the medium
between transmitter and receiver. It is also referred as short form FEC.
As the name suggests this module avoids retransmission of the
corrupted data as it helps in correcting the errors at the receiver.
FEC is power efficient compare to its' non FEC counterpart as with the
same transmit power one can achieve better BER in FEC based
communication system.
There are many techniques invented to be used as forward error
correction techniques such as Convolution coding, Turbo coding, BCH
coding and more.
Bit Error Performance of Flat Fading Rayleigh Channel using BCH encoding
10
-1
10
-2
10
-3
10
-20
-15
-10
-5
5
SNR in dB
10
15
20
25
4.6
clearall
clc
clearfigure
M=4;
K=131;
N=255;
mpsk=modem.pskmod(M);
modulation
%Creating object of
dmpsk=modem.pskdemod(M);
%Creating object of
demodulation
cc=fec.bchenc(N,K);
%Creating object of BCH
Coder
cd=fec.bchdec(N,K);
%Creating object of BCH
decoder
snr=-20:30;
%Defining the range of
SNR
for j=1:length(snr)
u=randi([0,M-1],1,K);
%Generating random
sequence
b=de2bi(u);
%Converting data from
decimal to binary
s=encode(cc,b);
%Encoding data
m=bi2de(s);
%Converting data from
binary to decimal
msg=modulate(mpsk,m);
%Modulating the Signal
msg_nocode=modulate(mpsk,u);
ratio=1:length(snr);
fori=1:10000
%Imposing Flat Fading Rayleigh Channel to coded
signal
h1=sqrt(0.5)*(randn()+1i*randn());
s2=h1.*msg;
y=awgn(s2,snr(j),'measured');
h_star=conj(h1);
signal=(h_star.*y)./((abs(h1))^2);
%Imposing Flat Fading Rayleigh Channel to uncoded
signal
h2=sqrt(0.5)*(randn()+1i*randn());
s3=h2.*msg_nocode;
y_nocode=awgn(s3,snr(j));
h_star2=conj(h2);
signal2=(h_star2.*y_nocode)./((abs(h2))^2);
%Demodulating data
dem=demodulate(dmpsk,signal2);
msg_hat=demodulate(dmpsk,signal);
bits_nocode=de2bi(dem);
d=de2bi(msg_hat);
%Converting from
decimal to binary
ds=decode(cd,d);
%Decoding the
data
[Number ratio(i)]=biterr(ds,b);
%Simulatin bit
error rate
[number Ratio(i)]=biterr(b,bits_nocode);
end
bercode(j)=mean(ratio);
berno(j)=mean(Ratio);
end
clearfigure
semilogy(snr,bercode)
title('Bit Error Performance of Flat Fading Rayleigh
Channel using BCH encoding')
xlabel('SNR in dB')
ylabel('Bit Error Rate')
holdon
semilogy(snr,berno,'r')
legend('Bit Error Rate of BCH encoding','Bit Error
Rate without BCH encoding','location','NorthOutside')
axis([-20 28 10^(-3.25) 1])
[The End]