0% found this document useful (0 votes)
325 views

Ccn-Matlab Soft

This document provides information about bit stuffing and HDLC frames. It explains that bit stuffing is used to accommodate control signals by adding redundant data. The process involves inserting a '0' bit after every 5 consecutive '1' bits at the transmitter. The receiver counts the '1' bits and discards the next bit if it is a '0', knowing it is a stuffed bit rather than a control signal. An example HDLC frame format is also shown. The document then provides the algorithm for bit stuffing, which involves appending bits to an output sequence while counting '1' bits and inserting a '0' if the count reaches 5.

Uploaded by

Vishal Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
325 views

Ccn-Matlab Soft

This document provides information about bit stuffing and HDLC frames. It explains that bit stuffing is used to accommodate control signals by adding redundant data. The process involves inserting a '0' bit after every 5 consecutive '1' bits at the transmitter. The receiver counts the '1' bits and discards the next bit if it is a '0', knowing it is a stuffed bit rather than a control signal. An example HDLC frame format is also shown. The document then provides the algorithm for bit stuffing, which involves appending bits to an output sequence while counting '1' bits and inserting a '0' if the count reaches 5.

Uploaded by

Vishal Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 109

DEPARTMENT OF ELECTRONICS & COMMUNICATION

ENGINEERING

CMR INSTITUTE OF TECHNOLOGY


Department of Electronics & Communication
2005-06

LABORATORY CERTIFICATE
This
is
to
certify
that
Mr/Ms_________________________
bearing USN
___________has satisfactorily completed the
course
of
experiments
in
VLSI
&
MICROCONTROLLER Laboratory prescribed
by the VTU for 7th semester BE electronics &
communication course in the laboratory of this
college in the year 2005 2006.
DATE :

Signature of Teachers in charge


Signature of HOD

(Mrs.Indumathi)
2

CCN
& DSP Question Bank
1. Using MATLAB design an IIR low pass filter which has
maximally flat frequency response with the following
specifications:
Pass band ripple=0.5db
Pass band edge frequency=0.25
Stop band attenuation=15db
Stop band edge frequency=0.55
Use T=1 sec and impulse invariance transformation.
2. Using MATLAB design an IIR filter with pass band edge
frequency at 1500Hz and stop band edge at 2000Hz for a
sampling frequency of 8000Hz.passband attenuation is 1dB
and stop band attenuation is 15dB. Use butter worth prototype
design and bilinear transformation.
3. Using MATLAB design an IIR filter with pass band edge
frequency at 1500Hz and stop band edge at 2000Hz for a
sampling frequency of 8000Hz.passband attenuation is 1dB
and stop band attenuation is 15dB. Use chebysher prototype
design and bilinear transformation.
4. Using MATLAB design an IIR filter to meet the following
specifications by choosing hamming window.
Window length =227
Stop band attenuation =50dB
Cut-off frequency=100Hz
Sampling frequency =1000Hz
5. Using MATLAB compute the linear convolution of the given
two sequences. Also
compute the linear convolution, circular convolution using
function files.
X1 (n)=[1 2 2 1]
X2 (n) =[1 2 2 1]
6. Using MATLAB compute the circular convolution of the
given two sequences
using function files.
3

X1 (n)=[1 2 2]

X2 (n) =[1 2 2 1]

7
Using matlab for a given sequence x(n), compute the Ninput DFT using FFT
algorithms. Plot the magnitude and phase spectrum
from the DFT calculated, obtain the results of IDFT.
8. Using MATLAB sample a band limited continuous time signal
band limited to
fm= 400Hz under the following conditions:
1. Nyquist rate
2. twice the Nyquist rate
3. half the Nyquist rate
9. Using MATLAB compute the impulse response of a system
described by the
difference equation
y(n) 3/4 y(n-1) -1/8 y(n-2)= x(n)-1/3x(n-1)
10 .Write a C Program to simulate Bit-Stuffing and De-Stuffing for
a HLDC frame.
11. Write a C Program to simulate Character-Stuffing and DeStuffing for a HLDC
Frame.
12. Write a c program to simulate the shortest Algorithm for the
given network in the
graph form (the number of nodes should be greater than 6).
13. Write a C Program to encrypt a given text message using
substitution method and
decrypt it
14. Write a C Program to encrypt a given text message using
transposition method and
decrypt it
15. Write a C Program to simulate the Minimum Spanning Tree
using suitable algorithm
for the given network in the graph form (the number of nodes
should be at least 6).
16. Write a C Program to compute the Polynomial Code Checksum
for CRC-CCITT.
Verify the program for the cases a. with out error b. with error
introduced
4

17. Conduct an experiment to implement serial communication in


synchronous mode
using any two of the following media
1. Twisted pair 2. Fiber link
3. RS-232c
18. Conduct an experiment to implement serial communication in
asynchronous mode
using any two of the following media
1. Twisted pair 2. Fiber link
3. RS-232C
19. Find out the discrete time convolution of thee sequences
x (n) = {1 2 3 4 5 6 } and h (n) = {1 2 3 4 },
using Code Composer Studio. Verify the results graphically.
20. Perform Circular Convolution of the given sequence using
Code Composer Studio.
21. Compute the response of the system whose coefficients are
a0=0.1311, a1=0.2622,
a2=0.1311 and b0=1, b1=-0.7478, b2=0.2722, when the input
is a unit impulse
signal.
22. Using code composer studio compute of the system whose
coefficients are
a0=0.0051477, a1=0.010295, a2=0.005147, b0=1, b1=0.844881, b2=0.873965
and when the input is two sine waves of frequencies 3000Hz
and 400Hz. take
sampling frequency=24,000

Computer Communication
Networks
Contents
1. WRITE A C PROGRAM TO SIMULATE BIT-STUFFING AND
DE-STUFFING FOR A HLDC FRAME AND DISPLAY THE
5

STUFFED FRAME.

2. WRITE A C PROGRAM TO SIMULATE CHARACTERSTUFFING AND DE-STUFFING FOR A HLDC FRAME


DISPLAY THE CHARACTER STUFFED FRAME.

AND

3. ALGORITHM FOR THE GIVEN NETWORK IN THE GRAPH


FORM(THE NUMBER OF NODES SHOULD BE GREATER
THAN 6).
4. WRITE A C PROGRAM FOR ENCRYPTION
DECRYPTION OF A GIVEN MESSAGE.

AND

5. WRITE A C PROGRAM TO SIMULATE THE MINIMUM


SPANNING TREE USING SUITABLE ALGORITHM FOR THE
GIVEN NETWORK IN THE GRAPH FORM(THE NUMBER OF
NODES SHOULD BE AT LEAST 6).
6. WRITE A C PROGRAM TO COMPUTE THE POLYNOMIAL
CODE CHECKSUM FOR CRC-CCITT.

INTRODUCTION TO CCN
COMMUNICATION NETWORKS

The transmission channels interconnecting all client and server


stations as well as all supporting hardware and software.
A telecommunications network is a network of telecommunications
links arranged so that messages may be passed from one part of the
network to another over multiple links.
Telecommunications network links may in turn be built out of
hierarchical transmission systems.
Examples of telecommunications networks are:

Computer network
the Internet
the Public switched telephone network
the global Telex network

Data
communications,
application
of
telecommunications
technology to the problem of transmitting data, especially to, from, or
between computers. In popular usage, it is said that data
communications make it possible for one computer to talk with
another. Telephone circuits are often used to transfer data, although
their relatively limited bandwidth makes them relatively slow paths
for data. Recent techniques, however, have made it possible to send
data over phone lines at rates of 28,800 bits per second and higher. A
modem is required for such telephone communications when they
occur over standard (analog) telephone circuits. Where cost can be
justified, high speed data links are constructed; these are often fiberoptic or coaxial cables designed for wide frequency range, or
microwave, radio links. Local-area and wide-area networks link
computers together so that they can transfer and share data. Because
many computers can be on the network at any given time, techniques
such as time-division multiplexing are used; each computer is
assigned a short time slot during which it can use the full bandwidth
of the network. Packet switching allows a single channel to be used
for multiple concurrent transmissions. Data packets contain addresses
that indicate the intended destination. To minimize datacommunication errors, special codes are used.

Network Topologies

1.WRITE A C PROGRAM TO SIMULATE BIT


STUFFING AND
DE-STUFFING USING

HDLC

THEORY
Digital communication has its advantages of speed, reliability,
etc but with it comes the problem of control signals. In analog
communication the modulation technique used can be used to
generate control signals. Like in FDM 3 frequencies can be
used: one frequency for a 'low', another one for a 'high' and
finally a third frequency for a control signal. But it isn't possible
in digital communication.
Bit patterns or bytes can be reserved for control signals. These
control signals can not be present in normal data. This can be
achieved for ASCII text or if a few bit patterns are used as data.
But when the whole set of bit patterns or ASCII values are
used, the special control singnals can not be present in data and
if present should not be interpreted as control signals but be
interpreted as data. This is the reason we use stuffing.
Stuffing is a process of adding redundant information or
increasing the amount of data transmitted in order to
acomodate control signals.
This is used when a bit oriented communication syatem is used.
Let us consider the control signals of frame started/end. We give
them a representation of 0111 1110. So now if this is present in
the data we are transmitting we change this pattern so that it no
longer matches the control signals of frame start/end. Each time
we see five ones (1s) at the transmitter we append 0 instantly so
that six ones (1s) can never exist. An argument can be raised
about the fact why should we add the 'zero' after 5 ones if the
6th bit was a 0 and not a 1. The reason is simlpe enough - the
receiver cannot differentiatebetween that 0 which is data and a
stuffed 0.
For example,
0111110 can now be interpreted as
0111 1110
(assuming 0 is stuffed 0)
0111 1101 (assuming 0
as data).
So once its settled that every 5 ones has a zero following it
irrespective of the next bit being a 0 or 1 lets see what the
receiver has to do. The receiver keeps a count of the ones and
each time it receives 5 ones it discards the next bit if its a 0 bit
9

which is the stuffed 0 bit and knows this isn't a control signal
but if the bit after 5 ones is also 1 its a frame end/start.
HDLC Frame
The high level data link control protocol is a bit oriented
protocol which uses bit stuffing for data transparency. HDLC
frame is as shown

011111 ADDRES CONTRO DATA


10
S
L

CHECKSU 011111
M
10

The control field is used for sequence numbers and


acknowledgements and other purposes. The data field may
contain arbitrary information. The checksum field is a minor
variation of the CRC code using CRC-CCITT as a generator.
Frames are delimited by 0111 1110 and this sequence is not
allowed in the data field.

ALGORITHM
1. Input data sequence.
2. Add start to frame to output sequence.
3. For every bit in input
a). Append bit to output sequence.
b). Is bit a 1?
Yes
Increment count.
If count is 5, append 0 to output
sequence and reset count.
No
Set count to zero.
4. Add stop to frame bits to output sequence.

SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 1000
void main()
{
int si=0,di=0,count=0;
char src[MAX],dest[MAX];

10

char flag[MAX]="01111110";
clrscr();
printf("Enter the msg bits\n");
scanf("%s",src);
di=strlen(flag);
strcpy(dest,flag);
while(src[si]!='\0')
{
if (src[si]=='1')
count++;
else
count=0;
dest[di++]=src[si++];
if (count==5)
{
count=0;
dest[di++]='0';
}
}
dest[di++]='\0';
printf("Stuffed message is %s",strcat(dest,flag));
si=strlen(flag);
for (di=0;si<strlen(dest)-2*si-1;si++,di++)
src[di]=dest[si];
count=0;
si=0;di=0;
while(src[si]!='\0')
{
if (src[si]=='1')
count++;
else
count=0;
dest[di++]=src[si++];
if (count==5)
{
count=0;
dest[di++]=src[si++];
}
}
dest[di]='\0';
printf("\nDestuffed msg is %s",dest);
getch();
}

OUTPUT:
1.
Enter the msg bits 01111111
Stuffed message is 0111111001111101101111110
Destuffed msg is
01111111
2.
Enter the msg bits 0110111111
Stuffed message is 011111100110111110101111110
Destuffed msg is
0110111111

11

2.WRITE A C PROGRAM TO SIMULATE CHARACTER


STUFFING
AND
DE-STUFFING
USING
HDLC
THEORY
Bit stuffing seems to be a foolproof plan but sometimes the
communication system cannot handle bits but can only manipulate bytes
(8 bits).In these cases we assume an ASCII set. The main control signals
are ETX (End text), STX (start text), DLE (Data link Escape).Other
control signals are also present like SOH (start of header), EOT (End of
transmission) etc but we will restrict the discussion to ETX, STX, DLE.
The principle remains the same STX (ASCII 02) denotes a start of data
and ETX (ASCII 03) the end of text. Incase ETX or the byte 03 happens to
be present in data it should be treated as data and not end of text.
Similar is the case for STX. To make sure this happens we use another
ASCII value called DLE (ASCII 16). Each time we see a STX in data we
make it DLE STX and an ETX is made into DLE ETX. So if we receive an
ETX or a STX and the previous ASCII value isnt DLE we know its a
frame start/end. Consider the case when DLE was the last data byte. The
end of text will now become as data as the receiver will get DLE ETX. So
now even DLE is stuffed. So each time transmitter sees DLE it makes it
DLE DLE.

12

ALGORITHM
1. Input data sequence
2. Add start of frame to output sequence (DLE STX)
3. For every character in input
a. Append character to output sequence
b. Is character DLE?
Yes:
Add DLE to output sequence
4. Add stop of frame chars to output sequence

SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define max 100
void main()
{
int si=0,di=0;
char src[max],des[max];
char flag1[max]="DLESTX",flag2[max]="DLEETX";
clrscr();
printf("Enter the string data\n");
scanf("%s",&src);
/*STUFFING PROCESS*/
strcpy(des,flag1);
di=strlen(flag1);
while(src[si]!='\0')
{
if(src[si]=='D'&&src[si+1]=='L'&&src[si+2]=='E')
{
des[di+0]='D',des[di+1]='L',des[di+2]='E',des[di+3]='D
',des[di+4]='L',des[di+5]='E';
di+=6;
si+=3;
}
else
des[di++]=src[si++];
}
des[di]='\0';
strcat(des,flag2);
printf("The stuffed string is %s\n",des);
/*DE-STUFFING PROCESS*/
di=strlen(des)-strlen(flag2);
des[di]='\0';
di=strlen(flag1);
for(si=0;des[di]!='\0';si++,di++)
src[si]=des[di];

13

si=di=0;
while(src[si]!='\0')
{
if(src[si+0]=='D'&&src[si+1]=='L'&&src[di+2]=='E'&&src
[si+3]=='D'&&src[si+4]=='L'&&src[di+5]=='E')
{
des[di]='D',des[di+1]='L',des[di+2]='E';
di+=3;
si+=6;
}
else
des[di++]=src[si++];
}
des[di]='\0';
printf("The destuffed string is %s",des);
getch();
}

OUTPUT:
1.

Enter the string data


The stuffed string is

ABCDLE
DLESTXABCDLEDLEDLEETX

The destuffed string is ABCDLE


2.

Enter the string data


The stuffed string is

ABCDEFGH
DLESTXABCDEFGHDLEETX

The destuffed string is ABCDEFGH

3.WRITE A C PROGRAM TO SIMULATE THE SHORTEST


PATH
ALGORITHM

THEORY
All packets need to be routed from the source to thedestination and in most
cases multiple hops are required.Routing algorithms are required to decide on
which output line and incoming packet should be forwarded onto.
Two types of routing algorithms now come in-one where the decision is fixed
and one where the route is constantly being recalculated for the best route in
other words static and dynamic routing algorithms or non-adaptive and
adaptive algorithms. Routing algorithms can be may to adapt to average
traffic/loss/delay/distance/queue length etc.
Dijkstras method of computing the shortest path is a static routing algorithm.
It involves building a graph of the subnet, with each node of the graph
representing a router and each arc representing a communication line or a link.
14

To find a route between a pair of routers the algorithm just finds the shortest
path between them on the graph.
In Dijkstras algorithm the metric used for calculation is distance. Each node
is labeled with its distance from the source node along with the previous node
in the path. Initially, no paths are known so all nodes are labeled with infinity.
As the algorithm proceeds and paths are found, the labels may change,
reflecting better paths.
A label may be either tentative or permanent. Initially, all nodes are tentative
and once it is discovered that the shortest possible path to a node is got it is
made permanent and never changed after that.

ALGORITHM
1.
2.
3.
4.
5.
6.
7.
8.
9.

Input graph data.


Make all nodes TENTATIVE.
Input source, destination.
Make source, the working node.
Make the working node PERMANENT.
Check all tentative nodes, which are connected to working node, update
weight if required.
Find TENTATIVE node with smallest weight. Make this the new
working node.
If working node is destination, go to step 8 else go to step 4.
Trace back from destination to source.

