Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key 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
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

Pulse Code Modulation and Line Coding Techniques using MATLAB

By Soham Chetan Kamani

 

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
 

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.

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!


Featured Tutorials

  • Introduction to Brain Waves & its Types (Part 1/13)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)
  • Performing Experiments with Brainwaves (Part 3/13)
  • Amplification of EEG Signal and Interfacing with Arduino (Part 4/13)
  • Controlling Led brightness using Meditation and attention level (Part 5/13)
  • Control Motor’s Speed using Meditation and Attention Level of Brain (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • What are the battery-selection criteria for low-power design?
  • Key factors to optimize power consumption in an embedded device
  • EdgeLock A5000 Secure Authenticator
  • How to interface a DS18B20 temperature sensor with MicroPython’s Onewire driver
  • Introduction to Brain Waves & its Types (Part 1/13)

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Slope compensation ramp calculation for UCC38084
  • Parts storage / inventory best practices and organization
  • Unusual gap shape of ETD59 ferrite core?
  • Vco cadencd
  • WH-LTE-7S1 GSM module and SIM card problem

RSS Electro-Tech-Online.com Discussions

  • surge arresters
  • NOR gate oscillator in LTspice not working
  • HV Diodes
  • intro to PI
  • Very logical explanation on low calue C3
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 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 | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key 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
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering