Вы находитесь на странице: 1из 21

COMMUNICATION SYSTEM LABORATORY 1

Experiment No: .
Date: . /. /

MATLAB EXPERIMENTS
PRE-LAB :

Go to Mathworks web-site and get familiar with MATLAB


Go through the tutorials. Run MATLAB and try to understand the following functions
(we can use Matlab help menu or online help)
randn
repmat
reshape
length
size
sqrt
plot
semilogy
abs
sum
mean
subplot
pwelch
scatterplot
eyediagram
real
imag
hist

Learn what is additive white Gaussian noise

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 2

Experiment No: .
Date: . /. /

BINARY PHASE SHIFT KEYING BIT ERROR RATE


PERFORMANCE ANALYSIS

Aim: To analyze BER(Bit Error Rate) performance of BPSK modulation Technique using
MATLAB software.

Equipments Required:

1. MATLAB, Computer installed with Windows XP or higher Version.

Theory:

With Binary Phase Shift Keying (BPSK), the binary digits 1 and 0 maybe represented by the
analog levels and respectively. The system model is as shown in the Figure
below.

Figure: Simplified block diagram with BPSK transmitter-receiver

Channel Model
The transmitted waveform gets corrupted by noise , typically referred to as Additive

White Gaussian Noise (AWGN).

Additive : As the noise gets added (and not multiplied) to the received signal

White : The spectrum of the noise if flat for all frequencies.

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 3

Gaussian : The values of the noise follows the Gaussian probability distribution

function, with and .

Computing the probability of error


Using the derivation provided in Section 5.2.1 of [COMM-PROAKIS] as reference:
The received signal,
when bit 1 is transmitted and
when bit 0 is transmitted.
The conditional probability distribution function (PDF) of for the two cases are:

Figure: Conditional probability density function with BPSK modulation


Assuming that S1 and S0 are equally probable i.e. , the threshold
0 forms the optimal decision boundary.
if the received signal is is greater than 0, then the receiver assumes was
transmitted.
if the received signal is is less than or equal to 0, then the receiver
assumes was transmitted.
i.e.
Y > 0=S1 and
Y < 0=S0 .
Probability of error given S1 was transmitted

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 4

With this threshold, the probability of error given S1 is transmitted is (the area in blue
region):
,
where,

is the complementary error function.


Probability of error given S0 was transmitted
Similarly the probability of error given S0 is transmitted is (the area in green region):

Total probability of bit error


.
Given that we assumed that S1 and S0 are equally probable i.e. P(S1)=P(S2)=1/2, the bit
error probability is,

EXPERIMENT PROCEDURE:

PREPARATION (PRE-LAB)

1) An analog signal carries four bits in each signal element. If 1000 signal elements are sent per
second , find the baud rate and bit rate.

2) What is a correlator?

STEPS TO FOLLOW:

The code performs the following:

(a) Generation of random BPSK modulated symbols +1s and -1s

(b) Passing them through Additive White Gaussian Noise channel

(c) Demodulation of the received symbol based on the location in the constellation

(d) Counting the number of errors

(e) Repeating the same for multiple Eb/No value VS BER(Bit Error Rate)

TEST PROCEDURE :

1. Open the MATLAB software by double clicking its icon.

2. MATLAB logo will appear and after few moments Command Prompt will appear.

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 5

3. Go to the File Menu and select a New M- file. (File NewM-file) or in the left hand corner a blank
white paper icon will be there. Click it once.

4. A blank M- file will appear with a title untitled

5. Now start typing your program. After completing, save the M- file with appropriate name. To
execute the program Press F5 or go to Debug Menu and select Run.

6. After execution output will appear in the Command window .If there is an error then with an
alarm, type of error will appear in red color.

7. Rectify the error if any and go to Debug Menu and select Run.

PROGRAM:

clc;

clear all;

close all;

num_bit=1000000;%number of bit

data=randint(1,num_bit); //%random bit generation (1 or 0)

s=2*data-1; //%conversion of data for BPSK modulation

SNRdB=0:9; // % SNR in dB

SNR=10.^(SNRdB/10);

for(k=1:length(SNRdB)) //%BER (error/bit) calculation for different SNR

y=s+awgn(s,SNRdB(k));

error=0;

for(c=1:1:num_bit)

if (y(c)>0&&data(c)==0)||(y(c)<0&&data(c)==1) //%logic acording to BPSK

error=error+1;

end

end

error=error/num_bit; // %Calculate error/bit

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 6

m(k)=error;

end

figure(1)

%plot start

semilogy(SNRdB,m,'r','linewidth',2),grid on,hold on;