SOURCE CODE:
#include<stdio.h>
#include<conio.h>
int p[10][10];
void main()
{
int i,j,k,n,pn,t;
int m[10][10],w[10][10];
void path(int i,int j);
clrscr();
printf("Enter no of nodes:");
scanf("%d",&n);
printf("\n Enter the node connection matrix");
printf("\n To indicate no connection between two nodes,enter weight as 100\n\n");
\* Prints the outline of the matrix*\
for (i=1;i<=n;i++)
printf("\t %d",i);
for (i=1;i<=n;i++)
{

15

printf("\n %d \t",i);
\* Takes the entered values as input*/
for (j=1;j<=n;j++)
{
scanf("%d",&w[i][j]);
m[i][j]=w[i][j];
p[i][j]=0;
}
}
for (i=1;i<=n;i++)
m[i][j]=0;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if (m[i][k]+m[k][j]<m[i][j])
{
m[i][j]=m[i][k]+m[k][j];
p[i][j]=k;
}
do
{
printf("\n Enter the source and destination nodes\n");
scanf("%d %d",&i,&j);
printf("\n The weight is %d",m[i][j]);
printf("\n The path is ");
printf("%d--->",i);
path(i,j);
printf("%d",j);
printf("\n to repeat press R");
}while (getch()=='R');
void path(int i,int j)
{
int k;
k=p[i][j];
if (k!=0)
{
path(i,k);
printf("%d-->",k);
path(k,j);
}}

OUTPUT:

16

Enter no of nodes 7
Enter the node connection matrix
1

1
100

2
2

3
1

4
100

5
100

6
4

7
100

100

100

100

100

100

100

100

100

100

100

100

100

100

100

100

100

100

100

100

100

100

100

100

Enter the source and destination nodes


1
7
The weight is 7
The path is 1-->3-->5-->7
To repeat press R

4.WRITE A C PROGRAM FOR ENCRYPTION AND DECRYPTION


OF A

GIVEN MESSAGE
17

THEORY
In cryptography, the messages to be encrypted, known as plaintext, are
transformed function that is parameterized by a key. The output of the encryption
process, known as ciphertext, is then transmitted, often by messenger or radio.
The art of breaking ciphers is called cryptanalysis. The art of devising ciphers
(cryptography) and breaking them (cryptanalysis) is collectively known as
cryptology.
Encryption methods are historically divided into two categories: substitution
ciphers and transposition ciphers.
Substitution ciphers
In a substitution ciphers, each letter or group of letters is replaced by another
letter or group of letters to disguise it . A way to do this is to have each of the
symbols in the plaintext, say the 26 letters for simplicity, map onto some other
letter. For example,
Plaintext: a b c d e f g h i j k l m n o p q r s t u v w x y z
Ciphertext: Q W E R T Y U I O P A S D F G H J K L Z X C V B N M
This general system is called a mono-alphabetic substitution with the key being
the 26-letter string corresponding to the full alphabet. For the key above, the
plaintext, attack would be transformed into the Ciphertext QZZQEA.
Transposition Ciphers
Substitution ciphers preserve the order of the plaintext symbols but disguise the.
Transposition Ciphers, in contrast, reorder the letters, but do not disguise them.
The figure below depicts a common transposition cipher, the columnar
transposition. The cipher is keyed by a word of phrase not containing any
repeated letters. In this example, MEGABUCK is the key. The purpose of the
key is to number the columns, column one being under the letter closest to the
start of the alphabet and so on. The plaintext is written horizontally in rows. The
cipher is readout by columns starting with the column whose key letter is the
lowest.

Plain text:
Pleasetransferonemilliondollarstomyswissbankaccountsixtwotwo
18

MEGA B U CK
p l e a s e t r
a n s f e r o n
e m i l l i o n
d o l l a r s t
o m y s w i s s
b a n k a c c o
u n t s i x t w
o t w o a b c d
Ciphertext:
AFLLSKSOSELAWAIATOOSSCTCLNMOMANTESILYNTWRNNTSOWDP
AEDBUOERIRICXB.

ALGORITHM
Encryption by substitution method
1. Read data to be encoded
2. For every character of data
a. If data is between a and z
Set encoded data to uppercase character from key
b. If data is between A and Z.
Set encoded data to lowercase character from key
c. If data between 0 and 9.
Set encoded data to digit from key
d. Else copy data into encoded datas array.
3. Print encoded data.
Decryption by substitution method
1. Read encrypted data.
2. For every character of data.
a. Scan through key to see if data is present.
(i)
If present get index of character add it to a if data is uppercase
else A if it is in lowercase else 0 if it is a digit.
(ii) If not present copy data into decoded datas array.
3. Print decoded data

Encryption by transposition method.


1.

Get sequence of characters in cipher i. e. MEGABUCK.

19

2.
3.
4.
5.

Get data to be decoded.


Arrange data horizontally under MEGABUCK.
Add . to make last row complete
For every column of MEGABUCK
a. Find next column to send using sequence.
b. Send data under this header i.e. print the data under this letter.
c. Jump back to 5 till all columns are not done.

Decryption by transposition method


1. Get sequence of characters in word i.e. MEGABUCK.
2. Get data to be decoded.
3. See if input as a multiple of length of word characters. If its not a multiple print
that it is an error and quit.
4. Find position of first character i.e. A.
5. Put size of data size of word characters underneath it.
6. Do step 4 to 5 for all characters of MEGABUCK in alphabetical order.
7. Print all characters row wise starting from M to K.

SOURCE CODE:
/*Encryption and De-cryption using Substitution method*/
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<math.h>
void main()
{
int encry,decry,ci;
char plain[100]=" ",cipher[100]="
clrscr();
printf("Enter the text\n");
printf("--------------\n");
gets(plain);

";

/*Encryption Process*/
while(1)
{
printf("Enter the key for encryption(between
1 and 25)\n");
scanf("%d",&encry);
if(encry<1||encry>25)
printf("\nInvalid key");
else
break;
}
for(ci=0;plain[ci]!='\0';ci++)
{
if(isalpha(plain[ci]))
{

20

if(isupper(plain[ci]))
cipher[ci]=(plain[ci]'A'+encry)%26+'A';
else
cipher[ci]=(plain[ci]'a'+encry)%26+'a';
}
else
cipher[ci]=plain[ci];
}
printf("Text after encryption is %s",cipher);
/*Decryption process*/
while(1)
{
printf("\nEnter the decryption key(between 1
and 25)\n");
scanf("%d",&decry);
if(decry==encry)
break;
else
printf("\nKey is wrong. Re-enter
key\n");
}
for(ci=0;cipher[ci]!='\0';ci++)
{
if(isalpha(cipher[ci]))
{
if(isupper(cipher[ci]))
plain[ci]=(cipher[ci]-'A'decry+26)%26+'A';
else
plain[ci]=(cipher[ci]-'a'decry+26)%26+'a';
}
else
plain[ci]=cipher[ci];
}
printf("Text after decryption is %s",plain);
getch();
}

OUTPUT:
Enter the text CMRIT
Enter the key for encryption(between 1 and 25)=5
Text after encryption is HRWNY
Enter the decryption key(between 1 and 25)=5
Text after decryption is CMRIT

SOURCE CODE:

21

/*Encryption and De-cryption using Transposition method*/


#include<ctype.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 1000
\* Function for Encrytion as well as De-cryption (if oper=1 is passed the it is encryption and if
oper=2 is passed then it is decryption)*\
void transpose(char *src,char *key,char *dest,int
oper)
{
int klen,plen,ch,i,j,k=0;
klen=strlen(key);
plen=strlen(src);
if ((plen%klen)!=0)
{
for (ch='A';(plen%klen)!=0;ch++)
src[plen++]=ch;
src[plen]='\0';
printf("\nAfter extending %s\n",src);
}
for (ch='A';ch<='Z';ch++)
{
for (i=0;i<klen;i++)
if (toupper(key[i])==ch)
for (j=i;j<plen;j+=klen)
if (oper!=0)
dest[k++]=src[j];
else
dest[j]=src[k++];
}
dest[k]='\0';
}
void getkey(char *msg,char *key)
{
int i;
while(1)
{
printf("\n%s",msg);
gets(key);
for (i=0;i<strlen(key);i++)
if(!isalpha(key[i]))
break;
if(i!=strlen(key))
printf("\nBad input key\n");
else
break;
}
}
\* Main Program*\
void main()
{

22

int len;
char plain[MAX],cipher[MAX],key[MAX];
clrscr();
printf("Encryption & decryption using
transposition\n");
printf("Enter the plain text\n");
gets(plain);
len=strlen(plain);
getkey("\nEnter key for encryption\n",key);
transpose(plain,key,cipher,1);
printf("\nnAfter encryption %s\n",cipher);
getkey("\nEnter key for decryption\n",key);
transpose(cipher,key,plain,0);
plain[len]='\0';
printf("\nAfter decryption %s\n",plain);
getch();
}

OUTPUT:
Encryption & decryption using transposition
Enter the plain text TRANSFER ONE CRORE RUPEES
Enter key for encryption MEGABUCK
After extending TRANSFER ONE CRORE RUPEESABCDEFG
After encryption NERCS UDEREFRDEAAN BROEGT RSFCPE
Enter key for decryption MEGABUCK
After decryption TRANSFER ONE CRORE RUPEES

5.WRITE A C PROGRAM TO FIND MINIMUM SPANNING


TREE OF A

SUBNET
23

THEORY
A spanning tree is a graph is just a sub-graph that contains all
the vertices and is a tree. A graph may have many spanning
trees. For instance, a complete graph 4 nodes can have 16
spanning trees. Suppose, the edges of the graphs have weights
or lengths, the weight of the trees is the some of its edges.
Obviously, different trees have different lengths.
A spanning tree includes all the routers, but contains no loops.
If each router knows which of its lines belong to the spanning
trees, it can copy and incoming broadcast packet onto all the
spanning trees lines except the one it arrived on. This method
makes excellent use of bandwidth, generative the absolute
minimum number of packets necessary to do the job. The only
problem is that each router must have knowledge of some
spanning tree for it to be applicable. Sometime this information
is available (e.g. with link state routing), but sometimes it is not
(e.g. with distance vector routing).

ALGORITHM
1.
2.
3.
4.
5.

Input number of vertices.


Input the edge weights.
Sort the edge weights in ascending order.
Pick the lowest edge and joined the corresponding vertices.
Repeat till edges are marked making sure that there are no
close loop.
6. Display selected edges.

SOURCE CODE:
#include<conio.h>
#include<stdio.h>
int p[10][10];
void main()
{
int i,j,k,z=900,x,y,n,flag,wt=0;
int m[10][10],w[10][10];
int chkcl(int,int,int,int);
clrscr();
printf("Enter the number of nodes\n");
scanf("%d",&n);
printf("\nEnter the node connection matrix\n");
for (i=1;i<=n;i++)
printf("\t%d",i);
for (i=1;i<=n;i++)

24

{
printf("\n%d\t",i);
for (j=1;j<=n;j++)
{
scanf("%d",&w[i][j]);
p[i][j]=w[i][j];
m[i][j]=0;
}
}
for (i=1;i<=n;i++)
{
x=100;
for (j=1;j<=n;j++)
{
if (p[i][j]<x)
{
flag=chkcl (i,j,n,z);
if (flag==1)
continue;
m[i][j]=1;
for (y=1;y<j;y++)
m[i][y]=0;
k=j;
x=p[i][j];
}
}
if (p[i][k]<100)
wt=wt+p[i][k];
p[i][k]=150;
p[k][i]=p[i][k];
}
printf("\nThe tree is \n");
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
if (m[i][j]!=0)
printf("%d--->%d\n",i,j);
printf("The weight is %d\n",wt);
getch();
}
int chkcl(int i,int j,int n,int k)
{
int t,flag;
for (t=1;t<=n;t++)
{
if ((p[i][t]==150)&&t!=k)
{
if (t==j)
return (1);
else
{
k=i;
flag=chkcl(t,j,n,k);
if (flag==1)
return (1);
}
}

25

}
return (0);
}

OUTPUT:

Enter the number of nodes 5


Enter the node connection matrix
1

1
2
100 2

3
3

4
5
100 4

100 100 5

100

100 100 7

100 5

100 100

100 8

100 100

The tree is
1-->2
2-->4
3-->1
5-->1

26

The weight is 14

6.WRITE A C PROGRAM TO COMPUTE POLYNOMIAL CODE


CHECKSUM
FOR CRC-CCITT
THEORY
The polynomial code (also known as a cyclic redundancy code or
CRC code) is widely used. Polynomial codes are based upon
treating bit strings as representations of polynomials with
coefficients of 0 and 1 only. A k-bit frame is regarded as the
coefficient list for a polynomial with k terms, ranging from x k-1
to x0. Such a polynomial is said to be of a degree k-1. The high
order ( left most) bit is the coefficient of x k-1 ; the next bit is the
coefficient of x k-2 , and so on. For example, 110001 has 6 bits
and thus represents a six-term polynomial with coefficients 1,1,
0,0,0 and 1: x5 + x4+ x0 .
When the polynomial code method is employed, the centre and
receiver must agree upon a generator polynomial, G(x) in
advance, both the high and low order bits of the generator must
be one. To compute the checksum for some frame with m bits,
corresponding to the polynomial M (x), the frame must be
longer than the generator polynomial. The idea is to append a
checksum to the end of the frame in such a way that the
polynomial represented by the checksummed frame is divisible
by G(x). When the receiver gets the checksummed frame, it
tries dividing it by G(x). If there is a remainder there has been a
transmission error.

ALGORITHM
27

1. Let r be the degree of G(x). Append r zero bits to the low order
end of the frame, so it now contains m+r bits and corresponds
to the polynomial xr M(x).
2. divide the bit string corresponding to G(x) into the bit string
corresponding to xr M (x) using modulo-2 division.
3. Subtract the remainder (which is always r or fewer bits) from
the bit string corresponding to xr M(x) using modulo-2
subtraction. The result is the checksummed frame to be
transmitted. Call its polynomial T(x).
The CRC-CCITT polynomial is x16 + x12+x5+1

SOURCE CODE:
#include<stdio.h>
#include <conio.h>
#define degree 16
int res[30];
int getnext(int array[],int);
void crc(int len)
{
int cp[]={1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1};
int i=0,pos=0,newpos;
while(pos<len-degree)
{
for(i=pos;i<pos+degree+1;++i)
res[i]=res[i]^cp[i-pos];
newpos=getnext(res,pos);
if(newpos>pos+1)
pos=newpos-1;
++pos;
}
}
int getnext(int array[],int pos)
{
int i=pos;
while(array[i]==0)
++i;
return i;
}
void main()
{
int array[30];
char ch;
int len,i=0;
clrscr();
puts("Enter the data stream:");
while((ch=getche())!='\r')
array[i++]=ch-'0';
len=i;
for(i=0;i<degree;++i)
array[i+len]=0;
len+=degree;

28

for(i=0;i<len;i++)
res[i]=array[i];
crc(len);
printf("\nThe transmitted frame is: ");
for(i=0;i<len-degree;++i)
printf("%d",array[i]);
for(i=len-degree;i<len;++i)
printf("%d",res[i]);
printf("\nEnter the stream for which crc is to be checked");
i=0;
while((ch=getche())!='\r')
array[i++]=ch-'0';
len=i;
for(i=0;i<len;i++)
res[i]=array[i];
crc(len);
printf("\ncheck sum:");
for(i=len-degree;i<len;i++)
printf("%d",res[i]);
getch();
}

OUTPUT:
(Without Error)
Enter data stream 10011
Transmitted frame is: 100110000001000010000
Enter the stream for which crc to be checked 100110000001000010000
Check sum: 0000000000000000
(With Error)
Enter data stream 10011
Transmitted frame is: 100110000001000010000
Enter the stream for which crc to be checked 100110000001000010001
Check sum: 0000000000000001

29

30

CONTENTS
I. Introduction to MATLAB...3
II. Verification of Sampling
Theorem..8

III. Finding the Impulse Response of a given system...


10

IV. Convolution of two given finite length sequences(linear and


circular).12

V. To obtain the FFT and IFFT for a given sequence


sequence...15

31

VI. Realization of IIR


filters...19

VII. Realization of FIR


filters...22

INTRODUCTION TO MATLAB
MATLAB stands for matrix laboratory .It is a technical computing environment
for high performance numeric computation and visualization.
MATLAB integrated numerical analysis, matrix computations, signal processing
and graphics in an easy-to-use environment.

32

There are also several optional TOOLBOXES available from the MATLAB.
These toolboxes are collection of functions written for special applications such
as symbolic computations, image processing, statistics, and control system design,
neural networks etc.

ACTUAL EXAMPLES:
>>
>>2+2
ans=
4
>>area=pi*2.15^2
area= 14.5220

MATLAB prompt
Command
MATLAB response

ON-LINE HELP:
ON LINE DOCUMENTATION :
MATLAB provides online help for all its built in functions and programming
language constructs.
DEMO :
MATLAB has a demonstration program that shows many of its features. The
program includes a tutorial introduction .Type demo at the matlab prompt to
invoke the demonstration program and follow the instruction on the screen.
Type help category in MATLAB with the appropriate category name, provides a list
of functions and commands in that category.
Example:
>> help fft
FFT Discrete Fourier transform.
FFT(X) is the discrete Fourier transform (DFT) of vector X. For
matrices, the FFT operation is applied to each column. For N-D
arrays, the FFT operation operates on the first non-singleton
dimension.
FFT(X,N) is the N-point FFT, padded with zeros if X has less
than N points and truncated if it has more.
FFT(X,[],DIM) or FFT(X,N,DIM) applies the FFT operation across the
dimension DIM.
For length N input vector x, the DFT is a length N vector X, with elements
N
X(k) =

x(n)*exp(-j*2*pi*(k-1)*(n-1)/N); 1kN.
n=1

33

The inverse DFT (computed by IFFT) is given by


N
x(n) = (1/N)

X(k)*exp( j*2*pi*(k-1)*(n-1)/N), 1 <= n <= N.


k=1

34

35

MATLAB WINDOWS
MATLAB works through three basic windows,
1. COMMAND window
2. GRAPHICS or FIGURE window
3. EDITOR window
1. COMMAND WINDOW:
This is the main window .It is characterized by the MATLAB command prompt
>>.
When you launch an application program, MATLAB puts you in this window. All
commands including those for running user written programs are typed in this
window at the MATLAB prompt.

2. GRAPHICS or FIGURE WINDOW :

The output of all the graphics commands typed in the command window are
flushed to the graphics or figure window.
The user can create as many figure windows as the system memory will allow.

36

3. EDITOR WINDOW:

This is where you write, edit, create, and save your own programs in files
called m-Files .
MATLAB provides its own built in editor .

MATLAB FILE TYPES


MATLAB has three types of files for storing information:
1. M-files.
2. MAT-files.
3. MEX-files.
1. M-FILES:
They are standard ASCII text files with an .m extension to the file name. There are
two types of m-files namely script file and function file.
2. MAT-FILES:
These are binary data files, with a .mat extension to the file name. MAT files are created
by MATLAB when you save the data with the save command. The data is written in a
special format that only MATLAB can read.
3. MEX_FILES:
These are MATLAB callable FORTRAN and c programs with an .mex extension to the
filename.

37

PROGRAM 1 :

Verification of Sampling Theorem

THEORY:
Sampling Theorem can be stated in two forms If a finite energy signal g(t) contains no frequencies higher than
w Hz, it is completely determined by specifying its ordinates at
a sequence of points spaced 1/2w sec apart.
If a finite energy signal g(t) contains no frequencies higher than
w Hz, it may be completely recovered from its ordinates at a
sequence of points spaced 1/2w sec apart.
The minimum sampling rate of 2w samples per second, for a signal
bandwidth of wHz is called NYQUIST RATE.
s = 2m
where,
s=Sampling Frequency
m=Message frequency
We encounter these conditions in Sampling Theorem, they are Right
sampling, Under sampling and Over sampling
.
Right Sampling s = 2m
Under Sampling s 2m
Right Sampling s 2m

PROBLEM:
Using MATLAB, sample a band limited continuous time signal,
band limited to fm=400Hz under the following conditions:
1.
Nyquist rate
2.
Under sampling
3.
Over sampling

38

MATLAB CODE:
%Nyquist Rate Sampling
s=800;
t=0:1/ s:256/ s;
X=sin(2*pi*400*t);
Xm=abs(fft(X));
K=0:length(X)-1;
Subplot(2,2,1);
Stem(k,Xm);

%Specify time period


%Specify msg signal
%abs=Computes absolute value
%fft=Computes the discrete fourier transform
coefficients
%stem=Plots the data sequence as stems from
x-axis terminated with circles for the datavalue

xlabel(Hz);
ylabel(Magnitude);
title(Nyquist Rate Sampling);
%Under Sampling
s=200;
t=0:1/ s:256/ s;
X=sin(2*pi*400*t);
Xm=abs(fft(X));
K=0:length(X)-1;
Subplot(2,2,2);
Stem(k,Xm);

%Specify time period


%Specify msg signal
%abs=Computes absolute value
%fft=Computes the discrete fourier transform
coefficients
%stem=Plots the data sequence as stems from
the x-axis terminated with circles for
the data value

xlabel(Hz);
ylabel(Magnitude);
title(Under Sampling);
%Over Sampling
s=1000;
t=0:1/ s:256/ s;
X=sin(2*pi*400*t);
Xm=abs(fft(X));
K=0:length(X)-1;
Subplot(2,2,3);
Stem(k,Xm);

%Specify time period


%Specify msg signal
%abs=Computes absolute value
%fft=Computes the discrete fourier transform
coefficients
%stem=Plots the data sequence as stems from
the x-axis terminated with circles for the
data value

xlabel(Hz);
ylabel(Magnitude);
title(Over Sampling);

39

OUTPUT:

40

PROGRAM 2:

Impulse Response of a given system

THEORY:
A complete characterization of any LTI system can be represented in
terms of its response to an Unit Impulse, which is referred to as
Impulse response of the system. Alternatively, the impulse response is
the output of a LTI system due to an impulse input applied at t=0, or
n=0.

PROBLEM:
Obtain the Impulse response of a system described by the
difference equationy(n)-3/4 y(n-1)+1/8 y(n-2) = x(n)-1/3 x(n-1)
Solution:
Y(z) - 3/4 Y(z)z-1 + 1/8 Y(z)z-2 = X(z) - 1/3 X(z) z-1
H(z) = Y(z) / X (z) = (1-1/3 z-1) / (1-3/4 z-1+1/8 z-2)
Applying partial fractions ,
-1

H(z) = (1-1/3 z-1) / (1-1/2 z-1)(1-1/4 z-1) = A / (1-1/2 z-1) + B / (1-1/4

z )
A=2/3;
B=1/3;
H(z) = (2/3) / (1-1/2 z-1) + (1/3) / (1-1/4 z-1)
h(n) = (2/3) (1/2)n u(n) + (1/3) (1/4)n u(n)
h(0)=1
h(4)=0.0429
h(1)=0.416
h(5)=0.02116
h(2)=0.187 h(6)=0.0105
h(3)=0.088 h(7)=0.0052

h(8)=0.0026
h(9)=0.0013

41

MATLAB CODE:
b=input('type in numerator coeff=');
a=input('type in denominator coeff=');
[h,t]=impz(b,a,6)
stem(t,h);
grid;
xlabel('time index');
ylabel('amplitude');
title('impulse response');

INPUT:
Type in numerator coeff=[1 -1/3]
Type in denominator coeff=[1 -3/4 1/8]

OUTPUT:

42

PROGRAM 3:

Convolution of two given finite length sequences(Linear and


Circular)

THEORY:

DEFINITION OF CONVOLUTION:
The convolution a * b of two functions a and b is defined as:

The asterisk operator is used to denote convolution. Many computer systems, and people
who frequently write mathematics on a computer will often use an asterisk to denote
simple multiplication (the asterisk is the multiplication operator in many programming
languages), however an important distinction must be made here: The asterisk operator
means convolution.
The output using the convolution operation, is: y(t) = x(t) * h(t)

SYSTEMS AND CONVOLUTION:


Let us say that we have the following block-diagram system:
-------x(t) ---->| h(t) |----> y(t)
--------

x(t) = input
h(t) = impulse response
y(t) = output

Where x(t) is the input to the circuit, h(t) is the circuit's impulse response, and y(t) is the
output. Here, we can find the output by convoluting the impulse response with the input
to the circuit. Hence we see that the impulse response of a circuit is not just the ratio of
43

the output over the input. In the frequency domain however, component in the output
with frequency is the product of the input component with the same frequency and the
transition function at that frequency. The moral of the story is this: the output to a circuit
is the input convoluted with the impulse response.

LINEAR CONVOLUTION:
Let x1(n) be the input sequence and h(n) be the impulse response of the system as shown
below.i.e
y(n)=x1(n)*h(n)
:where y(n) is the output sequence..
X1(n)

h(n)

y(n)

CIRCULAR CONVOLUTION:
Let x(n) and h(n) be the two sequences of length N.
Then,

y(n) = x(n) ( * ) N h (n)


= m=0N-1 x((n-m))N h(m); 0nN-1
y(n)= m=0N-1 x(m) h ((n-m))N
MATLAB CODE:
x1=input('first sequence=');
x2=input('second sequence=');
%linear convolution
y1=conv(x1,x2)
%circular convolution
l1=length(x1);
l2=length(x2);
n1=max(l1,l2);
y2=circonv(x1,x2,n1)
%circular using linear convolution
n2=l1+l2-1;
y3=circonv(x1,x2,n2)
subplot(3,1,1);
n1=0:1:length(y1)-1;
stem(n1,y1);
xlabel('time index');
ylabel('amplitude');
title('linear convolution');
subplot(3,1,2);
n2=0:1:length(y2)-1;
stem(n2,y2);
xlabel('time index');
ylabel('amplitude');
title('circular convolution');
subplot(3,1,3);
n3=0:1:length(y3)-1;
stem(n3,y3);

44

xlabel('time index');
ylabel('amplitude');
title('circular with linear');

FUNCTION FILE FOR CIRCULAR CONVOLUTION:


function[y]=circonv(x1,x2,n1)
l1=length(x1);
l2=length(x2);
if(n1<max(l1,l2))
error('n1 must be>=max(l1,l2)');
end
x1=[x1,zeros(1,n1-l1)];
x2=[x2,zeros(1,n1-l2)];
m=[0:1:n1-1];
M=mod(-m,n1);
x2=x2(M+1);
h=zeros(n1,n1);
for n=1:1:n1;
m=n-1;
p=0:1:n1-1;
q=mod(p-m,n1);
xm=x2(q+1);
h(n,:)=xm;
end
y=x1*h';

INPUT:
first sequence=[1 2 2 1]
second sequence=[1 2 2 1]

OUTPUT:
y1 =
1

10

10

10

y2 =
9
y3 =
1

45

PROGRAM 4:

To obtain FFT and IFFT for a given sequence where number of


n
points are 2 .

THEORY:
DECIMATION

IN

TIME FFT:

The decimation in time algorithm uses the divide and conquer


approach .Here the number of points is assumed as a power of
p
2.That is N=2
The decimation in time approach is one of breaking the N-point
transform into two N/2 point transform, then breaking each
N/2 point transforms into two N/4 point transforms, and
continuing this process until two point DFTs are obtained.
Example:

46

47

48

49

50

DECIMATION

IN FREQUENCY

FFT:

In this algorithm ,the output sequence X[K] is divided into


smaller and smaller sub-sequences in the same manner as in the
decimation in time algorithm.

PROBLEM:
For a given sequence x(n) compute the N-point DFT using
decimation in Time or decimation in Frequency FFT .Plot the
amplitude and phase spectrum. From the DFT calculated obtain
the IDFT,with and without function files.

MATLAB CODE :

51

1.WITHOUT

USING FUNCTION FILES

x1=input('enter the sequence x1=');


N=input('enter the value of N=');
xk=fft(x1,N);
subplot(2,2,1);
n=0:1:length(xk)-1;
stem(n,abs(xk));
xlabel('time index');
ylabel('amplitude');
title('magnitude plot');
subplot(2,2,2);
stem(n,angle(xk));
xlabel('time index');
ylabel('amplitude');
title('angle plot');
xk1=ifft(xk,N);
subplot(2,2,3);
stem(n,(xk1));
xlabel('time index');
ylabel('amplitude');
title('inverse fourier transform');
subplot(2,2,4);
n1=0:1:length(x1)-1;
stem(n1,x1);
xlabel('time index');
ylabel('amplitude');
title('input sequence');

INPUT:
Enter the sequence x1= [ 1 1 1]
Enter the value N= 8

OUTPUT:

52

2.USING

FUNCTION FILES OF

DFT

AND

IDFT :

x1=input('enter the sequence');


N=input('enter the value of N=');
xk=dft(x1,N);
subplot(2,2,1);
n=0:1:length(xk)-1;
stem(n,abs(xk));
xlabel('time index');
ylabel('amplitude');
title('magnitude plot');
subplot(2,2,2);
stem(n,angle(xk));
xlabel('time index');
ylabel('amplitude');
title('angle plot');
xk1=idft(xk,N);
subplot(2,2,3);
stem(n,(xk1));
xlabel('time index');
ylabel('amplitude');
title('inverse fourier transform');
subplot(2,2,4);
n1=0:1:length(x1)-1;
stem(n1,x1);
xlabel('time index');
ylabel('amplitude');
title('input sequence');

INPUT:
Enter the sequence x1=[ 1 1 1]
Enter the value N= 8

OUTPUT:

53

FUNCTION FILE FOR DFT:


function[xk]=dft(xn,N)
L=length(xn);
if(N<L)
error('N must be >=L')
end
x1=[xn zeros(1,N-L)];
for k=0:1:N-1
for n=0:1:N-1
p=exp((-i*2*pi*n*k)/N);
x2(k+1,n+1)=p;
end
end
xk=x1*x2.';

FUNCTION FILE FOR IDFT :


function xn=idft(xk,N)
for k=0:1:N-1
for n=0:1:N-1
p=exp(i*2*pi*n*k/N);
x2(k+1,n+1)=p;
end
end
xn=(xk*x2.')./N;

PROGRAM 5:
Realization of IIR Filters

THEORY:
A desired frequency response is approximated by a transfer
function expressed as a ratio of polynomials. This type of transfer
function yields an impulse response of infinite duration. Therefore, the
analog filters are commonly referred to as infinite impulse response
(IIR) filters The main classes of analog filters are 54

1.Butterworth Filter.
2.Chebyshev Filter.
These filters differ in the nature of their magnitude responses as well as
in their design and implementation.
BUTTERWORTH FILTERS:
Butterworth filters have very smooth passband,which we pay for with a
relatively wide transistion region.A butterworth filter is characterized
by its magnitude frequency response,
| H(j) | = 1 / [1+(/c)2N]1/2
where N is the order of the filter and c is defined as the cutoff
frequency where the filter magnitude is 1/2 times the dc gain (=0).

10 K 110 1

log10
Order

10

K2

10


2 log10 1
2

H j
1

N1 N 2

N3
0

N 2 N 3

Butterworth filter tables

N=1 (s + 1)
N=2 (s^2 +0.5 s^1 +1)
N=3 (s^2 +s+1)(s+1)
N=4 (s^2+0.76536s+1)(s^2+1.864776s+2)
N=5 (s+1)(s^2+0.6180s+1)(s^2+1.6180s+1)

55

CHEBYSHEV FILTERS:
Chebyshev filters are equiripple in either the passband or
stopband.Hence the magnitude response oscillates between the
permitted minimum and maximum values in the band a number of
times depending upon the order of filters.There are two types of
chebyshev filters.The chebyshev I filter is equiripple in passband and
monotonic in the stopband,where as chebyshev II is just the opposite.
The Chebyshev low-pass filter has a magnitude response given by

H j

A
2

C c
2
N

0. 5

where

A is the filter gain

is the 3-dB cutoff frequency


is a constant and

The Chebyshev polynomial of the 1st kind of Nth order, CN(x) is


given by

cos N cos 1 x , for x 1, passband

CN x

cosh N cosh 1 x , for x 1, stopband

H j

N odd

Magnitude response of low pass


Chebyshev Filter.

K1

N even
N1 N 2
N 2 N3
K2

N3

The magnitude response has equiripple pass band and maximally flat stop
band.
It can be seen that by increasing the filter order N, the Chebyshev
response approximates the ideal response.
56

The phase response of the Chebyshev filter is more non-linear than the
Butter worth filter for a given filter length N.

PROBLEM:
Using MATLAB design an IIR filter with passband edge
frequency 1500Hz and stop band edge at 2600Hz for a sampling
frequency of 8000Hz, variation of gain within pass band 1 db and
stopband attenuation of 15 db. Use Butterworth prototype
design and Bilinear Transformation.

Design:
W1=(2*pi* F1 )/ Fs = 2*pi*250)/1000 =0.5 rad
W2=(2*pi* F2 )/ Fs = 2*pi*375)/1000 =0.75 rad
Prewarp:
1 = 2/T tan (w1/2)
= 2 rad/sec

T=1sec

2 = 2/T tan (w2/2)


= 4.8rad/sec
Order:
n = log[(10-Ap/10 - 1)/ log[(10-As/10 - 1)
2*log[1 / 2 ]
n = 1.956
=2
Cut-off Frequency:
c1 = 1 / [(10-Ap/10 - 1)](1/2n)
c1 = 2
c2 = 2 / [(10-As/10 - 1)](1/2n)
c2 = 2.04
Choose c = 2 rad\sec
Normalized Transfer Function:

57

Hn(s) =

1/[ s2 + 1.4142s + 1]

Denormalized Transfer Function:


H(s)= Hn(s) |s-s/c

H(s)= Hn(s) |s-s/2

H(s) = 1/[(s/2)2 + (s/2) + 1 = 4\[s2 + 2.8484s + 4]


Apply BLT:
H(Z) = H(s)|s=(2/T)[(1-z-1)/(1+z-1)]
H(Z) = 0.29+0.586z-1 +0.29z-2
1+0.172 z-2

MATLAB CODE:
%Butterworth Prototype
Ap=input(enter passband attenuation =);
As=input(enter stopband attenuation =);
fp=input(enter passband frequency =);
fs= input(enter stopband frequency =);
Fs=input(enter sampling frequency=);
W1=2* fp / Fs ;
W2=2* fs / Fs ;
[N,Wn]=buttord(W1,W2,Ap,As)
[b,a]=butter(N,Wn)
freqz(b,a);
title(Butterworth frequency response)

INPUT:
enter
enter
enter
enter
enter

passband attenuation =1
stopband attenuation =15
passband frequency =1500
stopband frequency =2000
sampling frequency=8000

58

OUTPUT:
N=
6
Wn =
0.4104
b=
0.0117
0.0117

0.0699

0.1748

0.2331

0.1748

0.0699

-1.0635

1.2005

-0.5836

0.2318

-0.0437

a=
1.0000
0.0043

59

Problem:
Using MATLAB design an IIR filter with passband edge
frequency 1500Hz and stop band edge at 2600Hz for a sampling
frequency of 8000Hz, variation of gain within pass band 1 db and
stopband attenuation of 15 db. Use Chebyshew prototype design
and Bilinear Transformation.

Design:
W1=(2*pi* F1 )/ Fs = 2*pi*100)/4000 =0.05 rad
W2=(2*pi* F2 )/ Fs = 2*pi*500)/4000 =0.25 rad
Prewarp:
1 = 2/T tan (w1/2)

T=1sec

= 0.157 rad/sec
2 = 2/T tan (w2/2)
= 0.828 rad/sec
Order:
=

10-Ap/10 - 1

= 0.765
A= 10-As/20
g=

, A = 1020/20

(A2 - 1) /

r= 2 / 1
n=log10

g+

A=10
, g = 13.01

r=0.828/0.157 = 5.27 rad\sec


(g2-1)

log10{r+

(r2 1) }

60

n= 1.388
Therefore n= 2.

Cut-off Frequency:
c = p = 1 = 0.157 rad\sec
Normalized Transfer Function:
H(s)=[bo /
1+ 2
] / [ s2+b1s+b0]
= 0.505/[ s2+0.8s+0.036]
Denormalized Transfer Function:
H(s)= Hn(s) |s-s/c

H(s)= Hn(s) |s-s/0.157

H(s) = 0.0125 / [s2+0.125s+0.057]


Apply BLT:
H(Z) = H(s)|s=(2/T)[(1-z-1)/(1+z-1)]
H(Z) = 0.0125+0.025Z-1 + 0.0125 Z-2
4.2769-7.96Z-1 + 3.76Z-2
H(Z) = 0.0029+0.0052Z-1 + 0.0029 Z-2
1-1.86Z-1 + 0.88Z-2
%Chebyshev Prototype
Ap=input(enter passband attenuation =);
As=input(enter stopband attenuation =);
fp=input(enter passband frequency =);
f s= input(enter stopband frequency =);
Fs=input(enter sampling frequency=);
W1=2* fp / Fs ;
W2=2* fs / Fs ;
[N,Wn]=cheb1ord(W1,W2,Ap,As)
[b,a]=cheby1(N,Ap,Wn)
freqz(b,a);
title(Chebyshev frequency response);

61

INPUT:
enter
enter
enter
enter
enter

passband attenuation =1
stopband attenuation =15
passband frequency =1500
stopband frequency =2000
sampling frequency=8000

OUTPUT:
N=
4
Wn =
0.3750
b=
0.0191
a=
1.0000

0.0764

0.1147

0.0764

0.0191

-1.7994

1.9637

-1.1513

0.3301

62

PROGRAM 6:

Realization of FIR Filters

THEORY:
A linear-phase is required throughout the passband of the filter to
preserve the shape of the given signal in the passband. A causal IIR
filter cannot give a linear-phase characteristics and only special types
of FIR filters that exhibit center symmetry in its impulse response give
the linear-space. An FIR filter with impulse response h(n) can be
obtained as follows:
h(n) = hd(n)
0nN-1
=0
otherwise
.(a)
The impulse response hd(n) is truncated at n = 0, since we are
interested in causal FIR
Filter. It is possible to write above equation alternatively as
h(n) = hd(n)w(n)
.(b)
where w(n) is said to be a rectangular window defined by
w(n) = 1
0nN-1
=0
otherwise
Taking DTFT on both the sides of equation(b), we get
H() = Hd()*W()
HAMMING WINDOW:
The impulse response of an N-term Hamming window is defined
as follows:
wHam(n) = 0.54 0.46cos(2n / (N-1)) 0nN-1
=0
otherwise

PROBLEM:
63

Using MATLAB design an IIR filter to meet the following


specifications choosing Hamming window:
Window length, N = 27
Stop band attenuation = 50dB
Cut-off frequency = 100 Hz
Sampling frequency = 1000 Hz

MATLAB CODE:
N=input(Enter the window length=);
fc=input(Enter cut-off frequency=);
Fs=input(Enter sampling frequency=);
Wc=2*fc/ Fs;
Wh = (hamming(N))
b = fir1(N-1, Wc ,Wh)
[h,omega] = freqz(b,1,256);
mag = 20*log10(abs(h));
plot(omega/pi,mag);
grid;
xlabel(Frequncy in radians in terms of pi);
ylabel(gain in dB);
title(Response of FIR filter using Hamming window);

INPUT:
Enter the window length=27
Enter cut-off frequency=100
Enter sampling frequency=1000

OUTPUT:
Wh =
0.0800
0.0934
0.1327
0.1957
0.2787
0.3769
0.4846
0.5954
0.7031
0.8013
0.8843
0.9473
0.9866
1.0000
0.9866
64

0.9473
0.8843
0.8013
0.7031
0.5954
0.4846
0.3769
0.2787
0.1957
0.1327
0.0934
0.0800

b=
Columns 1 through 6
0.0019 0.0023 0.0022 -0.0000 -0.0058 -0.0142
Columns 7 through 12
-0.0209 -0.0185 0.0000

0.0374

0.0890

0.1429

Columns 13 through 18
0.1840 0.1994 0.1840

0.1429

0.0890

0.0374

Columns 19 through 24
0.0000 -0.0185 -0.0209 -0.0142 -0.0058 -0.0000
Columns 25 through 27
0.0022 0.0023 0.0019

65

INTRODUCTION TO DATA COMMUNICATION


Data communication is the transfer of data or information
between a source and a destination. The source transmits the
data and the destination receives it. The actual generation of
the information is not part of data communication nor is the
resulting action of the information at the destination.
Data communication is the transfer of data bits between two or
more intelligent devices in digital form. Data communication is
interested in the transfer of data, the method of transfer and the
preservation of the data from the errors during the transfer
process.
Communication is one of the most rapidly growing areas today.
In todays scenario Data communication and Networking play a
vital role.
66

Data communication is also called as Computer Communication


because, today, the transfer of information is usually between
two or more computers, or between computers and their
terminals, printers and other peripheral devices.
The day-to-day transactions at departmental stores, banks,
reservation counters and other businesses are all dependent
upon computer networks. The information age is equally
dependent on the computer and the computer network.
Rapid advances in computers and communication technologies
have resulted in the merging of these two technologies. The
lines have blurred between computing, switching and digital
transmission equipment, and the same digital techniques are
being used for data, voice and image transmission.
Today, with technology galloping towards ISDN, X.25, Frame
relay, TCP/IP, ATM, GPS, GPRS, 3G, Wireless, etc., it is essential
for students to equip themselves with the knowledge of Data
Communication and Networking.
Since basic Concepts of Data Communication and Networking
remains the same and will lay a firm foundation on which new
technologies can be built.

Concepts of Data Transmission


The transmission of information

The communication system is responsible for the transmission of


information from the sender to the recipient. At its simplest the
system contains
Transmission channel that is the physical link between the
communication parties.
A modulator that takes the source signal and transforms it so
that it is physically suitable for the transmission channel.
Transmitter that actually introduces the modulated signal into
the channel, usually amplifying the signal as it does so.
Receiver that detects the transmitted signal on the channel and
usually amplifies it (as it will have been attenuated by its
journey through the channel).
Demodulator that receives the original source signal from the Sink
received signal and passes it to the sink.

Transmitter

Channel

Receiver

Demodulator

67

or

Source

Noise

Noise Attenuation
Distortion

Noise

Modulator

A Typical Communication System


Systems are distinguished based on the type of signal presented
to the modulator. An analog system is designed for transmitting
analog signals. The PSTN is an analog system. A digital system
is designed to transmit digital signals. The PSDN is a digital
system.
An analog system can transmit digital signals, so long as they
are made to conform to the analog expectations of the system.
This work is done by the modem used to connect computers to
the PSTN. On the other hand, digital systems cannot transmit
analog signals, because their greater speed relies on the digital
form of the message. If the message source is analog, like
speech, then an ADC must first convert it to a digital sample.
When used to describe the modulation, the words analog and
digital refer to the message. All signals transmitted by the
system are analog, since they are continuously varying voltages
or fields. The signals transmitted over the channel are called
Carrier.

DATA TRANSMISSION:
There is always a need to exchange the data, commands and other control information
between the computer and its terminals, or between to computers. This information is in
form of bits. Data transmission refers to the movement of the bits over some physical
medium connecting two or more digital devices. The two options of transmitting the bits
are outlined below:
1) PARALLEL TRANSMISSION
If more than one bit of information is transmitted over the data transmission medium at a
time then it is considered a parallel communication.

68

2) SERIAL TRANSMISSION
The physical connection determines how many bits (1s and 0s) can be transmitted in a
single instance of time. If only one bit of information can be transmitted over the data
transmission medium at a time then it is considered a serial communication.

ANALYSIS
Mode of
communication

Disadvantages

Advantages

Parallel

Short distances only

Fast transfer rates

Serial

Slow transfer rates

Long distances

MODES

OF

DATA TRANSMISSION:

There are two methods of timing control for reception of bits. The transmission modes
corresponding to these two timing methods are given below.
ASYNCHRONOUS TRANSMISSION:

69

We call an action asynchronous when the agent performing an


action does so whenever it wishes. Asynchronous transmission
refers to the case when the sending end commences
transmission of bytes at any instant of time. Only one byte is
sent at a time and there is no time relation between consecutive
bytes, i.e., after sending a byte, the next byte can be sent after
an arbitrary delay.
Due to the arbitrary delay between consecutive bytes, the time
occurrences of the clock pulses at the receiving end need to be
synchronized repeatedly for each byte. This is usually achieved
by providing two extra bits, a start bit at the beginning and a
stop bit at the end of the byte.
Asynchronous transmission sends only one character at a time.
A character can be a letter of the alphabet, a number or a
control character. Preceding each character is a start bit and
ending each character is one or more stop bits. The purpose of
the start bit is to notify the receiving station of a new arriving
character. Typically, data is shown moving from left to right.
This is how it would appear on either a storage oscilloscope or a
network analyzer. The MSB is sent first and the LSB is sent last.
The purpose of the stop bits is to indicate the end of data. There
could be one or two stop bits, with one being the typical number
of stop bits that were used today. In asynchronous transmission,
the characters are sent individually with a quiet period in
between (quiet meaning 0 bit level). Asynchronous transmission
requires the transmitting station and receiving station to have
individual internal free-running clocks (operating at the same
frequency). Free-running means the clocks are not locked
together.
The receiving station starts checking for data after the start bit
is received (the start bit is wake up call). The receiving station
samples the transmitted data in the middle of each data bit. The
samples are evenly spaced. They match the transmitted data
because both transmit and receive clocks are operating at same
frequency.
Note: Receive clock frequency higher than transmitted frequency.
Condition 1: If the receive stations clock is higher in frequency than
the transmitted frequency, the samples will be spaced closer together
(higher frequency-shorter period). In the above example, we
transmitted the following data: 0100 1010, but we received the data:
0100 0101. The samples are out of synchronization with the

70

transmitting data. Therefore, we would have an error in receiving


data.
Condition 2: If the receiving stations clock is lower in frequency
than the transmitted frequency, then the samples become farther
apart (lower frequency-wider period). Again, the samples become out
of sync with the transmitted data. The transmitted data is 0100 1010,
but the received data is 0101 0101. We would again have received
data errors.
This is a basic problem with asynchronous communication: both
transmitter and receiver require a very stable clock to work properly.
At high frequencies (which results in high transfer rates), clock
stability is critical and asynchronous transmission is very difficult to
accomplish. Because of this inherent problem with asynchronous
transmission, it is used at low frequency/slow transfer rates.
SYNCHRONOUS TRANSMISSION:
A synchronous action, unlike an asynchronous action, is carried
out under the control of timing source. In synchronous
transmission, bits are always synchronized to reference clock
irrespective of the bytes they belong to. There are no start or
stop bits. Bytes are transmitted in a block in a continuous
stream of bits. Continuous transmission of bits enables the
receiver to extract the clock from the incoming electrical signal.
The bytes lose the identity and their boundaries need to be
identified. Therefore a unique sequence of a fixed number of
bits, called flag, is prefixed to each block. The flag identifies the
start of a block. The receiver first detects the flag and then
identifies the boundaries of different bytes using the counter.
Just after the flag there is the first bit of the first byte.
Synchronous transmission sends packets of characters at a time.
Each packet is preceded by a start of frame. This start frame is
used to tell the receiving station that a new packet of character
is arriving, and it synchronizes the receiving stations internal
block. The packets also have end frames to indicate the end of
the packet. The packet can contain up to 64,000 bits. Both start
and end frame have special bit sequence that the receiving
station recognizes (to indicate the start and end of the packet).
The start and end frames can be only to bytes each.
Conventional representation has asynchronous data flowing left
to right and synchronous data flowing right to left.
ASYNCHRONOUS V/S SYNCHRONOUS TRANSMISSION:

71

Asynchronous transmission is simple and inexpensive to


implement. It is used mainly with serial ports and dial-up
connections. It requires start and stop bits for each character:
this adds a high overhead to transmission. For example, for
every byte of data adds one start bit and two stop bits (i.e. 11
bits are required to send 8 bits). Asynchronous is used in slow
transfer rates (typically, up to a maximum of 56 kbps).
Synchronous transmission is more efficient. For example, only 4
bytes (3 start frame bytes and one stop framing byte) are
required to transmit up to 64 kbits. Synchronous transmission is
more difficult and expensive to implement than asynchronous. It
is used with all higher-communication transfer rates (Ethernet,
Token Ring, etc.). Synchronous is used in fast transfer rates
(typically, from 56 kbps to 100 Mbps).
Historically, synchronous communications were operating over
2400/4800 Baud modems and on point-to-point communications.
Example: Compare a 10K byte data transmission using asynchronous
transmission versus synchronous transmission. Determine the
efficiency (10 kbytes =80 kbits).
Asynchronous: Add 3 bits (1 start and 2 stop bits) for every byte
transmitted. 80 kbits + 30 kbits = total of 110 kbits transmitted
Efficiency= data transmitted X 100 = 80 kbits X 100=73%
Total bits sent
110 kbits
Synchronous: Add 4 bytes (32 bits) for the complete 10k byte data
packet.
80 kbits + 32 bits = total of 80.032 kbits transmitted
Efficiency = data transmitted X 100 = 80 kbits X 100 =99.9%
Total bits sent
80.032 kbits
Mode of
transmission
Asynchronous

Advantages
Simple and
inexpensive

Synchronous

Efficient

Disadvantages
High overhead
Complex and
expensive

Synchronous transmission has the advantage that the timing


information is accurately aligned to the received data, allowing
operations at much higher data rates. It also has the advantage that
the receiver tracks any clock drift, which may arise (for instance due
72

to temperature variation). The penalty is however a more complex


interfaces design, and potentially a more difficult interface to
configure (since there are many more interface options).
BIT-RATE

AND

BAUD-RATE:

The speed at which a serial data link operates is expressed in


bits per seconds and is
typically in the range 110 to over 56,600 bps.
Two units of speed are employed in data transmission. One is
bits/per second (bps) and the other baud (occurrence of
signaling characters on the Transmission line).Bit rate defines
the rate at which the information flows across a data link. Baud
rate defines the switching speed of a signal (i.e., the baud rate
indicates how often the signal changes the state).
For a binary two-level signal, a data rate of one bit per second is
equivalent to one Baud; for example, modem transmitting binary
data at 1,200 bps is said to operate at 1,200 baud. Suppose a
data transmission system uses signals with 16 possible discrete
levels. Each signal element can have one of 16=2 4 different
values; i.e. a signal element encodes 4 bits. If the 16-level
signals are transmitted at 1,200 baud, the data rate is 4 X 1,200
= 4,800 bps.
Bit rate is simply the number of bits that can be transmitted in a
second. If tp is the duration of a bit, the bit rate R will be 1/ t p .
The bit duration is not necessarily the pulse duration.
When bits are transmitted as an electrical signal having two
levels, the bit rate and the modulation rate of the signal are the
same. Modulation rate is the rate at which the electrical signal
changes its levels. It is expressed in bauds (per second is
implied). There is a one-to-one correspondence between bits and
electrical levels. It is possible to associate more than one bit to
one electrical level. For example, if the electrical signal has four
distinct levels, two bits can be associated with one electrical
level. In this case, bit rate is twice the baud rate.
TRANSMISSION MEDIA
THE RS232C INTERFACE
The first really universal standard for the physical connection
between the computer and modem was published in 1969 by the
Electronic Industry Association (EIA) in the USA and is known as

73

RS232C (Recommended Standard 232 versions C). Since the standard


has been revised (e.g., RS232D and RS232E).
RS232 specifies the plug and socket at the modem and the digital
equipment (i.e., their mechanics), the nature of the transmission path
and the signals required to control the operation of the modem (i.e.,
the functionality of the data link).
From the point of view of the standard, the modem is known as data
communications equipment(DCE) and the digital equipment to be
connected
to
the
modem
is
known
as
data
terminal
equipment(DTE).Because RS232 was intended for DTE to DCE links
,its functions are very largely those needed to control a modem.
LIMITATIONS

OF

RS232C:

DISTANCE LIMITATIONS: RS232C is that it can transmit data


reliably only up to 50 ft.
SPEED LIMITATIONS: Maximum speed is 19,200 bps.
GROUND LIMITATIONS: All Control and Data signals are
referenced against the same signal ground pin(pin 7). This is
called Unbalanced Transmission. The previous two limitations
are caused by this limitation.

RS232C CONTROL LINES:


The RS232 standard describes the functions carried out by several
control signals between the DTE and DCE. The following control
signals implement most of the important functions of an RS232C DTE
to DCE link.
Request to send (RTS): This is a signal from the DTE to the DCE.
When asserted, RTS indicates to the DCE that the DTE wishes to
transmit data.
Clear to send (CTS): This is a signal from the DCE to the DTE and,
when asserted, indicates that the DCE is ready to receive data from
the DTE.
Data set ready (DSR): This is a signal from the DCE to the DTE, which
indicates the readiness of the DCE. When this signal is asserted, the
DCE is able to receive from the DTE. DSR indicates that the DCE
(usually modem) is switched on and is in its normal functioning mode
(as opposed to its self-test mode).
Data terminal ready (DTR): This is a signal from the DTE to the DCE.
When asserted, DTR indicates that the DTE is ready to accept data
from DCE. In systems with a modem, it maintains the connection and
74

keeps the channel open. If DTR is negated, the communication path is


broken. In everyday terms, negating DTR is the same as hanging up a
phone.
TWISTED

PAIR:

Although the bandwidth characteristics of magnetic tape are


excellent, the delay characteristics are poor . Transmission time is
measured in min or hrs , not milliseconds for many applications an
online connection is needed.
A Twisted Pair consists of two insulated copper wires typically about
1mm thick. The wires are twisted together in helical form, just as a
DNA molecule. The twisted form is used to reduce electrical
interference to similar pairs close by. Twisted pairs can be used for
either analog or digital transmission. Twisted pairs can run several
kms without amplification. The most common application for the
twisted pair is the Telephone System.
The wires in Twisted Pair cabling are twisted together in pairs. Each
pairs consists of a wire used for the positive data signal & the wire
used for negative data signal .Any noise that appears on one wire of
the pair will also occur on the other wire.
Because the wires are opposite polarities, they are 180 deg. out of
phase (180 deg phasor definition of opposite polarity) .When the
noise appears on both the wires, it cancels or nulls itself out at the
receiving end .Twisted Pair cables are most efficiently used in systems
that use a balanced line method of transmission: polar line coding
(Manchester encoding) as opposed to unipolar line coding (TTL logic).
FIBRE OPTICS
Recent developments in Optical Technology have made it possible to
transmit data by pulses of light. A light pulse can be used to signal a 1
bit; the absence of a pulse signals a 0 bit .Visible light has a frequency
of about 106 MHz, so the bandwidth of an optical transmission system
is potentially enormous.
An optical system has components:
Transmission medium: Ultra thin fiber of glass or fused silica.
Light Source: LED or a laser diode, both of which emit light
pulse when an electrical current is applied.
Detector: A photo diode which generates an electric pulse
when light falls on it .
Fiber optic links are being installed for long distance telephone lines.

75

Experiment 1
Objective:

To conduct an experiment to implement serial


communication in
Synchronous mode using media:
1) Twisted Pair
2) RS-232c

