0% found this document useful (0 votes)
25 views9 pages

DC LAB 1 - DC - Merged

The document discusses analog to digital conversion. It generates a multitone signal, samples it, quantizes the samples, encodes the quantized values as bits, decodes and reconstructs the signal. It also applies low pass filtering to the original, quantized and encoded signals.

Uploaded by

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

DC LAB 1 - DC - Merged

The document discusses analog to digital conversion. It generates a multitone signal, samples it, quantizes the samples, encodes the quantized values as bits, decodes and reconstructs the signal. It also applies low pass filtering to the original, quantized and encoded signals.

Uploaded by

Wolfskin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

http://win10.

io
http://win10.io
http://win10.io
ANALOG TO DIGITAL CONVERSION
NAME : M.AUTHISELVI
ROLL NO: CB.EN.U4CCE19032
EXP NO : 1

CODE :

import numpy as np
import matplotlib.pyplot as plt
import scipy
from scipy import signal
import pandas as pd
fs = 220
t1 = np.arange(0,1,1/fs)
t2 = np.arange(0,1,1/fs)
t3 = np.arange(0,1,1/fs)
t = np.linspace(0,1,1000)
f1 = 20
f2 = 40
f3 = 60
fs = 220
A = 4
n = len(t1)
x =
A*np.sin(2*np.pi*f1*t1)+A*np.sin(2*np.pi*f2*t2)+A*np.sin(2*np.pi*f3*t
3)
plt.plot(t1,x)
y_ = [0]*n
for i in range(n):
y_[i] = x[i]*sum(signal.unit_impulse(n, i))
plt.stem(t1,y_)
ymax = max(y_)
ymin = min(y_)
ymin, ymax
stepSize = abs(ymax-ymin)/8
StepSize
N = 8
val = ymin
del_ = []
for i in range(0,N+1):
del_.append(val)
val += stepSize

del_
data = [
[str(del_[0])+', '+str(del_[1]), ((del_[0]+del_[1])/2)],
[str(del_[1])+', '+str(del_[2]), ((del_[1]+del_[2])/2)],
[str(del_[2])+', '+str(del_[3]), ((del_[2]+del_[3])/2)],
[str(del_[3])+', '+str(del_[4]), ((del_[3]+del_[4])/2)],
[str(del_[4])+', '+str(del_[5]), ((del_[4]+del_[5])/2)],
[str(del_[5])+', '+str(del_[6]), ((del_[5]+del_[6])/2)],
[str(del_[6])+', '+str(del_[7]), ((del_[6]+del_[7])/2)],
[str(del_[7])+' ,'+str(del_[8]), ((del_[7]+del_[8])/2)]
]

# Create the pandas DataFrame


df = pd.DataFrame(data, columns = ['Quantization region', 'Quantized
value'])

# print dataframe.
df
quant_val = [
((del_[0]+del_[1])/2),
((del_[1]+del_[2])/2),
((del_[2]+del_[3])/2),
((del_[3]+del_[4])/2),
((del_[4]+del_[5])/2),
((del_[5]+del_[6])/2),
((del_[6]+del_[7])/2),
((del_[7]+del_[8])/2)
]

bit_value = ['000', '001', '010', '011', '100', '101', '110', '111']

df2 = pd.DataFrame(zip(quant_val, bit_value), columns=['Quantized


value','Encoded bits'])
print(df2)

y_quant = []
for i in y_:
for j in range(len(del_)-1):
if i >= del_[j] and i< del_[j+1]:
y_quant.append(((del_[j]+del_[j+1])/2))

plt.stem(y_)
plt.show()
plt.stem(y_quant)
y_encode = []
for i in y_quant:
for j in range(len(quant_val)):
if i == quant_val[j]:
y_encode.append(bit_value[j])

y_encode

y_decode = []

for i in y_encode:
for j in range(len(bit_value)):
if i == bit_value[j]:
y_decode.append(quant_val[j])

y_decode

from scipy.signal import butter, lfilter,filtfilt


from scipy.signal import freqs
from scipy.fft import fft

def lowpass(cutOff, fs, order=1):


nyq = 0.5 * fs
normalCutoff = cutOff / nyq
b, a = butter(order, normalCutoff, btype='low', analog = True)
return b, a

def lowpass_filter(data, cutOff, fs, order):


b, a = lowpass(cutOff, fs, order=order)
y = filtfilt(b, a, data)
return y
filtered1 = lowpass_filter(y_, 70, 220, 3)
plt.plot(filtered1)
filtered2 = lowpass_filter(y_quant, 70, 220, 3)
plt.plot(filtered2)
filtered2 = lowpass_filter(y_decode, 70, 220, 3)
plt.plot(filtered2)
OUTPUT :

Multitone Signal (Figure 1)

Sampled Signal ( Figure 2 )

Quantised Signal ( Figure 3 )


Quantised Values ( Table 1 )

Reconstructed Sample Signal ( Figure 4 )

Reconstructed Quantised Signal ( Figure 5 )


Reconstructed Encoded Signal ( Figure 6 )

You might also like