BER_th=(1/2)*erfc(sqrt(SNR));

semilogy(SNRdB,BER_th,'k','linewidth',2);

title(' curve for Bit Error Rate verses SNR for Binary PSK modulation');

xlabel(' SNR(dB)');

ylabel('BER');

legend('simulation','theorytical')

OUTPUT :

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 7

Conclusion:

Questions:

1. Write matlab program to encode the data sequence using a) RZ b) NRZ c) Manchester d)
Differential encoding.

2.Why do we make 180 degree phase shift in PSK and why not 90 or 270?comment on this.

3. What is the function of a decision device.

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 8

Experiment No: .
Date: . /. /

QUADRATURE PHASE SHIFT KEYING BIT ERROR


RATE PERFORMANCE ANALYSIS

Aim: To write a program to calculate the Bit Error Rate (BER) of QPSK in an Additive
White Gaussian Noise (AWGN) channel.

Equipments Required:

MATLAB, Computer installed with Windows XP or higher Version.

Theory:
QPSK uses four points on the constellation diagram, equispaced around a circle. With four
phases, QPSK can encode two bits per symbol, shown in the diagram with Gray coding to
minimize the bit error rate (BER) sometimes misperceived as twice the BER of BPSK.

The mathematical analysis shows that QPSK can be used either to double the data rate
compared with a BPSK system while maintaining the same bandwidth of the signal, or to maintain
the data-rate of BPSK but halving the bandwidth needed. In this latter case, the BER of QPSK is
exactly the same as the BER of BPSK and deciding differently is a common confusion when
considering or describing QPSK. The transmitted carrier can undergo numbers of phase changes.

Given that radio communication channels are allocated by agencies such as the Federal
Communication Commission giving a prescribed (maximum) bandwidth, the advantage of QPSK
over BPSK becomes evident: QPSK transmits twice the data rate in a given bandwidth compared
to BPSK - at the same BER. The engineering penalty that is paid is that QPSK transmitters and
receivers are more complicated than the ones for BPSK. However, with modern electronics
technology, the penalty in cost is very moderate.

As with BPSK, there are phase ambiguity problems at the receiving end, and differentially
encoded QPSK is often used in practice.

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 9

The implementation of QPSK is more general than that of BPSK and also indicates the
implementation of higher-order PSK. Writing the symbols in the constellation diagram in terms of
the sine and cosine waves used to transmit them:

This yields the four phases /4, 3/4, 5/4 and 7/4 as needed.

This results in a two-dimensional signal space with unit basis functions

The first basis function is used as the in-phase component of the signal and the second as the
quadrature component of the signal.

Hence, the signal constellation consists of the signal-space 4 points

The factors of 1/2 indicate that the total power is split equally between the two carriers.

Comparing these basis functions with that for BPSK shows clearly how QPSK can be viewed as
two independent BPSK signals. Note that the signal-space points for BPSK do not need to split
the symbol (bit) energy over the two carriers in the scheme shown in the BPSK constellation
diagram.

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 10

QPSK systems can be implemented in a number of ways. An illustration of the major components
of the transmitter and receiver structure are shown below.

Bit error rate :

Although QPSK can be viewed as a quaternary modulation, it is easier to see it as two


independently modulated quadrature carriers. With this interpretation, the even (or odd) bits are
used to modulate the in-phase component of the carrier, while the odd (or even) bits are used to
modulate the quadrature-phase component of the carrier. BPSK is used on both carriers and they
can be independently demodulated.

As a result, the probability of bit-error for QPSK is the same as for BPSK:

However, in order to achieve the same bit-error probability as BPSK, QPSK uses twice the
power (since two bits are transmitted simultaneously).

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 11

The symbol error rate is given by:

If the signal-to-noise ratio is high (as is necessary for practical QPSK systems) the
probability of symbol error may be approximated:

The modulated signal is shown below for a short segment of a random binary data-stream.
The two carrier waves are a cosine wave and a sine wave, as indicated by the signal-space analysis
above. Here, the odd-numbered bits have been assigned to the in-phase component and the even-
numbered bits to the quadrature component (taking the first bit as number 1). The total signal
the sum of the two components is shown at the bottom. Jumps in phase can be seen as the PSK
changes the phase on each component at the start of each bit-period. The topmost waveform alone
matches the description given for BPSK above.

The binary data that is conveyed by this waveform is: 1 1 0 0 0 1 1 0.

The odd bits, highlighted here, contribute to the in-phase component: 1 1 0 0 0 1 1 0

The even bits, highlighted here, contribute to the quadrature-phase component:


11000110

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 12

EXPERIMENT PROCEDURE:

PREPARATION (PRE-LAB)

