Kvantování

In [1]:
import matplotlib.patches as mpp
import scipy.interpolate as interpol
#####################################

al=0.5

figure(figsize=(10,7))
ax=subplot(111)
grid(0)
xlim([0,1])
ylim([-3.5,3.5])

axhline(y=3, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al,label=ur'kvantovací hladina')
axhline(y=2, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=1, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=0, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=-1, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=-2, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=-3, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)

axhline(y=2.5, xmin=0, xmax=1, linestyle=':', linewidth=2, color='g', alpha=al,label=ur'rozhodovací hladina')
axhline(y=1.5, xmin=0, xmax=1, linestyle=':', linewidth=2, color='g', alpha=al,)
axhline(y=0.5, xmin=0, xmax=1, linestyle=':', linewidth=2, color='g', alpha=al,)
axhline(y=-0.5, xmin=0, xmax=1, linestyle=':', linewidth=2, color='g', alpha=al,)
axhline(y=-1.5, xmin=0, xmax=1, linestyle=':', linewidth=2, color='g', alpha=al,)
axhline(y=-2.5, xmin=0, xmax=1, linestyle=':', linewidth=2, color='g', alpha=al,)


t=arange(0.02,1,0.08)
len(t)
u=[1,2,2,3,1,2,1,0,-1,-2,-1,-3,-2]
len(u)
stem(t,u, linefmt='b', markerfmt='o', basefmt='|',)

tt=linspace(0.01,0.99,1000)
funkce=interpol.UnivariateSpline(t,u,s=0.5)
uu=funkce(tt)
plot(tt,uu,'k-',label=u'původní signál')
plot(t,funkce(t),'k.')

annotate(u'',size=16, xy=(t[3],3),xytext=(t[3],funkce(t[3])), 
        arrowprops=dict(arrowstyle="->", color='m', connectionstyle="arc3,rad=1.5", fc="w")   )
annotate(u'',size=16, xy=(t[4],1),xytext=(t[4],funkce(t[4])), 
        arrowprops=dict(arrowstyle="->", color='m', connectionstyle="arc3,rad=1.5", fc="w")   )
annotate(u'',size=16, xy=(t[5],2),xytext=(t[5],funkce(t[5])), 
        arrowprops=dict(arrowstyle="->", color='m', connectionstyle="arc3,rad=1.5", fc="w")   )

xlabel(r't\,[s] $\rightarrow$', x=0.9)
ylabel('$\mathrm u$\,[V] $\uparrow$', y=0.9, rotation=0)
legend()
Out[1]:
<matplotlib.legend.Legend at 0x3a6fc50>
In [2]:
al=0.5

figure(figsize=(10,7))
ax=subplot(111)
grid(0)
xlim([0,1])
ylim([-3.5,3.5])

axhline(y=3, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al,label=ur'kvantovací hladina')
axhline(y=2, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=1, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=0, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=-1, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=-2, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=-3, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)

t=arange(0.02,1,0.08)
len(t)
u=[1,2,2,3,1,2,1,0,-1,-2,-1,-3,-2]
len(u)
stem(t,u, linefmt='b', markerfmt='o', basefmt='|',)
xticks(t,arange(len(t)))
yticks(arange(-3,3.5,1), '101 110 111 000 001 010 011 '.split() )

xlabel(r'n\,[-] $\rightarrow$', x=0.9)
ylabel('hladina $\uparrow$', y=0.9, rotation=0)
#legend()
Out[2]:
<matplotlib.text.Text at 0x3a92690>
In [3]:
#### Kvantovací šum

al=0.5

figure(figsize=(10,7))
ax=subplot(111)
grid(0)
xlim([0,1])
ylim([-3.5,3.5])


t=arange(0.02,1,0.08)
len(t)
u=[1,2,2,3,1,2,1,0,-1,-2,-1,-3,-2]
len(u)
#stem(t,u, linefmt='b', markerfmt='o', basefmt='k-',)
#xticks(t,arange(len(t)))
#yticks(arange(-3,3.5,1), '101 110 111 000 001 010 011 '.split() )

xlabel(r't\,[s] $\rightarrow$', x=0.9)
ylabel(r'u\,[V] $\uparrow$', y=0.9, rotation=0)

ts=linspace(t[0],t[-1],1000)
funkcePCM = interpol.interp1d(t,u, kind='nearest')
plot(ts,funkce(ts),'k-',label=u'původní signál', lw=2)
plot(ts,funkcePCM(ts),'r-',label=u'PCM signál')
plot(ts,funkcePCM(ts)-funkce(ts),'g-',label=u'kvantovací šum')
legend(prop={'size':16})
grid()