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

Encoding Modulation

The document discusses various encoding and modulation techniques used in digital communication systems. It provides examples and code to demonstrate unipolar encoding, NRZ-L encoding, NRZ-I encoding, RZ encoding, biphase-manchester encoding, differential manchester encoding, ASK modulation, FSK modulation, PSK modulation, AM modulation, FM modulation, and PM modulation. Plots and signals are generated to illustrate each technique.

Uploaded by

jenny khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Encoding Modulation

The document discusses various encoding and modulation techniques used in digital communication systems. It provides examples and code to demonstrate unipolar encoding, NRZ-L encoding, NRZ-I encoding, RZ encoding, biphase-manchester encoding, differential manchester encoding, ASK modulation, FSK modulation, PSK modulation, AM modulation, FM modulation, and PM modulation. Plots and signals are generated to illustrate each technique.

Uploaded by

jenny khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Unipolar Encoding Technique:

import numpy as np

import matplotlib.pyplot as plt Example 1:

arr=input("Enter all bits with space in one line: ")

f=list(map(int,arr.split(' ')))

print("Unpipolar output for input: ")

unipolar=[0]

if f[0]==1:

unipolar = [1]

else:

unipolar = [0]

for i in range(0,len(f)):

unipolar.append(f[i]) Example 2:

time = np.arange(0, len(unipolar))

plt.subplot(321)

plt.title("Unipolar Encoding")

plt.xlabel("Time")

plt.ylabel("Bit")

plt.step(time,unipolar)

plt.tight_layout()

plt.xticks(time)

plt.yticks([0,1])

plt.xlim(0,len(f))

plt.grid(True)

plt.show()
Polar NRZ-L technique:
from copy import copy

import matplotlib.pyplot as plt

import numpy as np Example 1:

plt.figure()

f = [0, 1, 0, 0, 1, 1]

plt.subplot(321)

nrz_f=[1 if f[0]==0 else -1]

for i in range(0, len(f)):

k = f[int(i)]

if k == 0:

nrz_f.append(1)
Example 2:
else:

nrz_f.append(-1)

t = np.arange(0, len(nrz_f))

nrz_t = t

plt.title("NRZ-L Encoding")

plt.xlabel("Time")

plt.ylabel("Bit")

plt.step(nrz_t, nrz_f)

plt.xticks(nrz_t)

plt.axhline(y=0, color="r")

plt.xlim(0, len(nrz_f))

plt.tight_layout()

plt.show()
Polar NRZ-I Technique :
from copy import copy Example 1:

import numpy as np

import matplotlib.pyplot as plt

f = [0,1,0,0,1]

bit= 1

nrz_i=[1]

for i in range(0,len(f)):

if f[i]==1:
Example 2:
if bit==1:

bit=-1

else:

bit=1

nrz_i.append(bit)

nrz_t=np.arange(0,len(nrz_i))

plt.subplot(311)

plt.grid(True)

plt.axhline(y=0,color="r")

plt.title("NRZ-I Encoding")

plt.xlabel("Time")

plt.ylabel("Bit level")

plt.step(nrz_t,nrz_i)

plt.xticks(nrz_t)

plt.xlim(0,len(nrz_i))

plt.show()
Polar RZ Technique: plt.grid(True)

import matplotlib.pyplot as plt plt.show()

import numpy as np

from copy import copy


Example 1:

plt.figure()

f = [0,1,0,0,1,1]

t = np.arange(0, len(f))

plt.subplot(321)

plt.title("RZ encoding")

rz_bit=[-1 if f[0]==0 else 1]

for i in range(0,len(f)):

k=f[int(i)]
Example 2:
if k == 0:

rz_bit.append(-1)

rz_bit.append(0)

else:

rz_bit.append(1)

rz_bit.append(0)

rz_time=np.arange(0,len(rz_bit))

plt.step(rz_time,rz_bit)

label=np.arange(0,len(rz_time))

label_name=["" if a%2==1 else int(a*0.5) for a in label]

plt.xticks(ticks=label,labels=label_name)

plt.ylabel("Bit level")

plt.xlabel("Time")

plt.xlim(0,len(rz_bit))
Polar Biphase-Manchester: Example 1:

import matplotlib.pyplot as plt

import numpy as np

from copy import copy

f = [0,1,0,0]

t = np.arange(0, len(f))

plt.subplot(321)

plt.title("Manchester encoding")
Example 2:
rz_bit=[1 if f[0]==0 else 0]

for i in range(0,len(f)):

k=f[int(i)]

if k == 0:

rz_bit.append(1)

rz_bit.append(-1)

else:

rz_bit.append(-1)

rz_bit.append(1)

rz_time=np.arange(0,len(rz_bit))

plt.step(rz_time,rz_bit)

label=np.arange(0,len(rz_time))

label_name=["" if a%2==1 else int(a*0.5) for a in label]

plt.xticks(ticks=label,labels=label_name)

plt.ylabel("Bit level")

plt.xlabel("Time")

plt.xlim(0,len(rz_bit))

plt.grid(True)

plt.show()
Differential Manchester Encoding: Example 1:

import matplotlib.pyplot as plt

import numpy as np

from copy import copy

data = input("Input the binary stream: ");

data_temp = [ord(x) - 48 for x in data]

data = [1]

for d in data_temp:
Example 2:
if (d == 1 and data[len(data) - 1] == 1) or (d == 0 and
data[len(data) - 1] == -1):

data.extend([1, -1])

else:

data.extend([-1, 1])

time = np.arange(0,len(data))

plt.step(time,data)