80c51 main
controller card

Communication
module

80c51 main
controller card

Communication
module

Insert the EPROM labeled DCCT Expts to both of the 8051


controller cards.
Connect the communication module to the main controller card
using 60 pin FRC cable.
Connect the power supply and switch on.
Connect the RS232c cable to RS232 ports of both the two
communication modules.

76

Select from the Menu for serial communication by pressing key


2 on the main menu. The LCD will be cleared and the
following screen appears on the screen.

Enter Your Choice


1 -> 1200 Baud Rate
2 -> 300 Baud Rate

Menu 2

Press Key 1 on the embedded nodes of Menu 2 for Baud rate


of 1200.
The LCD screen will be cleared and the following screen will
appear on LCD.
Enter Your Choice
1 -> RS-232 medium
2 -> FSK/FO medium
3 -> PC-to-PC commn

Now press key 1 to choose the communication through


RS232 medium.
The LCD screen will be cleared and the following screen
appears on the LCD.
Enter Your Choice
(RS-232 medium)
1 -> Synchronous mode
2 -> Asynchronous mode

Menu 4

Now press 1 in Menu-4 to choose the Synchronous mode of


communication. The LCD screen will be cleared and the
following screen will appear on LCD.
Synchronous communication through
RS-232 medium

Menu 3

