DC Lab ITC Experiments
DC Lab ITC Experiments
AIM:
OUTPUT:
1 2 3 4
Enter the probabilities=[0.4 0.3 0.2 0.1]
dict =
[1] [ 1]
avglen =
1.9000
1.9000
binits/msg-sym
Entropy is:
1.8464
bits/msg-sym
Efficiency is:
97.1810
1 0 1 0 0 0 0 0 1
1 2 3 4
Hamming coding and decoding
Aim:
To write a program to encode binary data using a (7, 4)
Hamming code and decode it.
MATLAB CODE:
OUTPUT:
n =
k =
G =
1 0 0 0 1 1 1
0 1 0 0 1 1 0
0 0 1 0 1 0 1
0 0 0 1 0 1 1
H =
1 1 1 0 1 0 0
1 1 0 1 0 1 0
1 0 1 1 0 0 1
msg =
1 1 1 1
code =
1 1 1 1 1 1 1
recd =
1 1 0 1 1 1 1
syndrome =
1 0 1
errvect =
0 0 0 0 0 0 0
errvect =
1 0 0 0 0 0 0
search =
1 1 1
errvect =
0 0 0 0 0 0 0
errvect =
0 1 0 0 0 0 0
search =
1 1 0
errvect =
0 0 0 0 0 0 0
errvect =
0 0 1 0 0 0 0
search =
1 0 1
find =
index =
3
Position of error in codeword=3
correctedcode =
1 1 1 1 1 1 1
msg_decoded =
1 1 1 1
MATLAB CODE:
clc
K=3;
G1=7;
G2=5;
msg=[1 0 1 1 1];
trel=poly2trellis(K, [G1 G2])
disp('Message sequence:');
disp(msg);
coded=convenc(msg,trel);
disp('Encoder output:');
disp(coded);
tblen = length(msg);
decoded=vitdec(coded,trel, tblen,'trunc','hard');
disp('Decoder output:');
disp(decoded);
OUTPUT:
trel =
numInputSymbols: 2
numOutputSymbols: 4
numStates: 4
nextStates: [4×2 double]
outputs: [4×2 double]
Message sequence:
1 0 1 1 1
Encoder output:
1 1 1 0 0 0 0 1 1 0
Decoder output:
1 0 1 1 1
NOTE:
nextStates: [4×2 double] %[0,2;0,2;1,3;1,3]
outputs: [4×2 double] %[0,3;3,0;2,1;1,2]
Solution:
Encoder Diagram:
State Table:
2. Write a Program to obtain CRC code for the given data, using
CRC-CCITT polynomial
Program
#include <stdio.h>
#include <string.h>
void main()
{
int i,j,k,keylen,msglen,value;
char
data[100],ddata[100],out[100],recv[100],key[30],temp[30],quot[100
],rem[30], key1[30];
printf("Enter Data: ");
scanf("%s", &data);
printf("Enter Key: ");
scanf("%s", &key);
keylen=strlen(key);
msglen=strlen(data);
strcpy(ddata,data);
strcpy(key1,key);
for (i=0;i<keylen-1;i++)
{
data[msglen+i]='0';
}
for (i=0;i<keylen;i++)
temp[i]=data[i];
for (i=0;i<msglen;i++)
{
quot[i]=temp[0];
if(quot[i]=='0')
for (j=0;j<keylen;j++)
key[j]='0';
else
for (j=0;j<keylen;j++)
key[j]=key1[j];
for (j=keylen-1;j>0;j--)
{
if(temp[j]==key[j])
rem[j-1]='0';
else
rem[j-1]='1';
}
rem[keylen-1]=data[i+keylen];
strcpy(temp,rem);
}
strcpy(rem,temp);
printf("\nQuotient is ");
for (i=0;i<msglen;i++)
printf("%c",quot[i]);
printf("\nRemainder is ");
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);
strcat(ddata,rem);
printf("\nData to be transmitted is:%s\n", ddata);
printf("\n Enter the Received data:");
scanf("%s", &recv);
value=strcmp(ddata,recv);
if(value==0)
printf("Data is ERROR FREE\n");
else
printf("Error in received data\n");
return 0;
}
Output:
1. Enter Data: 110111011100
Enter Key: 1101
Quotient is 100010001001
Remainder is 101
Data to be transmitted is:110111011100101
Quotient is 100011011
Remainder is 111
Data to be transmitted is:110110101111