1. What are the types of QPSK?


2. What is the significance of Q-channel and I channel in QPSK modulator?
3. What is the minimum bandwidth requirement of QPSK?
4. Draw the output phase versus time relationship for a QPSK modulator.
5. Compare OQPSK and QPSK.

STEPS TO FOLLOW:

The code performs the following:

(a) Generation of random QPSK modulated symbols

(b) Passing them through Additive White Gaussian Noise channel

(c) Demodulation of the received symbol based on the location in the constellation

(d) Counting the number of errors

(e) Repeating the same for multiple Eb/No value VS BER(Bit Error Rate)

TEST PROCEDURE :

1. Open the MATLAB software by double clicking its icon.

2. MATLAB logo will appear and after few moments Command Prompt will appear.

3. Go to the File Menu and select a New M- file. (File NewM-file) or in the left hand corner a blank
white paper icon will be there. Click it once.

4. A blank M- file will appear with a title untitled

5. Now start typing your program. After completing, save the M- file with appropriate name. To
execute the program Press F5 or go to Debug Menu and select Run.

6. After execution output will appear in the Command window .If there is an error then with an
alarm, type of error will appear in red color.

7. Rectify the error if any and go to Debug Menu and select Run.

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 13

PROGRAM:

% BER QPSK

Clc %for clearing the command window


Closeall %for closing all the window except command window
Clearall %for deleting all the variables from the memory
nPSK=2; %QPSK
nSymbol=100000; %Number of Input Symbol
nbit=nSymbol*nPSK; %Number of Input Bit
Eb=1; %Energy Bit
itr=20; %Number of Itration
BER=1:itr; %Bit Error Rate

%Bit Error Rate Calculation

forSNRdb=1:1:itr % SNR in dB
counter=0;
SNR=10.^(SNRdb/10);
No=1/SNR;
v=(No/Eb)/(2*nPSK); % Noise Equation
for n=1:1:nSymbol
u1=rand(1); %random first bit generation
u2=rand(1); %random second bit generation

u1=round(u1); %round first bit to(1 or 0)


u2=round(u2); %round second bit to(1 or 0)

%Modulation Process

if(u1==0 && u2==0)


real=cosd(0);
img=sind(0);

elseif(u1==0 && u2==1)


real=cosd(90);
img=sind(90);

elseif(u1==1 && u2==0)


real=cosd(180);
img=sind(180);

elseif(u1==1 && u2==1)


real=cosd(270);
img=sind(270);

end

%Transmition Process

AWGN1=sqrt(v)*randn(1);
AWGN2=sqrt(v)*randn(1);

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 14

%Channel

realn=real+AWGN1;
imgn=img+AWGN2;

%RX

phin=mod(atan2d(imgn,realn)+360,360);

if((phin>=0&&phin<=45)||(phin>315))
uu1=0;
uu2=0;
elseif(phin>45&&phin<=135)
uu1=0;
uu2=1;
elseif(phin>135&&phin<=225)
uu1=1;
uu2=0;
elseif(phin>225&&phin<=315)
uu1=1;
uu2=1;
end

%Detection Process

if(u1~=uu1) %logic according to QPSK


counter=counter+1;
end
if(u2~=uu2) %logic according to QPSK
counter=counter+1;
end
end
BER(SNRdb)=(counter/nbit); %Calculate error/bit
end
SNRdb=1:1:itr;
pe=0.5*erfc(sqrt(10.^(SNRdb/10))); %Theoretical Bit Error Rate
figure('name','BER_QPSK','numbertitle','off');
semilogy(SNRdb,BER,'--g*','linewidth',1.5,'markersize',8);
axis([1 itr 10^(-4) 1]);
title(' curve for Bit Error Rate Vs SNRdb for QPSK modulation');
xlabel(' SNRdb(dB)');
ylabel('BER');
gridon;
holdon;

%Plot Bit Error Rate

semilogy(SNRdb,pe,'--bs','linewidth',1.5,'markersize',6);
axis([1 itr 10^(-4) 1]);
xlabel('SNRdb(dB)');
ylabel('BER');
gridon;
holdon;
legend('simulation','theoretical');

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 15

OUTPUT :

Conclusion:

Questions:

1. Write matlab program to encode the data sequence using a) RZ b) NRZ c) Manchester d)
Differential encoding.

2.Why do we make 180 degree phase shift in PSK and why not 90 or 270?comment on this.

3. What is the function of a decision device.

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 16

Experiment No: .
Date: . /. /

CYCLIC CODE BIT ERROR RATE PERFORMANCE


ANALYSIS

Aim: To study Cyclic Encoding and Decoding and to calculate bit error rate using MATLAB.