Menu 5

For this experiment one Trainer acts as a transmitter and


another node as a receiver and gets synchronized automatically.
77

When both the embedded nodes are chosen for RS-232 as


explained in the above steps, the nodes exchange the
information will be shifted to the Transmitter mode and another
one to the Receiver mode automatically.

Procedure:

In this experiment one node will be Tx mode for 10 secs and


shifts to Rx mode for another 10 secs. The vice versa action
occurs at other node.
The data can be entered using the keyboard for the node, which
is in transmission mode. The received data will be displayed in
the node in reception mode.
The data is also transmitted when the buffer is filled (the max
size of the buffer is 40 bytes), but the node shifts to
transmission mode only after the expiry of the time slot (10
secs).
Press ESC key on the keyboard when the node is in
transmission mode to return to the previous menu (Serial
communication synchronous RS-232 mode).
Repeat the experiment for 300 Baud rate*.

*Note: The Baud Rate shall be changed in Menu 2 and all the steps as
explained in the experimental setup and procedure needs to be
repeated.

Observation:
In this experiment the students shall observe and analyze the Principles of Synchronous mode of serial communication.
Conversion of signals: Signal level are changed from TTL to
RS232 levels (i.e., Logical Low signal is represented +3 to +12
V and Logical High signals are represented as -3 to -12V).

