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

DC Lab Manual

The document outlines the Digital Communication Lab course at Dayananda Sagar Academy of Technology & Management, detailing course outcomes and program outcomes for students in the Department of Electronics and Communication Engineering. It includes a list of experiments focused on digital modulation techniques such as ASK, PSK, and FSK, along with procedures for implementation and expected results. Additionally, it covers the application of Huffman coding for data compression in communication systems.

Uploaded by

bafnasiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
20 views

DC Lab Manual

The document outlines the Digital Communication Lab course at Dayananda Sagar Academy of Technology & Management, detailing course outcomes and program outcomes for students in the Department of Electronics and Communication Engineering. It includes a list of experiments focused on digital modulation techniques such as ASK, PSK, and FSK, along with procedures for implementation and expected results. Additionally, it covers the application of Huffman coding for data compression in communication systems.

Uploaded by

bafnasiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 39
DAYANANDA SAGAR ACADEMY OF TECHNOLOGY & MANAGEMENT Udayapura, Opp. Art of living, Kanakapura Road, Bangalore - 560082 iated to Visvesvaraya Technological University, Belagavi & Approved by AICTE, New; NAAC Accredited with A+ Grade DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING Accredited by NBA, New Delhi Digital Communication Lab (BECL504) PREPARED BY, Shalini M G, Assistant Professor Mahadey S, Assistant Professor Dr. Sumaiya M N, Associate Professor Dr. Banani Talukdar, Assistant Professor Dept. of ECE,DASTM Course Outcomes: At the end of the Course, the Student will be able to: Design the basic digital modulation and demodulation circuits for different CO1 | engineering applications 02 | Design of optimum communication receivers for AWGN channels lustration of different digital modulations using the signals and its equivalent CO3 | vector representations Implement the source coding and channel coding procedures using suitable co4 software Program Outcomes (POs) 1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an engineering specialization to the solution of complex engineering problems. 2. Problem analysis: Identify, formulate, research literature, and Analyze complex engineering problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and engineering sciences. 3. Design/development of solutions: Design solutions for complex engineering problems and design system components or processes that meet the specified needs with appropriate consideration for the public health and safety, and the cultural, societal, and environmental considerations. 4. Conduct investigations of complex problems: Use research-based knowledge and research methods including design of experiments, analysis and interpretation of data, and synthesis of the information to provide valid conclusions. 5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT tools including prediction and modelling to complex engineering activities with an understanding of the limitations. 6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice. Dept. of ECE,DASTM 7. Environment and sustainability: Understand the impact of the professional engineering solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable development. 8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering practice. 9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams, and in multidisciplinary settings. 10.Communication: Communicate effectively on complex engineering activities with ‘the engineering community and with society at large, such as, being able to comprehend and write effective reports and design documentation, make effective presentations, and give and receive clear instructions. 11.Project management and finance: Demonstrate knowledge and understanding of the engineering and management principles and apply these to one's own work, as a member and leader in a team, to manage projects and in multidisciplinary environments. 12.Life-tong learning: Recognize the need for, and have the preparation and ability to engage in independent and lifelong learning in the broadest context of technological change. SI LIST OF EXPERIMENTS N ° 1 Generation and demodulation of the Amplitude Shift Keying signal 2 | Generation and demodulation of the Phase Shift Keying signal 3 Generation and demodulation of the Frequency Shift Keying signal. 4 Generation of DPSK signal and detection of data using DPSK transmitter and receiver Dept. of ECE,DASTM 5 | Gram-Schmidt Orthogonalization: To find orthogonal basis vectors for the aiven set of vectors and plot the orthonormal vectors © | simutation of binary baseband signals using @ rectangular pulse and estimate the BER for AWGN channel using matched filter receiver. 7 | Perform the QPSK Modulation and demodulation. Display the signal and its constellation. 8 Generate 16-QAM Modulation and obtain the QAM constellation. 9 | Encoding and Decoding of Huffman code. 10 | Encoding and Decoding of binary data using a Hamming code. 11 | Fora given data, use the CRC-CCITT polynomial to obtain the CRC code. Verify for the cases, a) Without error b) With error ; Encoding and Decoding of Convolution code EXPERIMENT NO 1 AMPLITUDE SHIFT KEYING (GENERATION AND DETECTION) Aim: To design and study the working of ASK modulation and demodulation system with the help of suitable circuit Specifications: M(t) = 10V, 500Hz, C(t) = SV, 10KHz. Equipment used: BCLT-001 Trainer kit ~1 = ASK MODULATION CIRCUIT DIAGRAM: + ASK output Dept. of ECE,DASTM ASK DEMODULATION CIRCUIT DIAGRAM: DewoD oP ESCAPED ‘DEMODULATED Le ‘NAOT af bon uF The transmission of digital signals is increasing at ¢ rapid rate. Low-frequency analog signals are often converted to digital format (PAM) before transmission. The source signals are generally referred to as baseband signals. We can send analog and digital signals directly over a medium. From electro-magnetic theory, for efficient radiation of electrical energy from an antenna it must be at least in the order of, magnitude of a wavelength in size; c = fA, where c is the velocity of light, fis the signal frequency and \ is the wavelength. For a 1kHz audio signal, the wavelength is 300 km. An antenna of this sizeis not practical for efficient transmission. The low-frequency signal is often frequency translated to a higher frequency range for efficient transmission. The process is called modulation. The use of a higher frequency range reduces antenna size. Amplitude shift keying - ASK - in the context of digital communications is a modulation process, which imparts to a sinusoid two or more discrete amplitude levels. These are related to the number of levels adopted by the digital message. For a binary message sequence there are two levels, one of which is typically zero. Thus the modulated waveform consists of bursts of a sinusoid A binary ASK (BASK) waveis obtained by multiplying the message signal with the carrier. The B-ASK signal has two levels _1' and _0' representing the presence end absence of the sinusoid respectively. This can be shown in the waveform below. The message signal must be represented in NZR uni polar format only. Binary ASK system has the largest probability of bit error when compared to FSK and PSK systems. ‘There are sharp discontinuities shown at the transition points. These result in the signal having an unnecesserily wide bandwidth. Band limiting is generally introduced before transmission, in which case these discontinuities would be _rounded off’. The band limiting may be applied to the digital message, or the modulated signal itself. One of the disadvantages of ASK, compared with FSK and PSK, for example, is that it has not got a constant envelope. This makes its processing (¢.g., power amplification) more difficult, since linearity becomes an important factor. However, it does make for ease of demodulation with an envelope detector. Procedure: Dept. of ECE,DASTM 1.Connect the AC Adaptor to the mains and the other side to the experimental trainer. 2. Observe the Bit Clock frequency on the Oscilloscope. Adjust the frequency to 10 KHz and connect it to-. 3.Set the SPDP switches pattern to the desired code (say 0000 1111) 4, Parallel load by changing the switch to opposite side to shift side for a short duration and get back to shift position 5. Observe the & Bit word pattern at the output of the 8 Bit word generator. This is the actual modulating signal 6. Adjust the carrier frequency of— KHz and — Volt p-p, give this input to the ASK modulator inputs using a patch chord 7.Connect the 8 Bit word generators output to the data input terminal of the ASK Modulator. 8.0bserve the data input on one channel on a CRO and ASK output on the second channel. 9.To get demodulated signal, connect the ASK modulator output to demodulator input 10. Adjust the two knobs simultaneously to get the original digital message at the demodulator output on a CRO. Pre-viva Questions: 1. State different types of Digital modulation techniques? 2. Whatis shift keying? What are applications of shift keying? 3. What is a binary modulation technique? 4, Define ASK? Table : ASK Modulation & Demodulation (Amplitude & Frequency) SI. | input signal Bina Modulated signal | Demodulated signal no Ampitu | Frequen 5 . ‘Amplitu | Frequen | Amplitud | Frequenc de yy. ata de oy e y 1 2 3 Expected Waveforms + Msg signal 150Hz, 5V ANAM ALA AIA AT, TTT VV VY Carrier Signal 1 KHz, 5V Medulated 0/P Demodula ted 0/P. Verification/Validation: ASK waveforms are validated against expected output waveforms for different amplitude (1 - 10V) values of message signal and is found correct. Conclusions: ASK setup is Implemented using ASK BCLT-001 Trainer kit and the waveforms are validated and verified. Experiment No 2 PSK generation and detection Aim: To design and study the working of PSK modulation and demodulation using suitable circuit. Theory: Dept. of ECE,DASTM Phase shift keying is one of the most efficient digital modulation techniques. It is used for very high bit retes. In PSK, the phase of the carrier is modulated to represent Binary values. In BPSK, the carrier phase is used to switch The phase between 00 and1800 by digital polar Format. Hence it is also knowin as phase reversal keying. The modulated carrier is given by: Binary 1: (1) = Acva. Cos. (2nfet) Binary 0:$ (f) = Acs. Cos. (2nfet + 180) = Acow. Cos. (2nfet) Design: For modulator : Ve-5VeeVn-8 Vor , fn 100Hz, fe-Tkhz, Assume hfe=B= 50, Vbe(sat)=0.8V, Vce(sat)= 0.2V, Ic= 10 ma= Ie, Vm(peak)= IcRe+Vce(set)....e5= IbRD+0.8 Ib=4.2/RB_ (B=50, Rb=22kQ(63kOmax value); Ve(peak)= IcRct+Vce(sat)+eRe; le=Vo(p)- VCE(sat)/Re....e 1.8/Re Ib>Ic/B...,¢4.2/RB>1.8/ReB Assume Re=4.7K0 therefore Rb=2.2k0 For demodulator: 1/fo>RC> 1/Fel 3.3ms>RC>Ims Let Re= 2.2ms, C=0.2uf, Circuit Diagram: Modulation: r*—_t ow, bel Pr Demodulation: Dept. of ECE,DASTM Inverting summing amplifier Envelop detector Comparator Procedure: 1) The connections are made as per the circuit diagram. 2) A sine wave of amplitude Sv and 2kHz is fed to the Collector of the transistor as carrier. 3) the message signal, a square wave of amplitude SV and 150Hz is fed to the base of the transistor. 4 5 6) BPSK wave obtained is fed as input to the demodulation circuit. 7) The demodulated waveform is observed The BPSK wave is observed at pin 6 of the op-amp IC 741 The demodulation circuit is also connected ) ) ) ) ) ) ) ) 8) All the required waveform to be plotted Waveforms: Dept. of ECE,DASTM Demodulated output Result: Experiment No 3 FSK generation and detection To design and study the working of FSK modulation and demodulation with the help of a suitable circuit Theory: Asits name suggests, @ frequency shift keyed transmitter has its frequency shifted by the message. Although there could be more than two frequencies involved in an FSK signal, in this experiment the message will be a binary bit stream, and so only two frequencies will be involved. The word ,keyed" suggests that the messages of the ,on-off" (mark-space) variety, such as one (historically) generated by a morse key, or more likely in the present context, a binary sequence. Conceptually, and in fact, the transmitter could consist of two oscillators (on frequencies f1 and {2), with only one being connected to the output at any one time. Unless there are special relationships between the two oscillator frequencies and the bit clock there will be abrupt phase discontinuities of the output waveform during transitions of the message. Bandwidth: Practice is for the tones f1 and {2 to bear special inter-telationships, and to be integer multiples of the bitrate. This leads to the possibility of continuous phase, which offers advantages, especially with respect to bandwidth control. FSK signals can be generated at baseband, and transmitted over ‘telephone lines (for example). In this case, both f1 and f2 (of Figure 2) would be audio frequencies. Alternatively, this signal could be translated to a higher frequency. Yet again, it may be generated directly at carrier frequencies. Design: 0 Modulator. Re=VooVee/(I)=1k0 10K 0 Demodulator. Dept. of ECE,DASTM Low pass filter f-=2kHz, C=0.1pf fe R=7.9KQ (Choose 10KQ) Envelope Detector. fn=200Hz, fo=10KHz. Hence C=0.1pf, and R=10KQ Circuit Diagram: Modulator sine wave a= nie 2ve-r, ng aK rein tora mn ® one aver) Ve 10K 1 Tox B= 2h PPL Demodulator onra - i — sk o Om son one 3) Onmaautae sev vet -——— _ Lew pase Gwecte be Cormpaator. ——o} Procedure: 1. Rig up the modulator circuit as shown in the figure. 2. Apply cartier of amplitude 2 V(P- P) and frequency 1 kHz. 3. Apply carrier of amplitude 2 V(P- P) and frequency 2 kHz. 4. Apply message signal of amplitude 10 V(P -P) and frequency of 250 Hz 5. Observe ASK outputs at each collector of transistor, and also observe FSK output at pin6 of op- amp. Dept. of ECE,DASTM 6. Connect demodulator circuit. m Muu = ne Implement the following in C/C++/MATLAB/Scilab/Python or any other Suitable software rite a MATLAB program to encode binary data using Huffman code and decode it. Aim: To write a MATLAB program to encode and decode binary data using Huffman code. Theory: Huffman coding is a widely used method for lossless data compression, named after David A Huffman who introduced it in 1952. It's a variable-length prefix coding algorithm used to compress data, where the most frequent symbols are represented using shorter codes and the least frequent symbols are represented using longer codes Encoding the information before transmission is necessary to ensure data security and efficient delivery of the information. The MATLAB program presented here encodes and decodes the information and also outputs the values of entropy, efficiency and frequency probabilities of characters present in the data stream Huffman algorithm is a popular encoding method used in electronics communication systems. It is widely used in all the mainstream compression formats that you might encounter—from GZIP, PKZIP (winzip, etc) and BZIP2, to image formats such as JPEG and PNG. Some programs use just the Huffman coding method, while others use it as one step in a multistep compression process. Huffman coding & deciding algorithm is used in compressing data with variable-length codes. The shortest codes are assigned to the most frequent characters and the longest codes are assigned to infrequent characters. Procedure: Step 1. Compute the probability of each character in a set of data. Step 2. Sort the set of data in ascending order. Step 3. Create a new node where the left sub-nodeis the lowest frequency in the sorted list and the right sub-node is the second lowest in the sorted list. Step 4. Remove these two elements from the sorted list as they are now part of one node and add the probabilities. The result is the probability for the new node. Step 5. Perform insertion sort on the list. Step 6. Repeat steps 3, 4 and 5 until you have only one node left. Dept. of ECE,DASTM © Build the Huffman tree: af @ &h of Wh PROGRAM SaWrite a MATLAB based program for encoding and decoding of Huffman code’ (variable length source coding ) clc;clear all; close all; symbol =[1:5]; % Distinct data symbols appearing in p = [0.4 0.20.20.1 0.1]; % Probability of each data [dictavgler]=huffmandict(symbol p) samplecode = dict{5,2} % Codeword for fifth signal value dict(1 ;}dict{2, }dict(3,}dict(4,}dict{5,:) heode = huffmanenco(symbol,dict); dhsig = huffmandeco(hcode,dict); % Decode the code. disp(encoded msg:); displhcode); disp(decoded msg:); disp(dhsig); code_length=length(heode) H=sum#(p(m)4log2(1/p(m))); end yi disp(H= Efficiency=(H/avglen)*100 disp(H); Description ‘© symbols: A cell array of symbols to be encoded ‘© probabilities: A vector of probabilities corresponding to each symbol. The probabilities should sum up to1 Dept. of ECE,DASTM The function returns a cell array dict, which is a Huffman dictionary containing symbols and their corresponding Huffman codewords This program defines two functions: huffmanenco is used to encode data using the Huffman coding technique based on a given Huffman dictionary. Huffman encoding replaces each symbol with its corresponding Huffman codeword from the dictionary, resulting in a compressed representation of the data, and huffmandeco is used to decode data that has been encoded using the Huffman coding technique, based on a given Huffman dictionary. It takes the encoded data and the Huffman dictionary as input, returning the decoded data. Output dict = 5<2 cell 1 2 1 1 1 2 2 (0.0.01 3 3 10.4 4 4[__ [0.1.4] 5 5] [0.0.1.0] avelen = 2.2000 samplecods = isd eo 12 @ ancoced meg: 1 08 @ © @ 1 @ @ 1 1 0 @ 2 decoced msg: 2203 4 5 code_length = 14 e.3522 Efficiency = 15.0997 Manual verification: Conclusion: Thus, Huffman coding efficiently represents the input data using variable length codes, achieving compression by using shorter codes for more frequent symbols Dept. of ECE,DASTM 5.Write a MATLAB program to encode binary data using a (7,4) Hamming code and decode it. Aim: To write a MATLAB program to encode binary data using a (7,4) Hamming code and decode it. Theory: The (7,4) Hamming code is an error-correcting code that allows the correction of single-bit errors and the detection of two-bit errors. It operates on 4 bits of data and adds 3 parity bits to form a Tit codeword Let's go through the steps to encode and decode a (7,4) Hamming code Encoding (4-bit data to 7-bit codeword): 1. Data Preparation: Let's assume we have a 4-bit data sequence (D3, D2, D1, DO). 2. Calculate Parity Bits (PO, P1, P2): © POis the parity bit for bits: DO, D1, D3 ‘* Plis the parity bit for bits: DO, D2, D3 © — P2is the patity bit for bits. D1, D2, D3 3. Insert Parity Bits: Place the calculated parity bits at their respective positions in the 7-bit codeword. 4, Form the Codeword: The codeword is now composed of the original 4 bits of data and the 3 parity bits. The resulting 7-bit codeword structure is as follows: Codeword=(P2,P1,D2,P0,1,00,P0) Decoding (7-bit codeword to 4-bit dat: 1. Calculate Syndrome Bits (S2, S1, $0): — SQisthe parity of bits: PO, D1, DO, P2, D2, P1 ‘© Slis the parity of bits: P1, D2, D1, PO, DO, P2. © SZis the parity of bits: P2, D2, D1, P1, DO, PO. 2. Determine Error Position: Use the syndrome bits to identify the position of the error, if any. The binary representation of the syndrome bits indicates the error position 3. Correct Error: if an error is detected, correct the bit at the identified error position. 4. Extract Data Bits: Remove the parity bits to obtain the 4-bit original data Procedure: Let's consider a 4-bit data: 1011 (D3, D2, D1, DO). 1. Calculate Parity Bits: ‘* PO (parity for bits: DO, D1, D3) = DO xor D1 xor D3 = 1 xor 0 xor 1 = 0 (PO is the leftmost bit) © P1 (parity for bits: DO, D2, D3) = DO xor D2 xor D3 = 1 xor 1 xor1 = 1 © P2 (parity for bits: D1, D2, D3) = D1 xorD2 xor D3 = Oxor1 xor1 = 0 2. Insert Parity Bits: © Codeword: (0, 1, 1, 1, 0, 1, 0) Now you have the encoded (7,4) Hamming codeword. Dept. of ECE,DASTM PROGRAM “Simulation for encoding and decoding of a [7,4] Hamming code. The decoder Secan correct one error as shown and as theory states. The table at the end ‘of the file shows the various outputs with different error positions and ‘Samessage bits. One error can be placed at any of the 7 bit locations and ‘ecorrections made. cle;clear all; close all; n= 7%# of codeword bits per block k = 4%i of message bits per block 11.131 10101011 ]:%Parity submatrix-Need binary(decimal combination of 7.6.5.3) G = [eye(k) A]?:Generator matrix A eye(n-k) |’sParity-check matrix % ENCODER% msg =[1111] %Message block vector-change to any 4 bit sequence code = mod(msg'G,2) Encode message % CHANNEL ERROR(add one error to code)% S%eode(1)= ~code(1); code(2)= ~code(2); Secode(3)= ~code(3); code(4)= ~code(4);%Pick onecomment out others Sscode(5)= ~code(5); Sscode(6)= ~code(6); %code(7)= ~code(7); recd = code %Received codeword with error % DECODER% syndrome = mod(recd * H:2) ‘Find position of the error in codeword (index) fir forii=1:n if find errvect = zeros(1,n); errvect(ii) search = mod(errvect * H!2); if search == syndrome find index end end end disp({Position of error in codeword=num2str(index)]); correctedcode = recd; correctedcode(index Strip off parity bits msg_decoded=correctedcode; msg_decoded=msg_decoded(1:4) mod(recd(index)+1,2)%Corected codeword Dept. of ECE,DASTM ‘Error position Syndrome Decimal 4 bit word codeword dmin % 1 m1 7 0000 0000000 % 2 110 6 0001 0001011 3 %® 3 101 5 0010 0010101 4 % 4 on 3 0011 00111103 % 5 100 4 0100 100110 3 % 6 010 2 0101 0101101 3 % 7 001 1 0110 1100114 ‘%No error will give syndrome of 000 01110111000 3 % 1000 1000111 4 % 1001 1001100 3 % 1010 «1010010 4 % 1011 1011001 3 % 1100 1100001 3 % 1101 1101010 3 % 11101110100 4 % ww 1111111._ 3 ‘Any exclusive or additions of any two codewords should give another Secodeword In MATLAB, the eye function is used to create an identity matrix, which is a square matrix with ones on the main diagonal and zeros elsewhere. Where n is the number of rows (and columns) in the resulting identity matrix. Output n 7 ke 4 G= 1000111 01003110 0010101 oo0o01011 H= 117110100 1101010 10711001 Dept. of ECE,DASTM syndrome = 110 Position of error in codeword=2 correctedcode = cn msg_decoded = 1114.4 Manual verification: Conclusion: Thus a MATLAB program is written to encode and decode binary data using a (7,4) Hamming code and resulis have been verified 6.Write a MATLAB program to encode binary data using a ((3,1,2)/suitably designed) Convolution Dept. of ECE,DASTM code and decode it. Aim: To write a program to encode binary data using a ((3,1,2)/suitably designed) Convolution code and decode it. Theory: Creating a complete MATLAB program for encoding and decoding using a specific convolutional code requires a significant amount of code and understanding of the specific code parameters (rate, constraint length, generator polynomials, etc.). Ill provide you with a general outline and steps to create the encoding and decoding processes for a (3,1,2) convolutional code. Procedure: let's define the generator polynomials for a (3.1.2) convolutional code: Generator polynomials: © gl={1,0,1] e g2=(1,1,1] Encoding: 1. Define the input binary data. 2. Setup the convolutional code parameters (generator polynomials, rate, constraint lenath, etc.) 3. Use the convene function to perform convolutional encoding on the input data. Decoding: 1. Define the received encoded data (potentially with added noise or errors) 2, Set up the Viterbi decoder parameters (trellis structure, traceback depth, etc.) 3. Use the vitdee function to perform Viterbi decoding on the received encoded data % Parameters for the (3,1,2) convolutional code constraint length = 3; generator_polynomials = [10 1;11 1]; code_rate = 1/3; t= poly2trellis(constraint_length, generator_polynomials); % Define input binary data input_data = [1.010 1]; % Example binary data % Encoding using convolutional code encoded_data = convenc(input_deta, t); % Add some noise or errors (optional, for simulation purposes) received_data = encoded_data; % Simulated received data ‘% Decoding using Viterbi decoder tb_depth = 12; % Traceback depth decoded_data = vitdec(received_data, generator_polynomiels tb_depth, 'trunc’, hard); % Display results Dept. of ECE,DASTM disp( Original Data’); disp(input_data); disp(Encoded Data’); disp(encoded_data); disp( Received Data’); disp In this example, convenc is used for encoding, and vitdec is used for decoding with a Viterbi decoder. Make sure to adjust the input data, generator polynomials, and other parameters based on your specific requirements for the convolutional code. or function encoded_bits = convolutional_encoder(input_bits) % Define the convolutional code matrices 61=[110), 62= [101] % Initialize the output stream output_stream = % Perform convolutional encoding for i= 1:length(input_bits) % Extract the current input bits for encoding input_segment = input_bits(ici+2); % Perform convolutional encoding for each output bit output_bit! = mod(sum(input_segment * G1), 2); output_bit2 = mod(sum(input_segment * G2), 2); % Append the output bits to the output stream, outputstream = [output_stieam, output_bit1, output_bit2); end % Return the encoded bits encoded_bits = output_stream; end function decodec_bits = convolutional_decoder(encoded_bits) % Define the trellis structure for Viterbi decoding trellis = poly2trellis(2, [7 5]); % Generator polynomials: (7,5) % Perform Viterbi decoding decoded bits = vitdec(encoded_bits, trellis, §, trunc, hard’); end % Generate random binary input data input_bits = randi((0 1], 1, 100); Dept. of ECE,DASTM ‘6 Encode the input bits using the convolutional encoder encoded _bits = convolutional_encoder(input_bits); ‘% Simulate channel noise (you can modify this based on your requirements) noisy_encoded_bits = mod(encoded bits + randi((0 1], size(encoded_bits)), 2); % Decode the noisy encoded bits using the convolutional decoder decoded_bits = convolutional_decoder(noisy_encoded_bits); % Display results disp(‘Input Bits’); disp(input bits); disp(Encoded Bits:); disp(encoded_bits); disp(‘Noisy Encoded Bits:’); disp(noisy_encoded_bits); disp( Decoded Bits:); disp(decoded_bits); Manual verification: Conclusion: Thus a MATLAB program is written to encode binary data using ¢ ((3,1,2)/suitably designed) Convolution code and decode it and results have been verified. % Parameters for the (3,1,2) convolutional code cle; clear all; close all; trel = poly2trellis(«[G1 G2); coded = convenc(msg,trel); tblen = length(msg); decoded = vitdec(coded,treltblen,runc’/hard) Dept. of ECE,DASTM 7.For a given data, use CRC-CCITT polynomial to obtain the CRC code. Verify the program for the cases a) Without error b) With error Aim: To obtain the CRC code for a given data using CRC-CCITT polynomial and to Verify the program for the cases a) Without error b) With error Theory: The cyclic redundancy check, or CRO, is a technique for detecting errors in digital dete, but not for making corrections when errors are detected. Itis used primarily in data transmission This Cyclic Redundancy Check is the most powerful and easy to implement technique. CRC is based on binary division. In CRC, a sequence of redundant bits, called cyclic redundancy check bits, are appended to the end of data unit so that the resulting data unit becomes exactly divisible by a second, predetermined binary number. At the destination, the incoming data unit is divided by the same number. If at this step there is no remainder, the data unit is assumed to be correct and is therefore Dept. of ECE,DASTM accepted, A remainder indicates that the data unit has been damaged in transit and therefore must be rejected. The CCIT.T CRC-16 polynomial (used in a variety of applications) is represented by the polynomial x'"+x “4x'+1, which corresponds to the hex value 0x1021. We'll create a MATLAB program to generate the CRC code for a given input data and then simulate both cases. without error and with error in the received data Procedure: 1. Generate CRC for the given data using the CRC-CCITT polynomial 2. Introduce an ertor in the data 3. Recalculate CRC for the erroneous data. 4. Verify if the CRC detects the error. Start with a 16-bit binary number, which is the message to be transmitted: 1101100111011010 32 To obtain the check value, divide this number by the polynomial x +x +x+1. You can represent this polynomial with its coefficients: 1111 The division is performed in steps, and after each step the polynomial divisor is aligned with the left- most 1 in the number. Because the result of dividing by the four term polynomial has three bits (in general dividing by a polynomial of length n+1 produces a check value of length r), append the number with 000 to calculate the remainder. At each step, the result uses the bitwise XOR of the four bits being operated on, and all other bits are unchanged. The first division is 1101100111011010 000 m1 0010100111011010 000 Each successive division operates on the result of the previous step, so the second division is 0010100111011010 000 nn 0001010111011010 000 The division is completed once the dividend is all zeros. The complete division, including the above two steps, is 1101100111011010 000 m1 0010100111011010 000 m1 0001010111011010 000 m1 Dept. of ECE,DASTM 0000101111011010 000 wu 0000010011011010 000 mn 0000001101011010 000 mn 0000000010011010 000 wu 0000000001101010 000 mn 0000000000010010 000 m1 0000000000001100 000 mn 0000000000000011 000 nu d000000000000000 110 ‘The remainder bits, 110, are the check value for this message. PROGRAM cleclear all close all; % The program generates CRC code for any given input message stream & % generator polynomial %msg=[11100011] put Input Message sequence :); [110011] put( Input Generator Polynomial :'); [M Nesize(poly); mseg=[msg zeros(1.N-1)]; [q d=deconv(mseg,poly); rabs(); for i=1:length(r) a=r(i); if (mod(a,2)==0) (i) =0; else 1()=1; Dept. of ECE,DASTM end end cre=r(length(msg)+1:end) frame = bitormsegy) % Calculate check value message = 001101100111011010u32; messageLength = 16; divisor = 061111432; divisorDegree = 3; divisor = bitshift(divisormessageLength-divisorDegree-1); dd=dec2bin(divisor) ‘initialize the polynomial divisor. Use dec2bin to display ‘the bits of the result shift the divisor and message so that they have the correct ‘% number of bits (16 bits for the message and 3 bits for the remainder) divisor = bitshift(divisordivisorDegree); remainder = bitshif'(messagedivisorDegree), sdd=dec2bin(divisor) sdr=dec2bin (remainder) ‘ePerform the division steps of the CRC using a for loop. SeThe for loop always advances a single bit each step, so include % a check to see if the current digit is a 1. If the current digit is a 1, % then the division step is performed; otherwise, the loop advances a bit and continues. for k= 1:messageLength if bitget(remaindermessagel engthtdivisorDegree) remainder = bitxor(remainderdivison); end remainder = bitshift(remainder.1); end ‘SeShift the bits of the remainder to the right to get the check value for the operation. CRC_check_value = bitshift(remainder-messageLength); scre=dec2bin(CRC_check_value) ‘eYou can use the check value to verify the integrity of a message by repeating ‘% the same division operation. However, instead of using a remainder of 000 to start, % use the check value 110. If the message is error free, then the result of the division ‘ will be zero.Reset the remainder variable, and add the CRC check value to ‘% the remainder bits using a bitwise OR. Introduce an error into the message % by flipping one of the bit values with bitset. remainder = bitshift(message,divisorDegree); remainder = bitor{remainderCRC_check_value); remainder = bitset(remainder,6); br=dec2bin(remainder) for k= T:messageLength if bitget(remaindermessageL engthtdivisorDegree) remainder = bitxor(remainder,divison); end remainder = bitshift(remainder.1); end if remainder == disp(’Message is error free’) Dept. of ECE,DASTM else disp(‘Message contains errors.’) end OUTPUT: CRC generation Input Message sequence ‘[1 110001 1] Input Generator Polynomial {1 1001 1] cre= 11010 frame = 1171000311711 010 Check value calculation message = 0b1101100111011010u32; dd= '1111000000000000 sdd = 1111000000000000000' sdr= ‘1101100111011010000° sere = ‘110° br= '1101100111011110110' Message contains errors. In this program, bitshift is a MATLAB function that performs bitwise shifting on integer values. It shifts the bits of an integer to the left or right by a specified number of positions. dec2bin is a MATLAB function used to convert decimal (base-10) numbers to binary (base-2) representation. Manual verification: Dept. of ECE,DASTM Conclusion: The CRC code is obtained fora given data using CRC-CCITT polynomial and the program is verified for the cases a) Without error b) With error. 8.Gram-Schmidt Orthogonalization: To find orthogonal basis vectors for the given set of vectors and plot the orthonormal vectors. Aim: To write a MATLAB program to find orthogonal basis vectors for the given set of vectors and plot the orthonormal vectors using Gram-Schmidt Orthogonalization % Program cle; clear all; close all; % Input matrix A=[13;4-7;-1 12], % Initialize matrices rows, n] = size(A); % Dimensions of A Q = zeros(ows, n); % Orthogonal matrix QN = zeros(rows, n); % Orthonormal matrix % Gram-Schmidt Process forj=t:n Dept. of ECE,DASTM v= AG, j); % Start with the j-th column of A fori= 1:1 % Projection of A(;,) on Q(:i) rij = QGi)'*AG j)) / QG.)'* QG, 1); v =v-rij* Q(, i); % Subtract projection end Q(, j) = v; % Store orthogonal vector QN(, j) =v / norm(y); % Normalize to unit norm end ‘% Verify orthogonality and normalization orthogonallty_check = sqrt(diag(Q! * Q));% Norms of orthogonal vectors disp(Input vector is:'); disp(A); disp(ortho ='); disp(orthogonality_check); disp(‘orthonormal ='); disp(QN.' * QN); % Identity matrix for orthonormal vectors Result Input vector is A= 1 3 “1-12 ortho = 4.2426 0 0 13.8784 orthonormal = 1.0000 0.0000 0.0000 1.0000 Dept. of ECE,DASTM Dept. of ECE,DASTM 9. Perform the QPSK Modulation and demodulation. Display the signal and its constellation Program % Define input data data = [110101001 0); % information % Modulation M= 4; % Number of symbols k = log2(M); % Number of bits per symbol bits_per_symbol = length(data) / k; data_reshaped = reshape(data, k, bits_per_symbol)’; symbol = bi2de(data_reshaped, left sb’); % Generate QPSK modulation symbols modulated_signal = pskmod(symbol, M, pi/4); % Phase offset pi/4 for QPSK ‘% AWGN Channel (Additive White Gaussian Noise) EbNo = 10; % Energy per bit to noise power spectral density ratio (dB) SNR = EbNo + 10*l0g10(k); % Signal to Noise Ratio (4B) px_signal = awgn(modulated_signal, SNR, measured); % Demodulation demodulated_signal = pskdemod(rx_signal, M, pi/4); % Phase offset pi/4 for QPSK % Convert symbols to bits demodulatad_bits = de2bi(demodulated_signal, k, left-msb)’; received_data = reshape(demodulated bits’, 1, [): numérrs = symerr(datareceived data) ‘% Plot original and received data figure; subplot(2,1,1); stem(data, ‘linewidth, 2); title(Original Data’); xlabel(Bit); ylabel(Amplitude); axis(0 lenath(data) 0 1.5)); subplot(2,1,2); stem(received_deta, ‘linewidth, 2); title(Received Data); xlabel(Bit); ylabel( Amplitude); axis((0 length(received_data) 01.5); ‘% Scatter plot Dept. of ECE,DASTM ‘% Define demodulated symbols demodulated_symbols = demodulated_signal; % Replace with your demodulated symbols ‘% Map demodulated symbols to complex constellation points constellation_points = [1+1i, -1+1i, -1-1i, 1-1i]; % QPSK constellation points figure) scatter(real(constellation_points(demodulated_symbols+1)), imag(constellation_points(demodulated_symbols+1))); title(QPSK Constellation Diagram); xlabel(In-phase Component’); ylabel( Quadrature Component); axis(-2 2-2 2));% Adjust axis limits if needed grid on; Output: 15 3 ? e Zos p e—e 2 o 1 2 8 4 8 6 7 8 $s ait ts Received Data gt 9 | 4 Sos | 9 o—e—e ee o 1 2 S @ 5 6 7 @ $ © Bit Dept. of ECE,DASTM QPSK Constellation Diagram Quacrature Component 15 05 08, 1 +8 Inphase Component Dept. of ECE,DASTM 11. Simulation of binary baseband signals using a rectangular pulse and estimate the BER for AWGN channel using matched filter receiver Aim of the Experiment: To simulate binary baseband signals using a rectangular pulse and estimate the BER for AWGN channel using matched filter receiver. Theory: Binary baseband signaling is the transmission of binary data (0s and 1s) over a communication channel using a baseband signal, such as a rectangular pulse. Binary data is represented using 2 rectangular pulse waveform. Each bit (0 or 1) is mapped to a signal with specific amplitude and duration. The rectangular pulse serves as the carrier for transmitting binary information, providing a straightforward method for modulation in baseband communication systems. An Additive White Gaussian Noise (AWGN) channel models the real-world communication medium, where the transmitted signal encounters random noise. AWGN is characterized by its constant power spectral density and Gaussian amplitude distribution. The matched filter is a signal processing technique used at the receiver to maximize the signal-to-noise ratio (SNR). It is designed to be the conjugate of the transmitted pulse, enabling optimal detection of binary symbols in the presence of noise. The output of the matched filter is then sampled at the optimal time instants to decide the transmitted bit. The BER quantifies the systems performance by measuring the ratio of incorrectly detected bits to the total tansmitted bits. For an AWGN channel, the theoretical BER can be derived and compared with simulated values to velidate system design and functionality Program code: ‘% Simplified Parameters N= 1e4; % Number of bits SNR_dB = 0:5:20; % SNR values in dB pulse_width = 1; % Pulse width for rectangular pulse ‘% Generate random binary data data = randi((0 1], N, 1); % Define the rectangular pulse Dept. of ECE,DASTM t= 0:0.01:pulse_width; rect_pulse= ones(size(t)); % Initialize BER vector BER = zeros(length(SNR_dB), 1); = T:length(SNR_dB) for sri % Modulate binary data ‘u_signal = J; fori=1:N if data( ‘tx signal = [tx_signal; rect_pulse]; else tx_signal = [tx_signal; zeros(size(rect_pulsé))]; end end % Add AWGN SNR = 10*(SNR_dB(Snt_idx) / 10); noise_power = 1 / (2 * SNR); noise = sqrt(noise_power) * randn(length(tx_signal), 1); rx signal = t signal + noise; % Matched Filter matched _filter = rect_pulse; filtered_signal = conv(rx signal, matched_filter, same); % Sample the output of the matched filter sample_interval = round(length(iltered_signal) / N); sampled_signal = filtered_signal(1:sample_interval:end); % Decision (Threshold = 0.5) estimated_bits = sampled_signal > 0.5; % Compute BER num_esrors = sum(estimated_bits ~= data); Dept. of ECE,DASTM BER(snr_idx) = num_errors / N; end % Plot BER vs. SNR figure; semilogy(SNR_dB, BER, 'b-o); grid on; xlabel(SNR (dB)'); ylabel(Bit Error Rate (BER); title(BER vs. SNR for Rectangular Pulse Modulated Binary Data); Output: BER vs. ENR for Rectangular Pulse Modulated Binary Data 0358 — BitErorR ‘SNR (dB) Dept. of ECE,DASTM 12. Generate 16-QAM Modulation and obtain the QAM constellation. Aim of the Experiment: To Generate 16-QAM Modulation and obtain the QAM constellation using MATLAB. Theory: Quadrature Amplitude Modulation (QAM) is a widely used digital modulation scheme in modern communication systems. In QAM, two carrier waves, typically sinusoidal and orthogonal to each other, are modulated in amplitude by the input signals. These two carriers correspond to the in- phase (|) and quadraturephase (Q) components, which combine to form a constellation of points in the complex plane. In 16-QAM, the modulation order M=16, meaning it can represent 16 distinct symbols. Each symbol encodes 4 bits of information, as The 16-QAM constellation consists of 16 paints arranged in a grid-like pattern, typically forming a square. Each pointis a unique combination of amplitude levels for the | and Q components. The advantages of 16-QAM include higher spectral efficiency compared to simpler schemes like Binary Phase Shift Keying (BPSK) or Quadrature Phase Shift Keying (QPSK), as more bits can be transmitted per symbol. However, it is more susceptible to noise and distortion, making it suitable for high-SNR environments. Program code: cle; clear all; close all; % Parameters m= 16; % Modulation order (16-QAM) k = log2(m); % Bits per symbol n= 9000; % Total number of bits n= k* floor(n / k); % Ensure n is a multiple of k nsamp = 1; % Oversampling factor % Generate random bit sequence X= randi((0 1], n, 1);% Random binary sequence figure; Dept. of ECE,DASTM stem(x(1:20), filled’); % Plot first 20 bits title(Bit Sequence); xlabel(Bit index’); ylabel(Bit Amplitude); % Convert bits to symbols xsym = bi2de(reshape(s, k, length(x) / k).,'leftmsb’); % Group bits into symbols figure; stem(xsym(1:10), ‘filled’); % Plot first 10 symbols title(Symbol Plot); xlabel(‘Symbol Index); ylabel(Symbol Amplitude); % Modulate using 16-QAM y = gammod(xsym, m, 'UnitAveragePower’, true); % Normalize power ytx = y; % Transmitted signal % Add AWGN to the signal ebno = 10; % Eb/No in dB snr = ebno + 10*log10(k) - 10*log1 O(nsamp); % Calculate equivalent SNR yn = awgn(ytx, snr, measured); % Add noise to the signal % Received signal yex = yn; % Scatter plot of transmitted and received signals figure; scatterplot(y); % Transmitted signal title(Constellation diagram of Y); figure; scatterplot(yrx, 30); % Received signal with noise title(Constellation diagram of Yrx); Dept. of ECE,DASTM ore om

You might also like