Ccn-matlab Soft Copy



Comments



Description

DEPARTMENT OF ELECTRONICS & COMMUNICATIONENGINEERING 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 Nyquist rate 2. 16.X1 (n)=[1 2 2] X2 (n) =[1 2 2 1] 7 Using matlab for a given sequence x(n). twice the Nyquist rate 3. 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). obtain the results of IDFT. 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. Write a C Program to compute the Polynomial Code Checksum for CRC-CCITT. Write a C Program to encrypt a given text message using substitution method and decrypt it 14. 13. Write a C Program to encrypt a given text message using transposition method and decrypt it 15. with error introduced 4 . 11. 8. 12. compute the Ninput DFT using FFT algorithms. 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). Using MATLAB sample a band limited continuous time signal band limited to fm= 400Hz under the following conditions: 1. half the Nyquist rate 9. Write a C Program to simulate Character-Stuffing and DeStuffing for a HLDC Frame. Plot the magnitude and phase spectrum from the DFT calculated. Verify the program for the cases a. with out error b. Conduct an experiment to implement serial communication in asynchronous mode using any two of the following media 1. RS-232c 18.000 Computer Communication Networks Contents 1. a1=0.010295. Fiber link 3. Perform Circular Convolution of the given sequence using Code Composer Studio. Using code composer studio compute of the system whose coefficients are a0=0. using Code Composer Studio. Verify the results graphically. Find out the discrete time convolution of thee sequences x (n) = {1 2 3 4 5 6 } and h (n) = {1 2 3 4 }.1311 and b0=1. a2=0. a2=0. b1=-0.1311. a1=0.2722. WRITE A C PROGRAM TO SIMULATE BIT-STUFFING AND DE-STUFFING FOR A HLDC FRAME AND DISPLAY THE 5 .844881.005147. 21.873965 and when the input is two sine waves of frequencies 3000Hz and 400Hz. take sampling frequency=24.0051477. 20. b0=1. b2=0.7478. Conduct an experiment to implement serial communication in synchronous mode using any two of the following media 1. 22. Twisted pair 2. Fiber link 3. b2=0. Twisted pair 2. RS-232C 19. Compute the response of the system whose coefficients are a0=0.2622.17. when the input is a unit impulse signal. b1=0. INTRODUCTION TO CCN COMMUNICATION NETWORKS 6 . AND 5. ALGORITHM FOR THE GIVEN NETWORK IN THE GRAPH FORM(THE NUMBER OF NODES SHOULD BE GREATER THAN 6). WRITE A C PROGRAM TO COMPUTE THE POLYNOMIAL CODE CHECKSUM FOR CRC-CCITT.STUFFED FRAME. WRITE A C PROGRAM TO SIMULATE CHARACTERSTUFFING AND DE-STUFFING FOR A HLDC FRAME DISPLAY THE CHARACTER STUFFED FRAME. 6. 4. 2. AND 3. WRITE A C PROGRAM FOR ENCRYPTION DECRYPTION OF A GIVEN MESSAGE. 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). Telecommunications network links may in turn be built out of hierarchical transmission systems. In popular usage. 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. it is said that data communications make it possible for one computer to “talk” with another.800 bits per second and higher. from. Examples of telecommunications networks are:     Computer network the Internet the Public switched telephone network the global Telex network Data communications. especially to. have made it possible to send data over phone lines at rates of 28. each computer is assigned a short time slot during which it can use the full bandwidth of the network. Telephone circuits are often used to transfer data. 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. Where cost can be justified. however. To minimize datacommunication errors. although their relatively limited bandwidth makes them relatively slow paths for data. these are often fiberoptic or coaxial cables designed for wide frequency range. 7 . application of telecommunications technology to the problem of transmitting data. or between computers. A modem is required for such telephone communications when they occur over standard (analog) telephone circuits.The transmission channels interconnecting all client and server stations as well as all supporting hardware and software. special codes are used. high speed data links are constructed. radio links. Packet switching allows a single channel to be used for multiple concurrent transmissions. techniques such as time-division multiplexing are used. or microwave. Recent techniques. Data packets contain addresses that indicate the intended destination. Network Topologies 8 . In analog communication the modulation technique used can be used to generate control signals. etc but with it comes the problem of control signals. 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. 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. Like in FDM 3 frequencies can be used: one frequency for a 'low'. Each time we see five ones (1s) at the transmitter we append 0 instantly so that six ones (1s) can never exist. This is used when a bit oriented communication syatem is used. We give them a representation of 0111 1110. These control signals can not be present in normal data. For example. Stuffing is a process of adding redundant information or increasing the amount of data transmitted in order to acomodate control signals.the receiver cannot differentiatebetween that 0 which is data and a stuffed 0. But when the whole set of bit patterns or ASCII values are used. reliability. This can be achieved for ASCII text or if a few bit patterns are used as data. 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. 0111110 can now be interpreted as 0111 1110 (assuming 0 is stuffed 0) 0111 1101 (assuming 0 as data).WRITE A C PROGRAM TO SIMULATE BIT STUFFING AND DE-STUFFING USING HDLC THEORY Digital communication has its advantages of speed. The reason is simlpe enough . Let us consider the control signals of frame started/end. another one for a 'high' and finally a third frequency for a control signal. 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.1. This is the reason we use stuffing. But it isn't possible in digital communication. 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 . Bit patterns or bytes can be reserved for control signals. 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 isn’t DLE we know it’s 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 des). for(si=0. char flag1[max]="DLESTX".flag2). 13 . Is character DLE? Yes: Add DLE to output sequence 4.flag1).flag2[max]="DLEETX". while(src[si]!='\0') { if(src[si]=='D'&&src[si+1]=='L'&&src[si+2]=='E') { des[di+0]='D'. Add start of frame to output sequence (DLE STX) 3.si++. Add stop of frame chars to output sequence SOURCE CODE: #include<stdio.di=0. scanf("%s".des[max]. char src[max].des[di+5]='E'.ALGORITHM 1.des[di+1]='L'. si+=3. Append character to output sequence b. /*DE-STUFFING PROCESS*/ di=strlen(des)-strlen(flag2).h> #include<conio. di+=6. Input data sequence 2. clrscr().di++) src[si]=des[di]. des[di]='\0'.des[di+3]='D '. /*STUFFING PROCESS*/ strcpy(des.h> #define max 100 void main() { int si=0. di=strlen(flag1). For every character in input a.des[di]!='\0'. di=strlen(flag1). strcat(des. printf("Enter the string data\n").des[di+4]='L'. } des[di]='\0'.&src). } else des[di++]=src[si++]. printf("The stuffed string is %s\n".h> #include<string.des[di+2]='E'. printf("The destuffed string is %s". 14 . getch().des[di+1]='L'.des[di+2]='E'. Routing algorithms can be may to adapt to average traffic/loss/delay/distance/queue length etc. } OUTPUT: 1. 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'. 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. } else des[di++]=src[si++].des). It involves building a graph of the subnet. } des[di]='\0'. Dijkstra’s method of computing the shortest path is a static routing algorithm. Enter the string data The stuffed string is ABCDLE DLESTXABCDLEDLEDLEETX The destuffed string is ABCDLE 2. with each node of the graph representing a router and each arc representing a communication line or a link.si=di=0. 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. di+=3. si+=6. Check all tentative nodes.i++) printf("\t %d". 6. reflecting better paths.k. the working node. Trace back from destination to source. Make this the new working node.&n). the labels may change. A label may be either tentative or permanent. 4. scanf("%d". printf("\n To indicate no connection between two nodes.To find a route between a pair of routers the algorithm just finds the shortest path between them on the graph. ALGORITHM 1. no paths are known so all nodes are labeled with infinity. 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.enter weight as 100\n\n"). clrscr(). destination. As the algorithm proceeds and paths are found. 9. 2.pn. If working node is destination. Make all nodes TENTATIVE.n.w[10][10].i<=n.i++) { 15 . Find TENTATIVE node with smallest weight.int j). Input graph data. Initially. int m[10][10]. 7. Each node is labeled with its distance from the source node along with the previous node in the path. Make the working node PERMANENT. go to step 8 else go to step 4. 3. Input source. 8. printf("Enter no of nodes:"). SOURCE CODE: #include<stdio. void path(int i. In Dijkstra’s algorithm the metric used for calculation is distance. \* Prints the outline of the matrix*\ for (i=1.t. void main() { int i. which are connected to working node. Make source.h> int p[10][10]. Initially.h> #include<conio. printf("\n Enter the node connection matrix"). for (i=1. update weight if required. 5.i<=n.j.i). }while (getch()=='R').j).} printf("\n %d \t". path(k.k++) for(i=1. void path(int i.j). }} OUTPUT: 16 . printf("%d--->".m[i][j]). if (k!=0) { path(i.i<=n.i). printf("\n to repeat press R"). printf("%d-->". printf("%d". for(k=1. path(i. m[i][j]=w[i][j].k).&i. printf("\n The path is "). k=p[i][j]. printf("\n The weight is %d".i<=n.j<=n.j). } do { printf("\n Enter the source and destination nodes\n").int j) { int k.k<=n.j++) if (m[i][k]+m[k][j]<m[i][j]) { m[i][j]=m[i][k]+m[k][j].j++) { scanf("%d". } } for (i=1.&j).i++) m[i][j]=0.&w[i][j]).j<=n.i++) for(j=1. p[i][j]=0.k).i). \* Takes the entered values as input*/ for (j=1. p[i][j]=k. scanf("%d %d". 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 2 2 100 4 100 100 100 6 3 1 4 100 3 5 100 100 4 100 100 3 100 2 2 100 5 100 100 5 2 100 100 1 6 4 100 100 2 100 100 7 7 100 6 100 100 1 7 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 data’s 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 data’s array. 3. Print decoded data Encryption by transposition method. 1. Get sequence of characters in cipher i. e. MEGABUCK. 19 printf("--------------\n"). If its not a multiple print that it is an error and quit. 4. Add ‘.h> void main() { int encry. 7. scanf("%d".2. 6. 3. ".e.e. Find next column to send using sequence.h> #include<conio. Get data to be decoded. 5. if(encry<1||encry>25) printf("\nInvalid key"). printf("Enter the text\n").e. See if input as a multiple of length of word characters. gets(plain). Get data to be decoded.plain[ci]!='\0'. Decryption by transposition method 1.ci. Arrange data horizontally under MEGABUCK.cipher[100]=" clrscr(). /*Encryption Process*/ while(1) { printf("Enter the key for encryption(between 1 and 25)\n"). SOURCE CODE: /*Encryption and De-cryption using Substitution method*/ #include<stdio. 4. Put size of data size of word characters underneath it. 3. Do step 4 to 5 for all characters of MEGABUCK in alphabetical order.ci++) { if(isalpha(plain[ci])) { 20 .&encry). Find position of first character i.’ to make last row complete For every column of MEGABUCK a.h> #include<math. } for(ci=0.h> #include<ctype. 2. MEGABUCK. b. Send data under this header i. A. Jump back to 5 till all columns are not done. Print all characters row wise starting from M to K. 5. c. print the data under this letter. char plain[100]=" ".decry. Get sequence of characters in word i. else break. else cipher[ci]=(plain[ci]'a'+encry)%26+'a'. } else cipher[ci]=plain[ci]. } printf("Text after decryption is %s". } 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 . getch().&decry). } else plain[ci]=cipher[ci].ci++) { if(isalpha(cipher[ci])) { if(isupper(cipher[ci])) plain[ci]=(cipher[ci]-'A'decry+26)%26+'A'. Re-enter key\n").if(isupper(plain[ci])) cipher[ci]=(plain[ci]'A'+encry)%26+'A'. } for(ci=0. else plain[ci]=(cipher[ci]-'a'decry+26)%26+'a'.cipher).plain). /*Decryption process*/ while(1) { printf("\nEnter the decryption key(between 1 and 25)\n"). else printf("\nKey is wrong. if(decry==encry) break.cipher[ci]!='\0'. scanf("%d". } printf("Text after encryption is %s". i++) if(!isalpha(key[i])) break.ch<='Z'. if(i!=strlen(key)) printf("\nBad input key\n")./*Encryption and De-cryption using Transposition method*/ #include<ctype. klen=strlen(key).i.i++) if (toupper(key[i])==ch) for (j=i. for (i=0. if ((plen%klen)!=0) { for (ch='A'. plen=strlen(src). } for (ch='A'.h> #include<stdio. } } \* Main Program*\ void main() { 22 . gets(key).char *dest. printf("\nAfter extending %s\n". else break.i<strlen(key).k=0.j<plen. while(1) { printf("\n%s".h> #include<string.i<klen. } dest[k]='\0'.h> #include<conio. else dest[j]=src[k++].j+=klen) if (oper!=0) dest[k++]=src[j].char *key) { int i.char *key.msg).(plen%klen)!=0.plen. } void getkey(char *msg.src).ch++) src[plen++]=ch.int oper) { int klen.ch++) { for (i=0.ch. src[plen]='\0'.j.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. cipher). len=strlen(plain). } 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.plain.cipher. getkey("\nEnter key for encryption\n". gets(plain). printf("Enter the plain text\n"). clrscr(). char plain[MAX].1).key.key[MAX]. transpose(plain.cipher[MAX].key.key). printf("Encryption & decryption using transposition\n").key). transpose(cipher.0). printf("\nAfter decryption %s\n".int len. getch().plain). printf("\nnAfter encryption %s\n".WRITE A C PROGRAM TO FIND MINIMUM SPANNING TREE OF A SUBNET 23 . plain[len]='\0'. getkey("\nEnter key for decryption\n". 6.i<=n. Sort the edge weights in ascending order. different trees have different lengths. Input number of vertices.k. For instance. the edges of the graphs have weights or lengths. 5. the weight of the trees is the some of its edges. A spanning tree includes all the routers.w[10][10]. The only problem is that each router must have knowledge of some spanning tree for it to be applicable. int chkcl(int. scanf("%d".h> int p[10][10]. Display selected edges.THEORY A spanning tree is a graph is just a sub-graph that contains all the vertices and is a tree.g. 3.x. printf("Enter the number of nodes\n"). Suppose. a complete graph 4 nodes can have 16 spanning trees. with distance vector routing).y. SOURCE CODE: #include<conio. for (i=1.n.z=900.i). Repeat till edges are marked making sure that there are no close loop. Input the edge weights. int m[10][10].i++) printf("\t%d". Obviously.int. ALGORITHM 1. it can copy and incoming broadcast packet onto all the spanning trees lines except the one it arrived on. 2. void main() { int i. This method makes excellent use of bandwidth.h> #include<stdio. but contains no loops. generative the absolute minimum number of packets necessary to do the job.flag. but sometimes it is not (e. Sometime this information is available (e.i<=n.wt=0.int). with link state routing).j. 4. A graph may have many spanning trees. clrscr().g.i++) 24 . If each router knows which of its lines belong to the spanning trees.int. printf("\nEnter the node connection matrix\n"). Pick the lowest edge and joined the corresponding vertices. for (i=1.&n). p[i][j]=w[i][j].y<j. printf("The weight is %d\n". m[i][j]=1. else { k=i.n.z).flag. for (y=1.int j. if (flag==1) continue.j).i<=n.i. if (flag==1) return (1).int n.j. x=p[i][j]. } int chkcl(int i.i++) { x=100. } } for (i=1.i++) for (j=1. p[k][i]=p[i][k].k).{ printf("\n%d\t".j<=n. getch().j++) if (m[i][j]!=0) printf("%d--->%d\n". } printf("\nThe tree is \n"). for (j=1.y++) m[i][y]=0. } } 25 .j++) { if (p[i][j]<x) { flag=chkcl (i.t<=n.j.wt).int k) { int t.i<=n.j<=n.t++) { if ((p[i][t]==150)&&t!=k) { if (t==j) return (1).j++) { scanf("%d". for (t=1. k=j.&w[i][j]). for (i=1. for (j=1. } } if (p[i][k]<100) wt=wt+p[i][k].n. p[i][k]=150.i). m[i][j]=0. flag=chkcl(t.j<=n. } OUTPUT: Enter the number of nodes 5 Enter the node connection matrix 1 1 2 100 2 3 3 4 5 100 4 2 2 100 100 5 100 3 3 100 100 7 8 4 100 5 5 4 7 100 100 100 8 100 100 The tree is 1-->2 2-->4 3-->1 5-->1 26 .} return (0). 0. When the polynomial code method is employed. corresponding to the polynomial M (x). 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). ranging from x k-1 to x0. the centre and receiver must agree upon a generator polynomial. When the receiver gets the checksummed frame.1 5 2 4 3 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. Such a polynomial is said to be of a degree k-1. For example. it tries dividing it by G(x). the next bit is the coefficient of x k-2 .0 and 1: x5 + x4+ x0 .1. both the high and low order bits of the generator must be one. G(x) in advance. The high order ( left most) bit is the coefficient of x k-1 . Polynomial codes are based upon treating bit strings as representations of polynomials with coefficients of 0 and 1 only. 110001 has 6 bits and thus represents a six-term polynomial with coefficients 1. If there is a remainder there has been a transmission error. To compute the checksum for some frame with m bits. ALGORITHM 27 . and so on. the frame must be longer than the generator polynomial. A k-bit frame is regarded as the coefficient list for a polynomial with k terms. 0. 0.0. } void main() { int array[30]. while(array[i]==0) ++i.1.++i) res[i]=res[i]^cp[i-pos].h> #define degree 16 int res[30].1. Call its polynomial T(x).0. while(pos<len-degree) { for(i=pos. while((ch=getche())!='\r') array[i++]=ch-'0'. int i=0. The result is the checksummed frame to be transmitted.0.int). so it now contains m+r bits and corresponds to the polynomial xr M(x). if(newpos>pos+1) pos=newpos-1.0. char ch.i=0.0.++i) array[i+len]=0. puts("Enter the data stream:"). ++pos.i<pos+degree+1.pos=0. clrscr().0.0. 28 . len=i. divide the bit string corresponding to G(x) into the bit string corresponding to xr M (x) using modulo-2 division. return i. newpos=getnext(res.0.newpos.pos). Append r zero bits to the low order end of the frame. The CRC-CCITT polynomial is x16 + x12+x5+1 SOURCE CODE: #include<stdio. } } int getnext(int array[].0. 3. len+=degree.i<degree.0.0. Subtract the remainder (which is always r or fewer bits) from the bit string corresponding to xr M(x) using modulo-2 subtraction. int getnext(int array[].1}.int pos) { int i=pos.h> #include <conio. int len.0. 2. for(i=0. void crc(int len) { int cp[]={1.1. Let r be the degree of G(x). for(i=0. crc(len). while((ch=getche())!='\r') array[i++]=ch-'0'.i<len. } 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 .for(i=0.array[i]).i<len.i++) res[i]=array[i]. for(i=len-degree.++i) printf("%d".res[i]). crc(len).res[i]).++i) printf("%d". len=i. i=0. printf("\ncheck sum:").i<len-degree. printf("\nEnter the stream for which crc is to be checked").i<len. printf("\nThe transmitted frame is: ").i++) res[i]=array[i]. for(i=len-degree. getch().i<len. for(i=0.i++) printf("%d". 30 . To obtain the FFT and IFFT for a given sequence sequence………...3 II.8 III. Introduction to MATLAB………………………………………….CONTENTS I.. Convolution of two given finite length sequences(linear and circular).12 V.. …………………10 IV.15 31 . Finding the Impulse Response of a given system. Verification of Sampling Theorem………………………………….... signal processing and graphics in an easy-to-use environment. 32 .. matrix computations. Realization of FIR filters……………………………………………. MATLAB integrated numerical analysis..19 VII.22 INTRODUCTION TO MATLAB MATLAB stands for matrix laboratory . Realization of IIR filters…………………………………………….It is a technical computing environment for high performance numeric computation and visualization..VI.. For length N input vector x. the FFT operation is applied to each column. For N-D arrays. provides a list of functions and commands in that category.N.DIM) applies the FFT operation across the dimension DIM. FFT(X. and control system design. with elements N X(k) = x(n)*exp(-j*2*pi*(k-1)*(n-1)/N). These toolboxes are collection of functions written for special applications such as symbolic computations. the DFT is a length N vector X.[]. FFT(X.DIM) or FFT(X. For matrices. 1≤k≤N. image processing.N) is the N-point FFT. ACTUAL EXAMPLES: >> >>2+2 ans= 4 >>area=pi*2.15^2 area= 14. FFT(X) is the discrete Fourier transform (DFT) of vector X. Type help category in MATLAB with the appropriate category name. the FFT operation operates on the first non-singleton dimension.5220  MATLAB prompt Command MATLAB response ON-LINE HELP: ON LINE DOCUMENTATION : MATLAB provides online help for all it’s built in functions and programming language constructs. neural networks etc.Type demo at the matlab prompt to invoke the demonstration program and follow the instruction on the screen.There are also several optional ‘TOOLBOXES’ available from the MATLAB. n=1 33 . Example: >> help fft FFT Discrete Fourier transform. statistics. The program includes a tutorial introduction . padded with zeros if X has less than N points and truncated if it has more. DEMO : MATLAB has a demonstration program that shows many of its features. 1 <= n <= N.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). k=1 34 . 35 . COMMAND window 2. 1. GRAPHICS or FIGURE window 3. All commands including those for running user written programs are typed in this window at the MATLAB prompt. When you launch an application program. 36 . MATLAB puts you in this window.MATLAB WINDOWS MATLAB works through three basic windows. GRAPHICS or FIGURE WINDOW :   The output of all the graphics commands typed in the command window are flushed to the graphics or figure window. 2. EDITOR window 1. The user can create as many figure windows as the system memory will allow. COMMAND WINDOW: This is the main window .It is characterized by the MATLAB command prompt ‘>>’. MATLAB provides its own built in editor .mex extension to the filename.m extension to the file name. with a . create. EDITOR WINDOW:   This is where you write. There are two types of m-files namely script file and function file. 37 .3. 2. The data is written in a special format that only MATLAB can read. 3. edit. M-files. 2. 1. MAT-FILES: These are binary data files.mat extension to the file name. M-FILES: They are standard ASCII text files with an . MAT files are created by MATLAB when you save the data with the save command. and save your own programs in files called ‘m-Files’ . 3. MEX-files. MATLAB FILE TYPES MATLAB has three types of files for storing information: 1. MEX_FILES: These are MATLAB callable FORTRAN and c programs with an . MAT-files. The minimum sampling rate of 2w samples per second. Nyquist rate 2.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. sample a band limited continuous time signal.  Right Sampling → ƒs = 2ƒm  Under Sampling → ƒs ≤ 2ƒm  Right Sampling → ƒs ≥ 2ƒm PROBLEM: Using MATLAB. Under sampling 3.  If a finite energy signal g(t) contains no frequencies higher than ‘w’ Hz. Under sampling and Over sampling . for a signal bandwidth of ‘w’Hz is called NYQUIST RATE. it is completely determined by specifying its ordinates at a sequence of points spaced 1/2w sec apart. it may be completely recovered from its ordinates at a sequence of points spaced 1/2w sec apart. ƒs = 2ƒm where. they are Right sampling. Over sampling 38 . ƒs=Sampling Frequency ƒm=Message frequency We encounter these conditions in Sampling Theorem. band limited to fm=400Hz under the following conditions: 1. Subplot(2. title(‘Nyquist Rate Sampling’). %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’). Subplot(2.2. %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’).1). X=sin(2*pi*400*t). X=sin(2*pi*400*t). %Over Sampling ƒs=1000.2). Xm=abs(fft(X)). Xm=abs(fft(X)).3).2. X=sin(2*pi*400*t). t=0:1/ ƒs:256/ ƒs. ylabel(‘Magnitude’). t=0:1/ ƒs:256/ ƒs. 39 . ylabel(‘Magnitude’).Xm). %Under Sampling ƒs=200. Stem(k. Xm=abs(fft(X)).MATLAB CODE: %Nyquist Rate Sampling ƒs=800. %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’). title(‘Over Sampling’). K=0:length(X)-1.2. t=0:1/ ƒs:256/ ƒs. K=0:length(X)-1. ylabel(‘Magnitude’). Stem(k. Stem(k. K=0:length(X)-1.Xm).Xm). Subplot(2. title(‘Under Sampling’). OUTPUT: 40 . 0052 h(8)=0.0429 h(1)=0. or n=0.0013 41 .0105 h(3)=0. 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. Alternatively.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 . B=1/3. which is referred to as Impulse response of the system. 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) .416 h(5)=0.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. the impulse response is the output of a LTI system due to an impulse input applied at t=0.3/4 Y(z)z-1 + 1/8 Y(z)z-2 = X(z) .02116 h(2)=0.088 h(7)=0.187 h(6)=0. -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.0026 h(9)=0. grid. xlabel('time index'). a=input('type in denominator coeff='). title('impulse response'). ylabel('amplitude').h).6) stem(t.MATLAB CODE: b=input('type in numerator coeff=').t]=impz(b. INPUT: Type in numerator coeff=[1 -1/3] Type in denominator coeff=[1 -3/4 1/8] OUTPUT: 42 . [h.a. 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. Here.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. The output using the convolution operation. 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). and y(t) is the output. however an important distinction must be made here: The asterisk operator means convolution. Many computer systems. we can find the output by convoluting the impulse response with the input to the circuit. h(t) is the circuit's impulse response. Hence we see that the impulse response of a circuit is not just the ratio of 43 . 1. %linear convolution y1=conv(x1.y1). Then.i. stem(n2. title('linear convolution'). y(n) = x(n) ( * ) N h (n) = m=0N-1 x((n-m))N h(m). y2=circonv(x1. 0≤n≤N-1 y(n)= m=0N-1 x(m) h ((n-m))N MATLAB CODE: x1=input('first sequence=').l2).y2). The moral of the story is this: the output to a circuit is the input convoluted with the impulse response.y3).n1) %circular using linear convolution n2=l1+l2-1.3).2). component in the output with frequency ω is the product of the input component with the same frequency and the transition function at that frequency. subplot(3. n1=max(l1.n2) subplot(3. title('circular convolution'). l2=length(x2). stem(n1. n3=0:1:length(y3)-1. stem(n3.1. xlabel('time index').x2. n2=0:1:length(y2)-1. n1=0:1:length(y1)-1.1). X1(n) h(n) y(n) CIRCULAR CONVOLUTION: Let x(n) and h(n) be the two sequences of length N.. subplot(3.e y(n)=x1(n)*h(n) :where y(n) is the output sequence. In the frequency domain however. 44 . xlabel('time index'). ylabel('amplitude').the output over the input. y3=circonv(x1.x2) %circular convolution l1=length(x1). ylabel('amplitude'). LINEAR CONVOLUTION: Let x1(n) be the input sequence and h(n) be the impulse response of the system as shown below.1. x2=input('second sequence=').x2. n1-l2)]. p=0:1:n1-1. m=n-1.zeros(1.n1). FUNCTION FILE FOR CIRCULAR CONVOLUTION: function[y]=circonv(x1. h(n. l2=length(x2).xlabel('time index'). M=mod(-m. x2=x2(M+1). h=zeros(n1. end x1=[x1.n1). end y=x1*h'. INPUT: first sequence=[1 2 2 1] second sequence=[1 2 2 1] OUTPUT: y1 = 1 4 8 10 8 9 10 4 8 10 8 4 1 8 4 1 y2 = 9 y3 = 1 45 . xm=x2(q+1). q=mod(p-m.:)=xm.l2)').n1) l1=length(x1).n1).n1-l1)]. ylabel('amplitude').zeros(1. x2=[x2. title('circular with linear').x2.l2)) error('n1 must be>=max(l1. m=[0:1:n1-1]. for n=1:1:n1. if(n1<max(l1. Here the number of points is assumed as a power of p 2. then breaking each N/2 –point transforms into two N/4 –point transforms. THEORY: DECIMATION IN TIME FFT: The decimation in time algorithm uses the divide and conquer approach .PROGRAM 4: To obtain FFT and IFFT for a given sequence where number of n points are 2 . Example: 46 .That is N=2 The decimation in time approach is one of breaking the N-point transform into two N/2 –point transform. and continuing this process until two point DFT’s are obtained. 47 . 48 . 49 . 50 . with and without function files.Plot the amplitude and phase spectrum. From the DFT calculated obtain the IDFT.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 .DECIMATION IN FREQUENCY FFT: In this algorithm . MATLAB CODE : 51 . (xk1)). xlabel('time index').2. stem(n.x1).2. subplot(2.2.N).2). xlabel('time index').3). xk=fft(x1. stem(n1.WITHOUT USING FUNCTION FILES x1=input('enter the sequence x1='). subplot(2. title('inverse fourier transform').1). title('angle plot'). n1=0:1:length(x1)-1.abs(xk)). ylabel('amplitude'). xk1=ifft(xk. title('input sequence'). subplot(2.4). INPUT: Enter the sequence x1= [ 1 1 1] Enter the value N= 8 OUTPUT: 52 . subplot(2. n=0:1:length(xk)-1.2. title('magnitude plot'). xlabel('time index'). stem(n.angle(xk)). stem(n. ylabel('amplitude'). ylabel('amplitude'). N=input('enter the value of N='). xlabel('time index'). ylabel('amplitude').N).1. xlabel('time index').4). ylabel('amplitude').USING FUNCTION FILES OF DFT AND IDFT : x1=input('enter the sequence'). title('inverse fourier transform'). subplot(2. n=0:1:length(xk)-1.2. title('magnitude plot'). stem(n. title('angle plot').2.2.abs(xk)). title('input sequence'). xlabel('time index'). xk=dft(x1.x1).2). ylabel('amplitude'). stem(n. INPUT: Enter the sequence x1=[ 1 1 1] Enter the value N= 8 OUTPUT: 53 . subplot(2. N=input('enter the value of N=').2.1).3). subplot(2.angle(xk)).N). ylabel('amplitude').N). ylabel('amplitude'). subplot(2. xk1=idft(xk. stem(n. n1=0:1:length(x1)-1. xlabel('time index').2.(xk1)). stem(n1. xlabel('time index'). N) L=length(xn).n+1)=p. end end xk=x1*x2.'. x2(k+1.n+1)=p./N. Therefore.FUNCTION FILE FOR DFT: function[xk]=dft(xn.N) for k=0:1:N-1 for n=0:1:N-1 p=exp(i*2*pi*n*k/N). This type of transfer function yields an impulse response of infinite duration. FUNCTION FILE FOR IDFT : function xn=idft(xk. PROGRAM 5: Realization of IIR Filters THEORY: A desired frequency response is approximated by a transfer function expressed as a ratio of polynomials. if(N<L) error('N must be >=L') end x1=[xn zeros(1. x2(k+1. the analog filters are commonly referred to as infinite impulse response (IIR) filters The main classes of analog filters are 54 . for k=0:1:N-1 for n=0:1:N-1 p=exp((-i*2*pi*n*k)/N).N-L)].'). end end xn=(xk*x2.  10  K 110  1  log10  Order N  10  K2 10   1    2 log10  1   2    4 H  j  1 N1  N 2  N3 0 c N 2  N 3  Butterworth filter tables      N=1  (s + 1) N=2  (s^2 +0.1. BUTTERWORTH FILTERS: Butterworth filters have very smooth passband.A butterworth filter is characterized by its magnitude frequency response.Chebyshev Filter.6180s+1) 55 .76536s+1)(s^2+1.Butterworth Filter. These filters differ in the nature of their magnitude responses as well as in their design and implementation.864776s+2) N=5  (s+1)(s^2+0.6180s+1)(s^2+1. | 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). 2.5 s^1 +1) N=3 (s^2 +s+1)(s+1) N=4 (s^2+0.which we pay for with a relatively wide transistion region. K1 N even N1  N 2 N 2  N3 K2   N3  The magnitude response has equiripple pass band and maximally flat stop band.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. It can be seen that by increasing the filter order N.CHEBYSHEV FILTERS: Chebyshev filters are equiripple in either the passband or stopband. for x  1.There are two types of chebyshev filters. 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. the Chebyshev response approximates the ideal response. The Chebyshev low-pass filter has a magnitude response given by H  j   1   A 2 C   c  2 N  0.The chebyshev I filter is equiripple in passband and monotonic in the stopband. CN(x) is given by   c  cos N cos 1 x . stopband  H  j  N odd 1 Magnitude response of low pass Chebyshev Filter.where as chebyshev II is just the opposite. passband  CN  x      cosh N cosh 1 x . 56 . for x  1. variation of gain within pass band 1 db and stopband attenuation of 15 db.1)/ log[(10-As/10 .04 Choose Ωc = 2 rad\sec Normalized Transfer Function: 57 . PROBLEM: Using MATLAB design an IIR filter with passband edge frequency 1500Hz and stop band edge at 2600Hz for a sampling frequency of 8000Hz.1) 2*log[Ω1 / Ω2 ] n = 1.75∏ rad Prewarp: Ω1 = 2/T tan (w1/2) = 2 rad/sec T=1sec Ω2 = 2/T tan (w2/2) = 4. Design: W1=(2*pi* F1 )/ Fs = 2*pi*250)/1000 =0. The phase response of the Chebyshev filter is more non-linear than the Butter worth filter for a given filter length N. Use Butterworth prototype design and Bilinear Transformation.5∏ rad W2=(2*pi* F2 )/ Fs = 2*pi*375)/1000 =0.1)](1/2n) Ωc2 = 2.956 =2 Cut-off Frequency: Ωc1 = Ω1 / [(10-Ap/10 .1)](1/2n) Ωc1 = 2 Ωc2 = Ω2 / [(10-As/10 .8rad/sec Order: n = log[(10-Ap/10 . fp=input(‘enter passband frequency =’).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. [N. W1=2* fp / Fs .Hn(s) = 1/[ s2 + 1. Fs=input(‘enter sampling frequency=’). 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 .Wn) freqz(b.8484s + 4] Apply BLT: H(Z) = H(s)|s=(2/T)[(1-z-1)/(1+z-1)] H(Z) = 0.Ap. W2=2* fs / Fs .W2.a]=butter(N.29z-2 1+0.Wn]=buttord(W1.586z-1 +0. As=input(‘enter stopband attenuation =’).29+0.a).172 z-2 MATLAB CODE: %Butterworth Prototype Ap=input(‘enter passband attenuation =’).As) [b. fs= input(‘enter stopband frequency =’). 0635 1.4104 b= 0.1748 0.2318 -0.2331 0.0699 0.0043 59 .2005 -0.OUTPUT: N= 6 Wn = 0.0000 0.0437 a= 1.0699 -1.0117 0.0117 0.1748 0.5836 0. 05∏ rad W2=(2*pi* F2 )/ Fs = 2*pi*500)/4000 =0.157 = 5.828 rad/sec Order: έ= 10-Ap/10 .828/0. Design: W1=(2*pi* F1 )/ Fs = 2*pi*100)/4000 =0.Problem: Using MATLAB design an IIR filter with passband edge frequency 1500Hz and stop band edge at 2600Hz for a sampling frequency of 8000Hz.1) / έ Ωr= Ω2 / Ω1 n=log10 g+ . g = 13.27 rad\sec (g2-1) log10{Ωr+ (Ωr2 – 1) } 60 .1 έ = 0.157 rad/sec Ω2 = 2/T tan (w2/2) = 0.765 A= 10-As/20 g= .25∏ rad Prewarp: Ω1 = 2/T tan (w1/2) T=1sec = 0. variation of gain within pass band 1 db and stopband attenuation of 15 db. A=10 .01 Ωr=0. Use Chebyshew prototype design and Bilinear Transformation. A = 1020/20 (A2 . Cut-off Frequency: Ωc = Ωp = Ω1 = 0.n= 1.2769-7. 61 .Wn]=cheb1ord(W1.0029+0. title(‘Chebyshev frequency response’).0029 Z-2 1-1.157 H(s) = 0.As) [b. fp=input(‘enter passband frequency =’).86Z-1 + 0.76Z-2 H(Z) = 0. W1=2* fp / Fs .036] Denormalized Transfer Function: H(s)= Hn(s) |s-s/Ωc H(s)= Hn(s) |s-s/0. Fs=input(‘enter sampling frequency=’). [N.Ap. As=input(‘enter stopband attenuation =’).88Z-2 %Chebyshev Prototype Ap=input(‘enter passband attenuation =’).a]=cheby1(N.0125 / [s2+0.057] Apply BLT: H(Z) = H(s)|s=(2/T)[(1-z-1)/(1+z-1)] H(Z) = 0.388 Therefore n= 2.505/[ s2+0.0052Z-1 + 0.0125 Z-2 4.Wn) freqz(b.125s+0.157 rad\sec Normalized Transfer Function: H(s)=[bo / 1+ έ2 ] / [ s2+b1s+b0] = 0. W2=2* fs / Fs .a). f s= input(‘enter stopband frequency =’).W2.96Z-1 + 3.Ap.0125+0.8s+0.025Z-1 + 0. 3750 b= 0.7994 1.0764 0.0000 0.0764 0.3301 62 .1513 0.1147 0.0191 a= 1.9637 -1.0191 -1.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. 54 – 0. An FIR filter with impulse response h(n) can be obtained as follows: h(n) = hd(n) 0≤n≤N-1 =0 otherwise ……………….(a) The impulse response hd(n) is truncated at n = 0.(b) where w(n) is said to be a rectangular window defined by w(n) = 1 0≤n≤N-1 =0 otherwise Taking DTFT on both the sides of equation(b).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.46cos(2пn / (N-1)) 0≤n≤N-1 =0 otherwise PROBLEM: 63 . since we are interested in causal FIR Filter. we get H(ω) = Hd(ω)*W(ω) HAMMING WINDOW: The impulse response of an N-term Hamming window is defined as follows: wHam(n) = 0. It is possible to write above equation alternatively as h(n) = hd(n)w(n) ………………. Fs=input(‘Enter sampling frequency=’).9866 1. Wc .0934 0. Wh = (hamming(N)) b = fir1(N-1. grid.9866 64 . ylabel(‘gain in dB’).2787 0. INPUT: Enter the window length=27 Enter cut-off frequency=100 Enter sampling frequency=1000 OUTPUT: Wh = 0.3769 0.Using MATLAB design an IIR filter to meet the following specifications choosing Hamming window: Window length.8013 0. plot(omega/pi.Wh) [h.omega] = freqz(b. N = 27 Stop band attenuation = 50dB Cut-off frequency = 100 Hz Sampling frequency = 1000 Hz MATLAB CODE: N=input(‘Enter the window length=’).7031 0.1957 0.mag).0000 0. title(‘Response of FIR filter using Hamming window’).1327 0.9473 0.5954 0.8843 0. xlabel(‘Frequncy in radians in terms of pi’).0800 0.4846 0. fc=input(‘Enter cut-off frequency=’). mag = 20*log10(abs(h)).256).1. Wc=2*fc/ Fs. 7031 0.0142 -0.0185 0.0934 0.8013 0.0374 0.0.2787 0.0185 -0.1840 0.0890 0.0000 -0.0209 -0.0058 -0.9473 0.1994 0.0142 Columns 7 through 12 -0.0019 0.1840 0.0209 -0.0019 65 .4846 0.0374 Columns 19 through 24 0.3769 0.0022 0.8843 0.1429 Columns 13 through 18 0.0800 b= Columns 1 through 6 0.1327 0.0890 0.5954 0.0023 0.0022 -0.1957 0.0023 0.0058 -0.0000 0.1429 0.0000 -0.0000 Columns 25 through 27 0. The source transmits the data and the destination receives it.  Communication is one of the most rapidly growing areas today.  Data communication is the transfer of data bits between two or more intelligent devices in digital form. the method of transfer and the preservation of the data from the errors during the transfer process. 66 . In today’s scenario Data communication and Networking play a vital role. Data communication is interested in the transfer of data.INTRODUCTION TO DATA COMMUNICATION  Data communication is the transfer of data or information between a source and a destination. The actual generation of the information is not part of data communication nor is the resulting action of the information at the destination. Concepts of Data Transmission The transmission of information The communication system is responsible for the transmission of information from the sender to the recipient. the transfer of information is usually between two or more computers. At its simplest the system contains  Transmission channel that is the physical link between the communication parties. Frame relay. ATM.  Transmitter that actually introduces the modulated signal into the channel. 3G. usually amplifying the signal as it does so. GPS.  The day-to-day transactions at departmental stores. X. Data communication is also called as Computer Communication because.  Rapid advances in computers and communication technologies have resulted in the merging of these two technologies. reservation counters and other businesses are all dependent upon computer networks. or between computers and their terminals.  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).25.  Since basic Concepts of Data Communication and Networking remains the same and will lay a firm foundation on which new technologies can be built. The lines have blurred between computing. today. and the same digital techniques are being used for data.  A modulator that takes the source signal and transforms it so that it is physically suitable for the transmission channel. Transmitter Channel Receiver Demodulator 67 or . etc.. voice and image transmission. banks. with technology galloping towards ISDN. Wireless. The information age is equally dependent on the computer and the computer network.  Demodulator that receives the original source signal from the Sink received signal and passes it to the sink. printers and other peripheral devices. it is essential for students to equip themselves with the knowledge of Data Communication and Networking. TCP/IP. GPRS.  Today. switching and digital transmission equipment. the words analog and digital refer to the message. since they are continuously varying voltages or fields. like speech. This work is done by the modem used to connect computers to the PSTN. Data transmission refers to the movement of the bits over some physical medium connecting two or more digital devices. On the other hand. 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.  When used to describe the modulation. then an ADC must first convert it to a digital sample. or between to computers. so long as they are made to conform to the analog expectations of the system. The signals transmitted over the channel are called Carrier. The PSTN is an analog system. commands and other control information between the computer and its terminals. digital systems cannot transmit analog signals. This information is in form of bits. DATA TRANSMISSION: There is always a need to exchange the data. 68 . An analog system is designed for transmitting analog signals. The PSDN is a digital system. All signals transmitted by the system are analog.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 can transmit digital signals. If the message source is analog. A digital system is designed to transmit digital signals. because their greater speed relies on the digital form of the message. ASYNCHRONOUS TRANSMISSION: 69 . If only one bit of information can be transmitted over the data transmission medium at a time then it is considered a serial communication.2) SERIAL TRANSMISSION The physical connection determines how many bits (1’s and 0’s) can be transmitted in a single instance of time. 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. the next byte can be sent after an arbitrary delay. the samples will be spaced closer together (higher frequency-shorter period).. Condition 1: If the receive station’s clock is higher in frequency than the transmitted frequency. Free-running means the clocks are not locked together. Asynchronous transmission requires the transmitting station and receiving station to have individual internal free-running clocks (operating at the same frequency).  The receiving station starts checking for data after the start bit is received (the start bit is wake up call). Note: Receive clock frequency higher than transmitted frequency. The samples are out of synchronization with the 70 . the characters are sent individually with a quiet period in between (quiet meaning 0 bit level). This is usually achieved by providing two extra bits. In the above example. Preceding each character is a start bit and ending each character is one or more stop bits. The samples are evenly spaced. after sending a byte. The MSB is sent first and the LSB is sent last. the time occurrences of the clock pulses at the receiving end need to be synchronized repeatedly for each byte. In asynchronous transmission. Asynchronous transmission refers to the case when the sending end commences transmission of bytes at any instant of time. They match the transmitted data because both transmit and receive clocks are operating at same frequency. with one being the typical number of stop bits that were used today. There could be one or two stop bits. We call an action asynchronous when the agent performing an action does so whenever it wishes. we transmitted the following data: 0100 1010.  The purpose of the stop bits is to indicate the end of data.  Asynchronous transmission sends only one character at a time. a start bit at the beginning and a stop bit at the end of the byte. i. Typically. The purpose of the start bit is to notify the receiving station of a new arriving character.e. but we received the data: 0100 0101. The receiving station samples the transmitted data in the middle of each data bit. data is shown moving from left to right.  Due to the arbitrary delay between consecutive bytes. This is how it would appear on either a storage oscilloscope or a network analyzer. a number or a control character. Only one byte is sent at a time and there is no time relation between consecutive bytes. A character can be a letter of the alphabet. SYNCHRONOUS TRANSMISSION:  A synchronous action. In synchronous transmission. Again. is carried out under the control of timing source. The receiver first detects the flag and then identifies the boundaries of different bytes using the counter. This is a basic problem with asynchronous communication: both transmitter and receiver require a very stable clock to work properly. The flag identifies the start of a block. called flag. but the received data is 0101 0101. This start frame is used to tell the receiving station that a new packet of character is arriving. and it synchronizes the receiving station’s internal block.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).transmitting data. it is used at low frequency/slow transfer rates. we would have an error in receiving data.  The bytes lose the identity and their boundaries need to be identified. Just after the flag there is the first bit of the first byte. The packet can contain up to 64. ASYNCHRONOUS V/S SYNCHRONOUS TRANSMISSION: 71 . bits are always synchronized to reference clock irrespective of the bytes they belong to. Continuous transmission of bits enables the receiver to extract the clock from the incoming electrical signal. Condition 2: If the receiving station’s clock is lower in frequency than the transmitted frequency. The start and end frames can be only to bytes each. Therefore a unique sequence of a fixed number of bits. The packets also have end frames to indicate the end of the packet. At high frequencies (which results in high transfer rates). clock stability is critical and asynchronous transmission is very difficult to accomplish. Bytes are transmitted in a block in a continuous stream of bits. The transmitted data is 0100 1010. Because of this inherent problem with asynchronous transmission. the samples become out of sync with the transmitted data.  Synchronous transmission sends packets of characters at a time. There are no start or stop bits. Each packet is preceded by a start of frame. unlike an asynchronous action. Therefore. then the samples become farther apart (lower frequency-wider period). is prefixed to each block. We would again have received data errors.  Conventional representation has asynchronous data flowing left to right and synchronous data flowing right to left. It is used with all higher-communication transfer rates (Ethernet. Example: Compare a 10K byte data transmission using asynchronous transmission versus synchronous transmission. only 4 bytes (3 start frame bytes and one stop framing byte) are required to transmit up to 64 kbits. up to a maximum of 56 kbps). Synchronous transmission is more difficult and expensive to implement than asynchronous.032 kbits transmitted Efficiency = data transmitted X 100 = 80 kbits X 100 =99. Token Ring.). 11 bits are required to send 8 bits). For example. synchronous communications were operating over 2400/4800 Baud modems and on point-to-point communications. for every byte of data adds one start bit and two stop bits (i. It is used mainly with serial ports and dial-up connections. from 56 kbps to 100 Mbps).e. It also has the advantage that the receiver tracks any clock drift.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. Asynchronous: Add 3 bits (1 start and 2 stop bits) for every byte transmitted. It requires start and stop bits for each character: this adds a high overhead to transmission. 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. Asynchronous transmission is simple and inexpensive to implement. Asynchronous is used in slow transfer rates (typically. Synchronous is used in fast transfer rates (typically. which may arise (for instance due 72 . Determine the efficiency (10 kbytes =80 kbits).9% Total bits sent 80.  Historically. 80 kbits + 32 bits = total of 80.  Synchronous transmission is more efficient. etc. allowing operations at much higher data rates. For example.  For a binary two-level signal. i. One is bits/per second (bps) and the other baud (occurrence of signaling characters on the Transmission line). Baud rate defines the switching speed of a signal (i. modem transmitting binary data at 1. bit rate is twice the baud rate. Each signal element can have one of 16=2 4 different values. the baud rate indicates how often the signal changes the state). for example. The bit duration is not necessarily the pulse duration. In this case. two bits can be associated with one electrical level. There is a one-to-one correspondence between bits and electrical levels. 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. a data rate of one bit per second is equivalent to one Baud. Modulation rate is the rate at which the electrical signal changes its levels.e.200 = 4. If the 16-level signals are transmitted at 1.200 baud.200 baud. It is possible to associate more than one bit to one electrical level.to temperature variation).  Two units of speed are employed in data transmission.  When bits are transmitted as an electrical signal having two levels. the data rate is 4 X 1. The penalty is however a more complex interfaces design. the bit rate R will be 1/ t p .  Bit rate is simply the number of bits that can be transmitted in a second.. if the electrical signal has four distinct levels. Suppose a data transmission system uses signals with 16 possible discrete levels.200 bps is said to operate at 1.800 bps.e. 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 . and potentially a more difficult interface to configure (since there are many more interface options). the bit rate and the modulation rate of the signal are the same.600 bps. It is expressed in bauds (“per second” is implied). If tp is the duration of a bit. a signal element encodes 4 bits. For example.Bit rate defines the rate at which the information flows across a data link. RS232C (Recommended Standard 232 versions C). SPEED LIMITATIONS: Maximum speed is 19. RTS indicates to the DCE that the DTE wishes to transmit data. indicates that the DCE is ready to receive data from the DTE.g. Since the standard has been revised (e. the functionality of the data link). From the point of view of the standard. RS232D and RS232E). LIMITATIONS    OF RS232C: DISTANCE LIMITATIONS: RS232C is that it can transmit data reliably only up to 50 ft. 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). Data set ready (DSR): This is a signal from the DCE to the DTE. the nature of the transmission path and the signals required to control the operation of the modem (i. Clear to send (CTS): This is a signal from the DCE to the DTE and.e. When asserted. Data terminal ready (DTR): This is a signal from the DTE to the DCE.. This is called Unbalanced Transmission. it maintains the connection and 74 . their mechanics). the DCE is able to receive from the DTE.200 bps.e. When this signal is asserted. When asserted.its functions are very largely those needed to control a modem. In systems with a modem.Because RS232 was intended for DTE to DCE links . The following control signals implement most of the important functions of an RS232C DTE to DCE link. GROUND LIMITATIONS: All Control and Data signals are referenced against the same signal ground pin(pin 7). DTR indicates that the DTE is ready to accept data from DCE. which indicates the readiness of the DCE. The previous two limitations are caused by this limitation. RS232 specifies the plug and socket at the modem and the digital equipment (i. RS232C CONTROL LINES: The RS232 standard describes the functions carried out by several control signals between the DTE and DCE.. DSR indicates that the DCE (usually modem) is switched on and is in its normal functioning mode (as opposed to its self-test mode). Request to send (RTS): This is a signal from the DTE to the DCE.. when asserted. not milliseconds for many applications an online connection is needed. An optical system has components:  Transmission medium: Ultra thin fiber of glass or fused silica. The wires are twisted together in helical form. so the bandwidth of an optical transmission system is potentially enormous. FIBRE OPTICS Recent developments in Optical Technology have made it possible to transmit data by pulses of light. negating DTR is the same as hanging up a phone. out of phase (180 deg – phasor definition of opposite polarity) . the absence of a pulse signals a 0 bit . Transmission time is measured in min or hrs . just as a DNA molecule.Any noise that appears on one wire of the pair will also occur on the other wire. The most common application for the twisted pair is the Telephone System. In everyday terms. it cancels or nulls itself out at the receiving end .When the noise appears on both the wires. If DTR is negated. the delay characteristics are poor . 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. A Twisted Pair consists of two insulated copper wires typically about 1mm thick.keeps the channel open. A light pulse can be used to signal a 1 bit. the communication path is broken. Because the wires are opposite polarities. Twisted pairs can run several kms without amplification.  Detector: A photo diode which generates an electric pulse when light falls on it . both of which emit light pulse when an electrical current is applied. Each pairs consists of a wire used for the positive data signal & the wire used for negative data signal . 75 . Fiber optic links are being installed for long distance telephone lines. The wires in Twisted Pair cabling are twisted together in pairs. they are 180 deg. TWISTED PAIR: Although the bandwidth characteristics of magnetic tape are excellent.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).  Light Source: LED or a laser diode.Visible light has a frequency of about 106 MHz. 76 .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 RS232c cable to RS232 ports of both the two communication modules. Connect the power supply and switch on. 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. The LCD screen will be cleared and the following screen appears on the LCD. The LCD screen will be cleared and the following screen will appear on LCD. 77 . The LCD will be cleared and the following screen appears on the screen. 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. 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. Select from the Menu for serial communication by pressing key “2” on the main menu. Procedure:      In this experiment one node will be Tx mode for 10 secs and shifts to Rx mode for another 10 secs. 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. The data is also transmitted when the buffer is filled (the max size of the buffer is 40 bytes). which is in transmission mode.e. *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. The vice versa action occurs at other node.. the nodes exchange the information will be shifted to the Transmitter mode and another one to the Receiver mode automatically. but the node shifts to transmission mode only after the expiry of the time slot (10 secs). The data can be entered using the keyboard for the node. Repeat the experiment for 300 Baud rate*. 78 . 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). When both the embedded nodes are chosen for RS-232 as explained in the above steps. Logical Low signal is represented +3 to +12 V and Logical High signals are represented as -3 to -12V). The received data will be displayed in the node in reception mode. Experiment 2 Objective: To conduct an experiment to implement serial communication in Asynchronous mode using the media: 1) Twisted Pair 2) RS-232c 79 . Data received is slower than Parallel communication.   Hence. Cable used for communication is of 3 lines (Tx. Behavior of DTEs with different Baud rates. the noise interference can be avoided up to 15m to 50feets. Rx and Gnd). Select from the Menu for serial communication by pressing key “2” on the main menu. Connect the communication module to the main controller card using 60 pin FRC cable. The LCD will be cleared and the following screen appears on the screen. Connect the RS232c cable to RS232 ports of both the two communication modules. 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 .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. Enter Your Choice… (RS-232 medium) 1 -> Async Tx mode 2 -> Async Rx mode Menu 5 81 . The LCD screen will be cleared and the following screen appears on the LCD. The LCD screen will be cleared and the following screen will appear on 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. 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 will appear on LCD. when the user enters more than 60 bytes of Data). Cable used for communication is of 3 lines (Tx. Behavior of DTEs with different Baud rates. Rx and Gnd). After transmitting Data the control returns to the previous menu (Menu 5). One node is selected in transmission mode and the other node in reception mode. Logical Low signal is represented +3 to +12 V and logical high signals is represented as -3 to -12V). The size of the buffer is fixed to 60 bytes (characters).. The data will also be transmitted after prompting the user. Repeat the experiment for 300 Baud rate*.. Observation: In this experiment the students shall observe and analyze the     Principles of Asynchronous mode of serial communication. 82 . Hence the noise interference can be avoided up to 15m to 50feets. Data received is slower than Parallel communication.e. 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). Transmitting Node accept the data from the keyboard and transmits to the receiving end when the “ENTER” key is pressed.e. when the buffer is filled (i. Conversion of signals: Signal level are changed from TTL to RS232 levels (i. *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.Procedure:       The trainer has an option to act both as a transmitter and receiver and works in a half duplex communication. 83 . GENERAL LAYOUT OF CODE COMPOSER STUDIO 84 . Select target as TMS320C67xx (depends on the target processor we are using.out) file.> new. in our case it’s 67xx)... Give a appropriate project name. project type as executable (. the following screen will appear . and click finish in dialog box finally. 85 . In the main screen go to project .STEPS TO EXECUTE A PROGRAM USING CCS 1. 86 . Now a new project will be created(e.pjt) and a tree will be displayed on left hand side.g. linear.2. Go to File . 87 .> New .> Source file. Now we need to write C source code ..3. 4. 88 .Type the source code and click save. Now a blank screen will appear in which we have to write our C source code. 5.g. ‘lin.c’).When we press save icon in main screen. Save the file as C\C++ source file (e.c file . We have to save the source code file as . following dialog box will open. 89 .    C source code (e.. A library file (e. A linker command file (e.g.> Add files to project. Firstly add the source code file.cmd). hello..lib). Now we have to add 3 files to our project.c). rts6700. lin.6.g.. Go to Project . 90 .g. ..here browse for the source code file in projects directory and and click open ..(usually the common paths are .\ti\MyProjects\’projectname’\.) 91 .Now dialog box will open . .cmd).. add a library file from path.  Secondly.\ti\c6000\cgtools\lib\rts6700.Similarly Add two more files following same procedure .  First. add a linker command file from path …\ti\tutorial\dsk6713\hello1\hello.lcf.*. 7.the expanded project tree on left hand side will 92 . After the addition of all three files .lib (here file type is object and library file).cmd (here the file type is linker command file *. resemble this format.) 93 .(observe the LHS project tree which contains a library file. a source code and linker command file. 94 ..8.> compile file. Now the project will be compiled and any errors will be displayed below if there.>build. Now we need to compile and build our program. To build go to project . To compile go to project -. Now project will be built and any errors or warnings will be displayed below. A dialog box will open in which we have select executable .out file.out 95 . Go to file ..> load program. Now we need to load program in CPU or simulator .9. The usual path is …\ti\MyProjects\linear\debug\linear. Now we can assembly equivalent of C source code which the simulator has generated.10. 96 . . 97 .> Run . Go to Debug . To see the output of the program we have to run the program.11. 12. If the program needs any user input. a pop-up window will open. 98 . Now we can see output of the program below. . Graph title = ‘Any name’. Now a graph property dialog box will open up.> Graph .13. Go to View . DSP data type = 32-bit signed integer.. Index increment= 1(usually). Start address = “ the variable which we want to display”.. Select Display type = single time. Now we need to see the plot of output . DATA plot style = bar(for displaying discrete values).> Time\frequency. 99 . Grid style = Full grid. Now the graph will be displayed as shown below: *We can select different elements by using left and right keys of keyboard. 100 . Perform the Circular Convolution of the given sequence using Code Composer Studio. a2=0. a3=0. Compute the response of the system whose co-efficients are a0=0.2722. b2=0.873965 and when the input is two sine waves of frequencies 3000Hz and 400Hz . b1= -0. using Code Composer Studio. Find out the Discrete Time Convolution of the sequences x(n)={1 2 3 4 5 6} and h(n)={1 2 3 4}. 2. b2=0.005147. Verify the results graphically. b0=1.010295.1311 and b0=1.2622.Take sampling frequency as 24000Hz.0051477.CONTENTS 1.7478. 3. compute the system whose coefficients are a0=0. a1=0. 4. when the input is a unit impulse signal. b1= -0.1311. a1=0. Using Code Composer Studio. 101 .844881. 6.10.6] Output: y(n)=[1.0.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}.3.5.i++) printf("%d\n".0}.0.2.6.6] h(n)=[1.3.0.0.0.20.0. using Code Composer Studio.35. /*Lenght of i/p samples sequence*/ /*Lenght of impulse response Coeff*/ /*Input Signal Samples*/ /*Impulse Response Co-efficients*/ for(i=0.76.56. /* program to implement linear convolution */ #include<stdio. main() { int m=6.i++) { y[i]=0.4.73.0}.5.i<m+n-1.2.2. } Inputs: x(n)=[1.5.3. int n=6.h> int y[20].2.i<m+n-1.0.0.j.0. Verify the results graphically.70.4. int i=0.y[i]).36] 102 .60.5. } for(i=0. int x[15]={1.4.4.j<=i.4.3. for(j=0.j++) y[i]+=x[j]*h[i-j].0. int h[15]={1. h[30]. } y[0]=0.temp[30].y[30]. } for(i=m. scanf("%d".j.i<m.i<n.n.x2[30]. for(i=0.h> int m.Program 2 Problem: Perform the Circular Convolution of the given sequence using Code Composer Studio. a[0]=h[0].a[30]. printf(" enter the length of the second sequence\n"). if(m-n!=0) /*If lenght of both sequences are not equal*/ { if(m>n) /* Pad the smaller sequence with zero*/ { for(i=n.x[30]. scanf("%d". m=n.&x[i]). for(j=1. void main() { printf(" enter the length of the first sequence\n"). n=m.j++) scanf("%d".i++) x[i]=0.j<n. printf(" enter the first sequence\n").j<n.i.i++) h[i]=0.&n).j++) /*folding h(n) to h(-n)*/ 103 .i<m. for(j=0.&h[j]).i++) scanf("%d".k. /* program to implement circular convolution */ #include<stdio.&m). printf(" enter the second sequence\n"). i++) { a[i]=x2[i].a[j]=h[n-j]. } } /*displaying the result*/ printf(" the circular convolution is\n").i<n.y[i]).i<n.i++) printf("%d \t".j++) x2[j]=a[j-1]. for(k=1. x2[0]=a[n-1].j<n. for(i=0. } 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 .k<n.i++) y[0]+=x[i]*a[i]. /*circular shift*/ for(j=1.i<n. y[k]+=x[i]*x2[i].k++) { y[k]=0. /*Circular convolution*/ for(i=0. for(i=0. 0.0.0.0}.1311. y[2]=y[1].(y[1]*b[1])-(y[2]*b[2]).j++) { x[0]=impulse[j].0.2622.2722.0. for(j=0. main() { int j. x[2]=x[1].0. float z[10].2622. a1=0.7478. /*program to implement impulse response of the given sequence*/ #include <stdio.1311 and b0=1.7478. float x[3]={0. float a[3]={0.0.h> float y[3]={0.1311.j<10. x[1] = x[0].0.0.0}.0}. float impulse[10]={1. 0.Program 3 Problem: Compute the response of the system whose co-efficients are a0=0. } } 105 . b2=0. when the input is a unit impulse signal. b1= -0.0. float b[3]={1. 0. 0.2722}.1311}. y[1]=y[0]. -0. y[0] = (a[0] *x[0]) +(a[1]* x[1] ) +(x[2]*a[2]) . a2=0.y[0]). z[j]=y[0]. printf("%f\n". 024104 -0.0.013304 -0.131100 0.026565 -0.174741 0.2722} Outputs: 0.002718 0.360237 0.0.2622.-0.1311} Coefficient of y(n)={1.031373 -0.364799 0.7478.0.Inputs: Coefficient of x(n)={0.001589 Graph: 106 .1311. h> #include<math.n[128]. a3=0. float z[128]. main() { int i=0.j. float x[3]={0. 107 .010295.844881.0051477.Take sampling frequency as 24000Hz. b2=0. a1=0. compute the system whose co-efficients are a0=0.0.0}.873965 and when the input is two sine waves of frequencies 3000Hz and 400Hz .005147.m[128]. b1= -0.0.h> float y[3]={0.Program 4 Problem: Using Code Composer Studio.p[128]. /*program to implement differenceequation*/ #include <stdio. b0=1.0}. x[2]=x[1].float a[3]={0. y[0] = (a[0] *x[0]) +(a[1]* x[1] ) +(x[2]*a[2]) .005522 -0. float b[3]={1. z[j]=y[0].0. x[1] = x[0]. y[1]=y[0].844881.*/ y[2]=y[1].018097 0.000000 0.i++) { m[i]=sin(2*3.-0.010295.j<10.14*400*i/24000).005147. n[i]=sin(2*3.000000.i<10.003494 108 .j++) { x[0]=p[j].005147}.(y[1]*b[1])-(y[2]*b[2]). p[i]=m[i]+n[i].0.033484 0.004176 0.873965}.024796 -0.0.031289 -0.14*3000*i/24000).z[j]). } for(j=0. for(i=0.031259 0. printf("%f\n". /*z[j]=y[0]. } } OUTPUTS 0. 0.039590 Graph: 109 .
Copyright © 2024 DOKUMEN.SITE Inc.