78

Hence, the noise interference can be avoided up to 15m to


50feets.
Cable used for communication is of 3 lines (Tx, Rx and Gnd).
Data received is slower than Parallel communication.
Behavior of DTEs with different Baud rates.

Experiment 2
Objective:

To conduct an experiment to implement serial


communication in
Asynchronous mode using the media:
1) Twisted Pair
2) RS-232c

79

80c51 main
controller card

Communication
module

80c51 main
controller card

Communication
module

Insert the EPROM labeled DCCT Expts to both of the 8051


controller cards.
Connect the communication module to the main controller card
using 60 pin FRC cable.
Connect the RS232c cable to RS232 ports of both the two
communication modules.
Select from the Menu for serial communication by pressing key
2 on the main menu. The LCD will be cleared and the
following screen appears on the screen.

Enter Your Choice


1 -> 1200 Baud Rate
2 -> 300 Baud Rate

Menu 2

Press Key 1 on the embedded nodes of Menu 2 for Baud rate


of 1200.

80

The LCD screen will be cleared and the following screen will
appear on LCD.
Enter Your Choice
1 -> RS-232 medium
2 -> FSK/FO medium
3 -> PC-to-PC commn

Now press key 1 to choose the communication through


RS232 medium.
The LCD screen will be cleared and the following screen
appears on the LCD.
Enter Your Choice
(RS-232 medium)
1 -> Synchronous mode
2 -> Asynchronous mode

