Pages

Thursday 11 October 2012

Parity Check (Matlab 2012a)

Program:
clc;
clear all;
b = input('Enter the bit stream = ');
pr = input('Enter the error probability = ');
n = length(b);
c = 0;
for i = 1:n
        if(b(i)==1)
        c = c + 1;
        end
end
if(mod(c,2)~=0)
   b1 = [b ones(1,1)];
else
   b1 = [b zeros(1,1)];
end
l = length(b1);
disp('Input bit stream = ');
disp(b);
disp('Transmitting message sequence including parity bit = ');
disp(b1);
[ncode,err] = bsc(b1,pr);
disp('Received message sequence = ');
disp(ncode);
for i = 1:n
    if(ncode(l)~=b1(l))
        disp('Parity error');
        break;
    end
    if(ncode(i)~=b1(i))
        disp('Transmitted and received sequence does not match');
        break;
    else
        if(i==n)
       disp('Transmitted and received sequence match');
        end
    end
end


Output 1:


Enter the bit stream = [0 1 1 0 1 0]
Enter the error probability = 0.9
Input bit stream =
     0     1     1     0     1     0

Transmitting message sequence including parity bit =
     0     1     1     0     1     0     1

Received message sequence =
     1     0     0     1     1     1     1

Transmitted and received sequence does not match


Output 2:

Enter the bit stream = [0 1 1 0 1 0]
Enter the error probability = 0.7
Input bit stream =
     0     1     1     0     1     0

Transmitting message sequence including parity bit =
     0     1     1     0     1     0     1

Received message sequence =
     1     0     0     0     0     1     0


Parity error


Output 3:

 Enter the bit stream = [0 1 1 0 1 0]
Enter the error probability = 0.1
Input bit stream =
     0     1     1     0     1     0

Transmitting message sequence including parity bit =
     0     1     1     0     1     0     1

Received message sequence =
     0     1     1     0     1     0     1

Transmitted and received sequence match



No comments:

Post a Comment