Line codes are used to map binary information sequence into analog signal which has properties suitable for the physical media that is being utilized to send the data.

Consider the case of a networking equipment like a router or a switch. According to ISO-OSI ( “International Standard Organisation – Open System Interconnection”[1]) reference model , any communication device or network can be conceptualized into seven layers of protocols namely Application, Presentation, Session, Transport, Network, Data-Link, and Physical Layer. Physical Layer dictates the electrical, physical and mechanical properties of the communication network or device. It defines properties like voltage levels, timing , maximum data rate allowable through the media without data loss,bandwidth efficiency, power consumption, physical connectors ( details like 50Ω or 75Ω termination, SMA, SMC or BNC connectors etc…,).

Line codes are chosen in such a way that they are optimized for the media that is being used to transmit data. Some line codes provide excellent timing synchronization (Timing synchronization is important in the context of sampling and clock recovery at the receiver. Incorrect timing sync may cause unrecoverable errors at the receiver due to wrong sampling instants) but may posses an undesirable DC content ( Why ?? Desired operating frequency range for a particular application may be between 500KHz and 1MHz, presence of DC content in such an application causes wastage of power.)

Commonly used line codes are NRZ (Non Return to Zero), RZ (Return to Zero), AMI (Alternate Mark Inversion), Manchester code, 8b/10b code,2B1Q code, Miller code, etc..,

Power Spectrum Density (PSD) is a common method employed in choosing a line code suitable for the physical media under consideration. Lets discuss how to convert a bit stream into NRZ unipolar, NRZ polar and Manchester coded data and plot their PSD.

### Procedure to plot Power Spectral Density of line codes in Matlab :

Step 1: Generate random binary sequence of sufficient length .Too small number of bits will give a poor PSD plot , whereas , too large number of bits consumes more computation time.

Step 2: Map the generated bits into NRZ unipolar or NRZ polar or Manchester line code (see Algorithm).

Step 3: Plot PSD using “psd” function in matlab.

### Algorithm:

 Manchester Coding: NRZ Unipolar NRZ Polar First half of bit period : signal = data Second half of bit period: signal = !data For the entire bit period: signal=0 { if data =0 } signal=A volts { if data =1 } For the entire bit period: signal=-A volts { if data =0 } signal=A volts { if data =1 }

### File 1: %———Line_Encoder.m—————%

Check this ebook for the full Matlab code Simulation of Communication Systems using Matlab by Mathuranathan Viswanathan

### File 3:— PSD_of_Line_Codes.m—-> To generate PSD of Line codes

Power Spectral Density of Line Codes