Menu 3

Menu 4

Now press 2 in Menu-4 to choose the asynchronous mode of


communication. The LCD screen will be cleared and the
following screen will appear on LCD.

Enter Your Choice


(RS-232 medium)
1 -> Async Tx mode
2 -> Async Rx mode

Menu 5

81

Procedure:

The trainer has an option to act both as a transmitter and


receiver and works in a half duplex communication.
One node is selected in transmission mode and the other node in
reception mode.
Transmitting Node accept the data from the keyboard and
transmits to the receiving end when the ENTER key is
pressed. The size of the buffer is fixed to 60 bytes (characters).
The data will also be transmitted after prompting the user, when
the buffer is filled (i.e., when the user enters more than 60 bytes
of Data).
After transmitting Data the control returns to the previous menu
(Menu 5).
The received Data will be displayed on the LCD of the receiving
node. Press ESC key on the keyboard to return to the previous
menu(Menu 5).
Repeat the experiment for 300 Baud rate*.

*Note: The Baud Rate shall be changed in Menu 2 and all the steps as
explained in the experimental setup and procedure needs to be
repeated.

Observation:
In this experiment the students shall observe and analyze the

Principles of Asynchronous mode of serial communication.


Conversion of signals: Signal level are changed from TTL to
RS232 levels (i.e., Logical Low signal is represented +3 to +12
V and logical high signals is represented as -3 to -12V). Hence
the noise interference can be avoided up to 15m to 50feets.
Cable used for communication is of 3 lines (Tx, Rx and Gnd).
Data received is slower than Parallel communication.
Behavior of DTEs with different Baud rates.

82

83

GENERAL LAYOUT
OF
CODE COMPOSER STUDIO

84

STEPS TO EXECUTE A PROGRAM USING CCS


1. In the main screen go to project - - > new.. the following screen
will appear .
Give a appropriate project name, project type as executable
(.out) file.
Select target as TMS320C67xx (depends on the target processor
we are using, in our case its 67xx), and click finish in dialog box
finally.

85

2. Now a new project will be created(e.g. linear.pjt) and a tree


will be displayed on
left hand side.

86

3. Now we need to write C source code . Go to File - - > New - > Source file.

87

4. Now a blank screen will appear in which we have to write our


C source
code.Type the source code and click save.

88

5. We have to save the source code file as .c file .When we press


save icon in main
screen, following dialog box will open. Save the file as C\C++
source file (e.g.
lin.c).

89

6. Now we have to add 3 files to our project.

C source code (e.g. lin.c).


A library file (e.g. rts6700.lib).
A linker command file (e.g. hello.cmd).

Firstly add the source code file.


Go to Project - - > Add files to project...

90

Now dialog box will open ,here browse for the source code file in
projects directory and and click open .(usually the common paths
are ..\ti\MyProjects\projectname\...)

91

Similarly Add two more files following same procedure .


First, add a library file from
path...\ti\c6000\cgtools\lib\rts6700.lib (here file type is object
and library file).
Secondly, add a linker command file from path
\ti\tutorial\dsk6713\hello1\hello.cmd (here the file type is
linker command file *.lcf,*.cmd).

7. After the addition of all three files ,the expanded project tree on left
hand side will
92

resemble this format.(observe the LHS project tree which contains


a library file, a
source code and linker command file.)

93

8. Now we need to compile and build our program.


To compile go to project -- > compile file. Now the project will be
compiled and any
errors will be displayed below if there.
To build go to project - - >build. Now project will be built and any
errors or warnings
will be displayed below.

94

9. Now we need to load program in CPU or simulator .


Go to file - - > load program.
A dialog box will open in which we have select executable .out file.
The usual path is \ti\MyProjects\linear\debug\linear.out

95

10. Now we can assembly equivalent of C source code which the


simulator has generated.

96

11. To see the output of the program we have to run the program.
Go to Debug - - > Run .

97

12. Now we can see output of the program below.

If the program needs any user input, a pop-up window will open.

98

13. Now we need to see the plot of output .


Go to View - - > Graph - - > Time\frequency..
Now a graph property dialog box will open up.

Select

Display type = single time.


Graph title = Any name.
Start address = the variable which we want to display.
Index increment= 1(usually).
DSP data type = 32-bit signed integer.
DATA plot style = bar(for displaying discrete values).
Grid style = Full grid.

99

Now the graph will be displayed as shown below:

*We can select different elements by using left and right keys
of keyboard.

100

CONTENTS
1. Find out the Discrete Time Convolution of the sequences
x(n)={1 2 3 4 5 6} and h(n)={1 2 3 4}, using Code Composer
Studio. Verify the results graphically.
2. Perform the Circular Convolution of the given sequence using
Code Composer Studio.
3. Compute the response of the system whose co-efficients are
a0=0.1311, a1=0.2622, a2=0.1311 and b0=1, b1= -0.7478,
b2=0.2722, when the input is a unit impulse signal.
4. Using Code Composer Studio, compute the system whose coefficients are a0=0.0051477, a1=0.010295, a3=0.005147,
b0=1, b1= -0.844881, b2=0.873965 and
when the input is two sine waves of frequencies 3000Hz and
400Hz .Take sampling frequency as 24000Hz.

101

Program 1
Problem: Find out the Discrete Time Convolution of the sequences
x(n)={1 2 3 4 5}
and h(n)={1 2 3 4}, using Code Composer Studio. Verify
the results
graphically.
/* program to implement linear convolution */
#include<stdio.h>
int y[20];
main()
{
int m=6;
int n=6;
int i=0,j;
int x[15]={1,2,3,4,5,6,0,0,0,0,0,0};
int h[15]={1,2,3,4,5,6,0,0,0,0,0,0};

/*Lenght of i/p samples sequence*/


/*Lenght of impulse response Coeff*/
/*Input Signal Samples*/
/*Impulse Response Co-efficients*/

for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);
}

Inputs:
x(n)=[1,2,3,4,5,6]
h(n)=[1,2,3,4,5,6]

Output:
y(n)=[1,4,10,20,35,56,70,76,73,60,36]

102

Program 2
Problem: Perform the Circular Convolution of the given sequence
using Code Composer
Studio.
/* program to implement circular convolution */
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0)
/*If lenght of both sequences are not equal*/
{
if(m>n)
/* Pad the smaller sequence with zero*/
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
/*folding h(n) to h(-n)*/

103

a[j]=h[n-j];
/*Circular convolution*/
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
/*circular shift*/
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
/*displaying the result*/
printf(" the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d \t",y[i]);
}

Inputs:
Length of first sequence = 4
Length of second sequence = 4
First sequence =[1 2 2 1 ]
Second sequence =[1 2 2 1]

Outputs:
The circular convolution is [9 8 9 10]

104

Program 3
Problem: Compute the response of the system whose co-efficients
are a0=0.1311,
a1=0.2622, a2=0.1311 and b0=1, b1= -0.7478, b2=0.2722,
when the input is a unit
impulse signal.
/*program to implement impulse response of the given sequence*/
#include <stdio.h>
float y[3]={0,0,0};
float x[3]={0,0,0};
float z[10];
float impulse[10]={1,0,0,0,0,0,0,0,0,0};
main()
{
int j;
float a[3]={0.1311, 0.2622, 0.1311};
float b[3]={1, -0.7478, 0.2722};
for(j=0;j<10;j++)
{
x[0]=impulse[j];
y[0] = (a[0] *x[0]) +(a[1]* x[1] ) +(x[2]*a[2]) - (y[1]*b[1])-(y[2]*b[2]);
printf("%f\n",y[0]);
z[j]=y[0];
y[2]=y[1];
y[1]=y[0];
x[2]=x[1];
x[1] = x[0];
}
}

105

Inputs:
Coefficient of x(n)={0.1311,0.2622,0.1311}
Coefficient of y(n)={1,-0.7478,0.2722}

Outputs:
0.131100
0.360237
0.364799
0.174741
0.031373
-0.024104
-0.026565
-0.013304
-0.002718
0.001589

Graph:

106

Program 4
Problem: Using Code Composer Studio, compute the system whose
co-efficients are
a0=0.0051477, a1=0.010295, a3=0.005147, b0=1, b1=
-0.844881, b2=0.873965 and
when the input is two sine waves of frequencies 3000Hz
and 400Hz .Take
sampling frequency as 24000Hz.
/*program to implement differenceequation*/
#include <stdio.h>
#include<math.h>
float y[3]={0,0,0};
float x[3]={0,0,0};
float z[128],m[128],n[128],p[128];
main()
{
int i=0,j;

107

float a[3]={0.005147,0.010295,0.005147};
float b[3]={1.000000,-0.844881,0.873965};
for(i=0;i<10;i++)
{
m[i]=sin(2*3.14*3000*i/24000);
n[i]=sin(2*3.14*400*i/24000);
p[i]=m[i]+n[i];
}
for(j=0;j<10;j++)
{
x[0]=p[j];
y[0] = (a[0] *x[0]) +(a[1]* x[1] ) +(x[2]*a[2]) - (y[1]*b[1])-(y[2]*b[2]);
z[j]=y[0];
printf("%f\n",z[j]);
/*z[j]=y[0];*/
y[2]=y[1];
y[1]=y[0];
x[2]=x[1];
x[1] = x[0];
}
}

OUTPUTS
0.000000
0.004176
0.018097
0.033484
0.031259
0.005522
-0.024796
-0.031289
-0.003494
108

0.039590

Graph:

109

You might also like