You are on page 1of 6

[MECH662-matlab]

[Parity check]

Module 10<Topic 1>< Matlab Program’s on Parity


Check >
Course Learning Outcomes:
C7. Use communication toolbox and programming with wireless communication and computation
platforms to evaluate the appropriateness of scripting and simulations
C8. With less supervision, collaborate work with a group to develop and communicate reasonable

recommendations for the script debugging.

Activity 1 : Matlab Program on Parity Check


In this experiment, you will learn how to represent, manipulate, and analyze parity check using

Bin sequence

1. to study how to develop a program to perform parity check

2. to study about the matlab commands used

3. to use parity check to obtain parity check bit for error detection and correction

Introduction

Even & Odd Parity Check,


Generate & Add Parity Bit, in a
Bin Sequence Using MATLAB
A parity bit is a bit added to the end of a sequence of bits (zeros or ones) that indicates whether the number of
bits in the string with the value one is even or odd. Parity bits are used as the simplest form of error detecting
code.

Assume, for example, that two devices are communicating with even parity, the transmitting device sends data,
it counts the number of set bits in each group of bits. If the number of set bits is even, it sets the parity bit to 0; if
the number of set bits is odd, it sets the parity bit to 1. In this way, every sequence have an even number of set
bits. On the receiving side, the device checks to make sure that it has an even number of set bits. If it finds an
odd number of set bits, the receiver knows there was an error during transmission.

NOTE:
The sender and receiver must both agree to use parity checking and to agree on whether parity is to be odd or
even. If the two sides are not configured with the same parity sense, communication will be impossible.

Course Module
[MECH662-matlab]
2

[Parity check]

MATLAB Code for Even Parity Check & Adding Parity Bit, in an User Dfined Bin Sequence

clc;
close all;
clear all;
a=input('Enter the Number of bits in the sequence to test for Even parity');
disp('Enter the bit sequence One by one to test for Even parity: ')
for i=1:a
x(i)=input('');
end
t=0;
for i = 1:a
if(x(i))
t = t + 1; %increment by one if a bit is one
end
end

if(mod(t,2)~=0) %check if not even then attach another '1' to make the parity
even
y = [x 1];
disp('Parity bit generated : 1');
else %check if even then attach another '0' to let the parity be even
y = [x 0]; disp('Parity bit generated : 0');
end
disp('Input bit sequence:');
disp(x); %display the input bit sequence
disp('Bit sequence with parity (Even) bit : ');
disp(y); %display the resultant bit sequence after parity bit addition

Sample input output for Even Parity Check & Adding Parity Bit
(1)
Enter the Number of bits in the sequence to test for Even parity
7
Enter the bit sequence One by one to test for Even parity:
1
0
1
1
0
1
1
Parity bit generated : 1
Input bit sequence:
1 0 1 1 0 1 1

Bit sequence with parity (Even) bit :


1 0 1 1 0 1 1 1
[MECH662-matlab] 3

[Parity check]

(2)
Enter the Number of bits in the sequence to test for Even parity
7
Enter the bit sequence One by one to test for Even parity:
1
0
1
1
0
1
0
Parity bit generated : 0
Input bit sequence:
1 0 1 1 0 1 0

Bit sequence with parity (Even) bit :


1 0 1 1 0 1 0 0

MATLAB Code for Odd Parity Check & Adding Parity Bit, in an User Dfined Bin Sequence
clc;
close all;
clear all;
a=input('Enter the Number of bits in the sequence to test for Odd parity');
disp('Enter the bit sequence one by one to test for Odd parity: ')
for i=1:a
x(i)=input('');
end
t=0;
for i = 1:a
if(x(i)==1)
t = t + 1; %increment by one if a bit is one
end
end

if(mod(t,2)~=1) %check if not odd then attach another '1' to make the parity odd
y = [x 1]; disp('Parity bit generated : 1');
else %check if odd then attach another '0' to let the parity be odd
y = [x 0]; disp('Parity bit generated : 0');
end
disp('Input bit sequence:');
disp(x); %display the input bit sequence
disp('Bit sequence with parity (Odd) bit : ');
disp(y); %display the resultant bit sequence after parity bit addition
[MECH662-matlab] 4

[Parity check]

Sample input output for Even Parity Check & Adding Parity Bit
(1)
Enter the Number of bits in the sequence to test for Odd parity
7
Enter the bit sequence one by one to test for Odd parity:
1
0
1
1
0
1
0
Parity bit generated : 1
Input bit sequence:
1 0 1 1 0 1 0

Bit sequence with parity (Odd) bit :


1 0 1 1 0 1 0 1

(2)
Enter the Number of bits in the sequence to test for Odd parity
7
Enter the bit sequence one by one to test for Odd parity:
1
0
1
1
0
1
1
Parity bit generated : 0
Input bit sequence:
1 0 1 1 0 1 1

Bit sequence with parity (Odd) bit :


1 0 1 1 0 1 1 0
Course Module
<Exercises >
1) Implement the programme with varied values of input

References and Supplementary Materials


Books and references
1. Wireless Communication Networks and Systems, Global Edition Stallings – 2018

Online Supplementary Reading Materials


● 1. Gordon L. Stüber ‘Principles of Mobile Communication’ springer publications 2016

● MainakChowdhury, ArumitaBiswas ‘Wireless Communication: Theory and


Applications’Oxford university press-2017
● UpenaDalal ‘Wireless communication and networks’ oxford university press-2015
Wireless Multimedia: A Guide to the IEEE 802.15.3 Standard

You might also like