Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Pulse Code Modulation and Line Coding Techniques using MATLAB

By Soham Chetan Kamani September 10, 2013

 

Pulse code modulation is a form of information conversion from discrete to digital. Pulse code modulation is used in almost all modern communication systems and is essential for digital communication. Each sampled value is given in the form of a discrete signal, converted to its binary equivalent, and coded in the form of zeros and ones. There are different types of pulses used for coding ones and zeros. In the following program the user is asked to select the pulse which will then be used to modulate the incoming digital signal.

Working Principle

Each discrete signal consists of a set of values. In order to convert this signal into digital form, each discrete value must be represented as its binary equivalent. This binary number can be of any number of bits, where a greater number of bits means better accuracy, but also increased memory and bandwidth usage. For this project, we use 3 bits which will represent 8 values( from 0 to 7). The only issue is that the values of a discrete signal can be much grater than 7 or much smaller than 1. In this case we have to normalize it. We do this by dividing the entire signal vector by its maximum amplitude, so it can have values ranging only from 0 to 1. We then multiply this by 7 so that it now has values from 0 to 7, as required

Types of Pulses

Three different types of pulses are used in the program , all with their advantages and disadvantages.

Return to zero pulse:

If the pulse has a period of T seconds, for a digital ‘1’ it is on for T/2 seconds and off for T/2 seconds. For a digital ‘0’ it is off for T seconds

Example: for T=30

On:

Signal Diagram showing ON state of Return to Zero Pulse

Fig. 1: Signal Diagram showing ON state of Return to Zero Pulse 

Off:

Signal Diagram showing OFF State of Return to Zero Pulse

Fig. 2: Signal Diagram showing OFF state of Return to Zero Pulse 

Not Returning to zero (NRZ):

 As the name suggests, this pulse does not return to zero for a digital ‘1’, i.e. for a period of T seconds, it is on for T seconds. For a digital zero it is off for T seconds.

Example : for T=30

On:

Signal Diagram showing ON State of Not Return to Zero Pulse

Fig. 3: Signal Diagram showing ON state of Not Return to Zero Pulse 

Off: 

Signal Diagram showing OFF State of Not Return to Zero Pulse

Fig. 4: Signal Diagram showing OFF state of Not Return to Zero Pulse 

Manchester Pulse and Output

Manchester pulse:

This is an alternating type of pulse. For a digital one, the pulse is on for the first T/2 seconds the off for the next T/2 seconds. For a digital zero, the pulse is off for the first T/2 seconds the on for the next T/2 seconds. This pulse has the advantage that there is no DC component present in the modulated signal,  however, it takes up twice the bandwidth of NRZ pulse.

Example: for T=60

On:

Signal Diagram showing ON State of Manchester Pulse

Fig. 5: Signal Diagram showing ON state of Manchester Pulse

Off:

Signal Diagram Showing OFF State of Manchester Pulse

Fig. 6: Signal Diagram showing OFF state of Manchester Pulse

Algorithm and Code explanation

        Step 1 – Clear all existing windows and variables

        Step 2 – Take the input signal from the user and store it in the variable ‘signal’

       Step 3 – The signal has to be normalized. In our program we use 8-bits (values ranging from 0 to )hence our normalized signal is the input signal divided by its maximum and then multiplied by 7

        Step 4 – Define two empty vectors binsignal and pulsesignal to represent the binary value and pulse output of each signal value respectively

        Step 5 – For each value of ‘signal’ obtain its binary value using the dec2bin function

       Step 6 – The binary value is a string. In order to convert it to a matrix of zeros and ones, subtract the ascii value of 0 ie 48 from the binary value and store it in ‘binvalue’

        Step 7 – Concatenate ‘binvalue’ with the existing binsignal and repeat from step 5 until the whole signal is converted into binary values.

        Step 8 – Take input from the user to determine which type of pulse is to be used.

        Step 9 – Define the pulses for RZ, NRZ, and Manchester types.

        Step 10 – Define an empty vector pulsesignal.

        Step 11 – Read ‘binsignal’ for each value of binsignal, concatenate the appropriate pulse with the pulsesignal matrix.

        Step 12 – Plot the output pulsesignal using plot() function.

Output

Screenshot of Matlab Code for Pulse Width Modulation and Line Coding

Fig. 7: Screenshot of Matlab Code for Pulse Width Modulatiin and Line Coding

 

Screnshot of Matlab Output for Pulse Width Modulation and Line Coding

Fig. 8: Screnshot of Matlab Output for Pulse Width Modulation and Line Coding 

 

Project Source Code

###


clc; clear all; close all;

signal=input('enter signal');

i=[];

normsignal=(signal./max(signal))*7;

binsignal=[];

pulsesignal=[];

for i=1:length(signal)

    binvalue=dec2bin(signal(i),3);

    binvalue=binvalue-48;

    binsignal=[binsignal binvalue];

end

pulse=input('choose pulse: 1=Return to Zero, 2=Not return to Zero 3=Manchester');

if pulse==1

    for i=1:length(binsignal)

        if binsignal(i)==1

            pulsesignal=[pulsesignal ones(1,10) zeros(1,10)];

        end

        if binsignal(i)==0

            pulsesignal=[pulsesignal zeros(1,20)];

        end

    end

end

if pulse==2

    for i=1:length(binsignal)

        if binsignal(i)==1

            pulsesignal=[pulsesignal ones(1,20)];

        end

        if binsignal(i)==0

            pulsesignal=[pulsesignal zeros(1,20)];

        end

    end

end

if pulse==3

    for i=1:length(binsignal)

        if binsignal(i)==1

            pulsesignal=[pulsesignal ones(1,10) (-1*ones(1,10))];

        end

        if binsignal(i)==0

            pulsesignal=[pulsesignal (-1*ones(1,10)) ones(1,10)];

        end

    end

end

plot(pulsesignal);          

###

 



Filed Under: Electronic Projects
Tagged With: line coding, matlab, pulse code modulation
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Simple Active Bandpass Filter Oscillates
  • De-coupling capacitors with 50 V rating
  • 12VAC to 12VDC 5A on 250ft 12AWG
  • Getting Started with Electronics: What Helped You the Most in the Beginning?
  • DC/DC Converter with wide range input

RSS Electro-Tech-Online.com Discussions

  • Refrigeration System Reliability in Harsh Aussie Conditions
  • Chinese Tarrifs – 104%!?!
  • can a AT89C51 be used as a rom?
  • Telegram Based Alarm - Sensor cable protection
  • An Update On Tarrifs

Featured – Designing of Audio Amplifiers part 9 series

  • Controller Chip Selection for Developing USB Enabled Device (Part 6/6)
  • Signal and Encoding of USB System (Part 5/6)
  • USB Requests and Stages of Control Transfer (Part 4/6)
  • USB Descriptors and their Types (Part 3/6)
  • USB Protocol: Types of USB Packets and USB Transfers (Part 2/6)
  • Introduction to USB: Advantages, Disadvantages and Architecture (Part 1/6)

Recent Articles

  • Renesas launches 64-bit RZ/A3M with built-in 12 8MB memory
  • Hexagon’s Septentrio introduces 23 mm x 16 mm GNSS modules compatible with PX4 and ArduPilot
  • Basics of Audio Amplifier – 1/9
  • Designing 250 Milli Watt Audio Power Amplifier – 2/9
  • Designing 1 Watt Audio Power Amplifier – 3/9

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe