I need to implement some sort of simple delta modulation for my homework.
The test signal is $x(t)=10\sin(20\pi t)+\cos(100\pi t)$, sampled at $f_s=40f_{\tt{max}}$
Block scheme of delta modulator is given as
where integrator is given as
and characteristic of 1-bit quantizer is given as
This is my code where I tried to implement previous logic
import numpy as np
import matplotlib.pyplot as plt
fs = 40 * 50
duration = 0.2
t = np.linspace(0, duration, fs)
test_signal = 10 * np.sin(20 * np.pi * t) + np.cos(100 * np.pi * t)
plt.plot(t, test_signal)
plt.xlabel('t(s)')
plt.ylabel('x(t)')
plt.xticks([0, 5e-2, 0.1, 0.15, 0.2])
plt.grid(True)
plt.show()
def quantization(element):
if element > 0:
return 1
else:
return -1
x_m = []
integrator_state = 0
def delta_mod(x_t):
for i in range(len(x_t)):
if i == 0:
x_m.append(quantization(x_t[0]))
integrator_state = x_m[0]
else:
x = x_t[i] - integrator_state
x_m.append(quantization(x))
integrator_state = x_m[i]-integrator_state
delta_mod(test_signal)
plt.plot(t, x_m, drawstyle='steps-pre', label='x_m(t)')
plt.xlabel('t(s)')
plt.ylabel('x_m(t)')
plt.yticks([-4,-2,0,2,4])
plt.grid(True)
plt.show()
These are plots I get
And these are plots that my proffesor got
Does anyone know what am I doing wrong while trying to implement this logic.
x = x_t[i] + integrator_state
Shouldn't this be a subtraction? $\endgroup$np.linspace(0, duration, fs*duration)
? Also,integrator_state = x_m[i]-integrator_state
seems backwards. $\endgroup$