label=np.arange(0,len(data))

plt.subplot(321)

label_name=["" if a%2==1 else int(a*0.5) for a in label]

plt.xticks(ticks=label,labels=label_name)

plt.title("Differential Manchester : ")

plt.ylabel("Bit level")

plt.xlabel("Time")

plt.grid(True)

plt.show()
ASK Modulation:
import matplotlib.pyplot as plt Example 1:

import numpy as np

from copy import copy

low_amp=1

high_amp=2

f=2

time=np.arange(0,1,0.01)

b1=2*np.sin(2*np.pi*f*time)

b0=1*np.sin(2*np.pi*f*time)

or_data=input("Enter digital data bits: ")

or_data=[ord(x) -48 for x in or_data]


Example 2:
data=[]

for x in or_data:

if x==1:

data.extend(b1)

else:

data.extend(b0)

time=np.arange(0,len(data))

plt.plot(time,data)

plt.xlabel('Time')

plt.ylabel('Amplitude')

plt.grid()

plt.show()
FSK Modulation:
import matplotlib.pyplot as plt Example 1:

import numpy as np

from copy import copy

phase=0

f=2

time=np.arange(0,1,0.01)

b1=2*np.sin(2*np.pi*4*time)

b0=1*np.sin(2*np.pi*2*time)

or_data=input("Enter digital data bits: ")


Example 2:
or_data=[ord(x) -48 for x in or_data]

data=[]

for x in or_data:

if x==1:

data.extend(b1)

else:

data.extend(b0)

time=np.arange(0,len(data))

plt.plot(time,data)

plt.grid()

plt.show()
PSK Modulation: Example 1:

import matplotlib.pyplot as plt

import numpy as np

from copy import copy

phase=0

f=2

p0=np.pi

time=np.arange(0,1,0.01)

b1=1*np.sin(2*np.pi*f*time) Example 2:

b0=1*np.sin(2*np.pi*f*time+p0)

or_data=input("Enter digital data bits: ")

print_data=copy(or_data)

or_data=[ord(x) -48 for x in or_data]

data=[]

for x in or_data:

if x==1:

data.extend(b1)

else:

data.extend(b0)

time=np.arange(0,len(data))

plt.title('PSK for '+print_data)

plt.plot(time,data)

plt.grid()

plt.show()
AM Modulation: plt.tight_layout()

import numpy as np plt.show()

import matplotlib.pyplot as plt Example 1:

print('Amplitude Modulation')

time= np.arange(0,10,0.01)

fc=2

ac=2

plt.subplot(3,1,1)

carrier_signal=ac*np.sin(2*np.pi*fc*time)

plt.title('Carrier')

plt.xlabel('Time')

plt.ylabel('Amplitude')

plt.plot(carrier_signal)
Example 2:
message_amplitude=.2

message_frequency=.2

plt.subplot(3,1,2)

plt.title('Message Signal')

message_signal=message_amplitude*np.sin(2*np.pi*m
essage_frequency*time)

plt.xlabel('Time')

plt.ylabel('Amplitude')

plt.plot(message_signal)

plt.subplot(3,1,3)

plt.title('Amplitude Modulated Signal')

modulated_s=carrier_signal*message_signal

plt.xlabel('Time')

plt.ylabel('Amplitude')

plt.plot(modulated_s)
FM Modulation: plt.xlabel('Time')

import numpy as np plt.tight_layout()

import matplotlib.pyplot as plt plt.show()

modulator_frequency =4.0 Example 1:

carrier_frequency = 40.0

time = np.arange(441.0) / 441.0

modulator = np.sin(2 * np.pi * modulator_frequency *


time)

carrier = np.sin(2 * np.pi * carrier_frequency * time)

product = np.zeros_like(modulator)

for i, t in enumerate(time):

product[i] = np.sin(2* np.pi * (carrier_frequency * t +


modulator[i])) Example 2:

plt.subplot(3, 1, 1)

plt.title('Modulator')

plt.plot(modulator)

plt.ylabel('Amplitude')

plt.xlabel('Time')

plt.subplot(3, 1, 2)

plt.title('Carrier')

plt.plot(carrier)

plt.ylabel('Amplitude')

plt.xlabel('Time')

plt.subplot(3, 1, 3)

plt.title("Frequency Modulated signal")

plt.plot(product)

plt.ylabel('Amplitude')
PM Modulation : plt.show()

import numpy as np

import matplotlib.pyplot as plt Example 1:

carrier = 220.0

modulator = 440.0

beta = 1.0

x1 = np.linspace(0.0, 0.03, num=2000)

carrierWave = np.cos

modulatorWave = np.cos

y1 = np.cos(carrier * np.pi * x1)

y2 = np.cos(modulator * np.pi * x1)

y3 = np.cos(carrier * np.pi * x1 + beta * y2)

plt.subplots_adjust(left = 0.1, bottom = 0.25)

plt.subplot(3, 1, 1)

carrierObj, = plt.plot(x1, y1, '-')

plt.axis([0, 0.03, -1.1, 1.1])

plt.title('Phase Modulation')

plt.ylabel('Carrier')

plt.subplot(3, 1, 2)

modulatorObj, = plt.plot(x1, y2, '-')

plt.axis([0, 0.03, -1.1, 1.1])

plt.ylabel('Modulator')

plt.subplot(3, 1, 3)

modulatedObj, = plt.plot(x1, y3, '-')

plt.axis([0, 0.03, -1.1, 1.1])

plt.xlabel('time (s)')

plt.ylabel('Modulated Carrier')

plt.tight_layout()

You might also like