Software Required:

MATLAB, Computer installed with Windows XP or higher Version.

Theory:

Cyclic codes are an important class of linear codes for which the encoding and decoding
can be efficiently implemented using shift registers. Many common linear codes, including
Hamming and Golay codes, have an equivalent cyclic representation. Cyclic code is a block code,
where the circular shifts of each code word gives another word that belongs to the code. They
are error-correcting codes that have algebraic properties that are convenient for efficient error
detection and correction. Let be a linear code over a finite field (also called Galois field) of block
length n. is called a cyclic code if, for every code word c=(c1,...,cn) from C, the word (cn,c1,...,cn-1)
in obtained by a cyclic right shift of components is again a code word. Because one cyclic right
shift is equal to n 1 cyclic left shifts, a cyclic code may also be defined via cyclic left shifts.
Therefore the linear code is cyclic precisely when it is invariant under all cyclic shifts. Cyclic
Codes have some additional structural constraint on the codes. They are based on Galois fields and
because of their structural properties they are very useful for error controls. Their structure is
strongly related to Galois fields because of which the encoding and decoding algorithms for cyclic
codes are computationally efficient. The Hamming(7,4) code may be written as a cyclic code over
GF(2) with generator .In fact, any binary Hamming code of the form Ham(r, 2) is equivalent to a
cyclic code, and any Hamming code of the form Ham(r,q) with r and q-1 relatively prime is also
equivalent to a cyclic code. Given a Hamming code of the form Ham(r,2) with the set of even code
words forms a cyclic code.

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 17

Operation :

The theory of a CRC calculation is straight forward. The data is treated by the CRC algorithm as
a binary number. This number is divided by another binary number called the polynomial. The rest
of the division is the CRC checksum, which is appended to the transmitted message. The receiver
divides the message (including the calculated CRC), by the same polynomial the transmitter used.
If the result of this division is zero, then the transmission was successful. However, if the result is
not equal to zero, an error occurred during the transmission

Calculation for generating a CRC

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 18

Checking a message for CRC error

Experiment Procedure:

STEP 1: Start the program.


STEP 2: Assign the block length n.
STEP 3: Assign the message bits k.
STEP 4: The cyclic code is (n, k)
STEP 5: Generate the polynomial.
STEP 6: Obtain the input message randomly.
STEP 7: The input message is in binary format.
STEP 8: The code word is formed by appending the parity bits with the message bits.
STEP 9: The parity bits are calculated from the generation polynomial.
STEP10: The code word formed is transmitted through noisy channel.
STEP11: The received signal is then decoded with the help of generator polynomial.
STEP12: Bit error rate is calculated by comparing decoded message and original message.

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 19

program:
clc;clear all;
close all;
n=7;k=4;num_bit=10000;
genpoly=cyclpoly(n,k,'max');
SNRdB=0:10;
SNR=10.^(SNRdB/10);

for i=1:length(SNR)

msg=randint(num_bit,k,[0,1]);
code=encode(msg,n,k,'cyclic/binary',genpoly);
[row column]=size(code);
codevec=reshape(code.',1,row*column);
noise=awgn(codevec,SNRdB(i));
y=codevec+noise;
error=0;
for j=1:length(y)
if (y(j)>1&&codevec(j)==0)||(y(j)<0&&codevec(j)==1)
error=error+1;
end
end
error=error/num_bit;
m(i)=error;
end
y(find(y>0))=1;
y(find(y<0))=0;
decode_y=decode(y,n,k,'cyclic/binary',genpoly);
decmsg=reshape(decode_y,num_bit,k)

semilogy(SNRdB,m,'r','linewidth',2),grid on;
title(' Bit Error Rate verses SNR for Cyclic Code');
xlabel(' SNR(dB)');
ylabel('BER');

MODEL GRAPH

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 20

Bit Error Rate verses SNR for Cyclic Code


0
10

-1
10
BER

-2
10

-3
10
0 1 2 3 4 5 6 7 8 9 10
SNR(dB)

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY


COMMUNICATION SYSTEM LABORATORY 21

Conclusion:

Questions:

1 Consider the n = 7 binary cyclic code generated by g(x) = 1 + x + x 3 Find code word
for any message sequence.

2. Describe the smallest cyclic code containing the vector 0011010.

3. For designing of (4,1) cyclic repetition code, what would be the order of the
generator polynomial g(x)?

4. For the generation of a cyclic code, the generator polynomial should be the factor
of _____

5. List out the advantage and disadvantage of cyclic code

V Semester B.Tech Dept of ECE VELTECH UNIVERSITY

Вам также может понравиться