theoretical_results.lyx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. #LyX 2.1 created this file. For more info see http://www.lyx.org/
  2. \lyxformat 474
  3. \begin_document
  4. \begin_header
  5. \textclass article
  6. \use_default_options true
  7. \maintain_unincluded_children false
  8. \language english
  9. \language_package default
  10. \inputencoding auto
  11. \fontencoding global
  12. \font_roman default
  13. \font_sans default
  14. \font_typewriter default
  15. \font_math auto
  16. \font_default_family default
  17. \use_non_tex_fonts false
  18. \font_sc false
  19. \font_osf false
  20. \font_sf_scale 100
  21. \font_tt_scale 100
  22. \graphics default
  23. \default_output_format default
  24. \output_sync 0
  25. \bibtex_command default
  26. \index_command default
  27. \paperfontsize default
  28. \spacing single
  29. \use_hyperref false
  30. \papersize default
  31. \use_geometry true
  32. \use_package amsmath 1
  33. \use_package amssymb 1
  34. \use_package cancel 1
  35. \use_package esint 1
  36. \use_package mathdots 1
  37. \use_package mathtools 1
  38. \use_package mhchem 1
  39. \use_package stackrel 1
  40. \use_package stmaryrd 1
  41. \use_package undertilde 1
  42. \cite_engine basic
  43. \cite_engine_type default
  44. \biblio_style plain
  45. \use_bibtopic false
  46. \use_indices false
  47. \paperorientation portrait
  48. \suppress_date false
  49. \justification true
  50. \use_refstyle 1
  51. \index Index
  52. \shortcut idx
  53. \color #008000
  54. \end_index
  55. \leftmargin 3cm
  56. \topmargin 3cm
  57. \rightmargin 3cm
  58. \bottommargin 3cm
  59. \secnumdepth 3
  60. \tocdepth 3
  61. \paragraph_separation indent
  62. \paragraph_indentation default
  63. \quotes_language english
  64. \papercolumns 1
  65. \papersides 1
  66. \paperpagestyle default
  67. \tracking_changes false
  68. \output_changes false
  69. \html_math_output 0
  70. \html_css_as_file 0
  71. \html_be_strict false
  72. \end_header
  73. \begin_body
  74. \begin_layout Title
  75. Jmspeex' Journal of Dubious Theoretical Results
  76. \end_layout
  77. \begin_layout Abstract
  78. This is a log of theoretical calculations and approximations that are used
  79. in some of the Daala code.
  80. Some approximations are likely to be too coarse, some assumptions may not
  81. correspond to the observable universe and some calculations may just be
  82. plain wrong.
  83. You have been warned.
  84. \end_layout
  85. \begin_layout Part
  86. Relationship Between
  87. \begin_inset Formula $\lambda$
  88. \end_inset
  89. and
  90. \begin_inset Formula $Q$
  91. \end_inset
  92. in RDO
  93. \end_layout
  94. \begin_layout Standard
  95. When using a high-rate scalar quantizer, the distortion is given by
  96. \begin_inset Formula
  97. \[
  98. D=\frac{Q^{2}}{12}\ ,
  99. \]
  100. \end_inset
  101. where
  102. \begin_inset Formula $Q$
  103. \end_inset
  104. is the quantizer's interval between two levels (not the maximum error like
  105. in some other work).
  106. The rate required to code the quantized values (assuming round-to-nearest)
  107. is
  108. \begin_inset Formula
  109. \[
  110. R=-\log_{2}Q+C
  111. \]
  112. \end_inset
  113. where
  114. \begin_inset Formula $C$
  115. \end_inset
  116. is a constant that does not depend on Q.
  117. Starting from a known
  118. \begin_inset Formula $\lambda$
  119. \end_inset
  120. we want to find the quantization interval
  121. \begin_inset Formula $Q$
  122. \end_inset
  123. that minimizes the rate-distortion curve, so
  124. \begin_inset Formula
  125. \begin{align*}
  126. \frac{\partial}{\partial Q}\left(D+\lambda R\right) & =0\\
  127. \frac{\partial}{\partial Q}\left(\frac{Q^{2}}{12}-\lambda\log_{2}Q-\lambda C\right) & =0\\
  128. \frac{Q}{6}-\frac{\lambda}{Q\log2} & =0\\
  129. Q & =\sqrt{\frac{6\lambda}{\log2}}
  130. \end{align*}
  131. \end_inset
  132. Or, if
  133. \begin_inset Formula $Q$
  134. \end_inset
  135. is known, then
  136. \begin_inset Formula
  137. \[
  138. \lambda=\frac{Q^{2}\log2}{6}
  139. \]
  140. \end_inset
  141. \end_layout
  142. \begin_layout Section*
  143. Quantization threshold
  144. \end_layout
  145. \begin_layout Standard
  146. When we have a value between 0 and 1 and consider whether to round up or
  147. down, we can compute the optimal decision threshold
  148. \begin_inset Formula $x$
  149. \end_inset
  150. for which the RD cost for the decision is equal
  151. \begin_inset Formula
  152. \[
  153. x^{2}+\lambda R_{0}=\left(1-x\right)^{2}+\lambda R_{1}\ ,
  154. \]
  155. \end_inset
  156. where
  157. \begin_inset Formula $R_{0}$
  158. \end_inset
  159. and
  160. \begin_inset Formula $R_{1}$
  161. \end_inset
  162. are the costs for coding a zero and a one, respectively.
  163. Solving for
  164. \begin_inset Formula $x$
  165. \end_inset
  166. we have
  167. \begin_inset Formula
  168. \begin{align*}
  169. x^{2}+\lambda R_{0} & =\left(1-x\right)^{2}+\lambda R_{1}\\
  170. x^{2}+\lambda R_{0} & =x^{2}-2x+1+\lambda R_{1}\\
  171. 2x & =1+\lambda\left(R_{1}-R_{0}\right)\\
  172. x & =\frac{1}{2}+\frac{\lambda\Delta R}{2}\ ,
  173. \end{align*}
  174. \end_inset
  175. where
  176. \begin_inset Formula $\Delta R=R_{1}-R_{0}$
  177. \end_inset
  178. .
  179. In other words, it's like round-to-nearest, but with an additional bias
  180. of
  181. \begin_inset Formula $\lambda\Delta R/2$
  182. \end_inset
  183. towards zero.
  184. \end_layout
  185. \begin_layout Part
  186. Rate-Distortion Analysis of a Quantized Laplace Distribution
  187. \end_layout
  188. \begin_layout Standard
  189. Here we assume that the quantization step size has already been taken into
  190. account and that
  191. \begin_inset Formula $\sigma$
  192. \end_inset
  193. is the normalized standard deviation of a DCT coefficient.
  194. The post-quantization distribution of a Laplace-distributed variable with
  195. non-zero quantization threshold
  196. \begin_inset Formula $\theta$
  197. \end_inset
  198. is:
  199. \begin_inset Formula
  200. \[
  201. p\left(n\right)=\begin{cases}
  202. 1-r^{\theta} & n=0\\
  203. r^{\theta}\left(1-r\right)r^{n-1} & n>0
  204. \end{cases}
  205. \]
  206. \end_inset
  207. where
  208. \begin_inset Formula $\theta=\frac{1}{2}$
  209. \end_inset
  210. for round-to-nearest and
  211. \begin_inset Formula $r=e^{-\sqrt{2}/\sigma}$
  212. \end_inset
  213. .
  214. The entropy (rate)
  215. \begin_inset Formula $R$
  216. \end_inset
  217. of the quantized Laplace distribution is:
  218. \begin_inset Formula
  219. \[
  220. R=\overset{\mathrm{sign}}{\overbrace{r^{\theta}}}+\overset{\mathrm{non-zero}}{\overbrace{H\left(r^{\theta}\right)}}+\overset{\mathrm{tail}}{\overbrace{\frac{r^{\theta}H\left(r\right)}{1-r}}}
  221. \]
  222. \end_inset
  223. \end_layout
  224. \begin_layout Standard
  225. \begin_inset Formula
  226. \begin{align*}
  227. D(r) & =-\log r\left(\int_{0}^{\theta}x^{2}r^{x}dx+\sum_{k=1}^{\infty}\int_{\theta-1}^{\theta}x^{2}r^{k}r^{x}dx\right)\\
  228. & =I\left(r,\theta\right)-I\left(r,0\right)+\frac{r}{1-r}\left(I\left(r,\theta\right)-I\left(r,\theta-1\right)\right)
  229. \end{align*}
  230. \end_inset
  231. where
  232. \begin_inset Formula
  233. \begin{align*}
  234. I\left(r,x\right) & =-\log r\int x^{2}r^{x}dx\\
  235. & =r^{x}\frac{2x\log r-x^{2}\log^{2}r-2}{\log^{2}r}+C
  236. \end{align*}
  237. \end_inset
  238. \end_layout
  239. \begin_layout Standard
  240. When
  241. \begin_inset Formula $\sigma$
  242. \end_inset
  243. is much smaller than the quantization step size (everything quantizes to
  244. zero), then the distortion is simply
  245. \begin_inset Formula $\sigma^{2}$
  246. \end_inset
  247. and when
  248. \begin_inset Formula $\sigma$
  249. \end_inset
  250. is very large (flat distribution), then the distortion is that of a scalar
  251. quantizer:
  252. \begin_inset Formula $1/12$
  253. \end_inset
  254. .
  255. So in the general case we can approximate with
  256. \begin_inset Formula
  257. \[
  258. D=\min\left(\sigma^{2},\frac{1}{12}\right)
  259. \]
  260. \end_inset
  261. which tends to overestimate
  262. \begin_inset Formula $D$
  263. \end_inset
  264. in the region where
  265. \begin_inset Formula $\sigma^{2}$
  266. \end_inset
  267. is close to
  268. \begin_inset Formula $1/12$
  269. \end_inset
  270. .
  271. Assuming high-rate RDO, we have
  272. \begin_inset Formula
  273. \[
  274. \lambda=\frac{Q^{2}\log(2)}{6}=\frac{\log(2)}{6}\ .
  275. \]
  276. \end_inset
  277. The total RD-cost (expressed as a rate) becomes
  278. \begin_inset Formula
  279. \[
  280. R+\frac{D}{\lambda}=r^{\theta}+H\left(r^{\theta}\right)+\frac{r^{\theta}H\left(r\right)}{1-r}+\min\left(\frac{6\sigma^{2}}{\log(2)},\frac{1}{2\log(2)}\right)
  281. \]
  282. \end_inset
  283. This cost function can be approximated by the (smoother) cost function
  284. \begin_inset Formula
  285. \[
  286. C=\frac{1}{2}\log_{2}\left(1+\left(6.33\sigma\right)^{2}\right)
  287. \]
  288. \end_inset
  289. \end_layout
  290. \begin_layout Part
  291. PVQ Distortion
  292. \end_layout
  293. \begin_layout Standard
  294. Let
  295. \begin_inset Formula $\mathbf{X}=g\mathbf{z}$
  296. \end_inset
  297. and
  298. \begin_inset Formula $\hat{\mathbf{X}}=\hat{g}\hat{\mathbf{z}}$
  299. \end_inset
  300. be the unquantized and quantized coefficient vector, respectively.
  301. The quantization distortion is
  302. \begin_inset Formula
  303. \begin{align}
  304. D & =\left(\mathbf{X}-\hat{\mathbf{X}}\right)^{T}\left(\mathbf{X}-\hat{\mathbf{X}}\right)\nonumber \\
  305. & =\mathbf{X}^{T}\mathbf{X}+\hat{\mathbf{X}}^{T}\hat{\mathbf{X}}-2\hat{\mathbf{X}}^{T}\mathbf{X}\nonumber \\
  306. & =g^{2}+\hat{g}^{2}-2g\hat{g}\mathbf{z}\hat{\mathbf{z}}\nonumber \\
  307. & =\left(g-\hat{g}\right)^{2}+2g\hat{g}-2g\hat{g}\mathbf{z}\hat{\mathbf{z}}\nonumber \\
  308. & =\left(g-\hat{g}\right)^{2}+g\hat{g}\left(2-2\mathbf{z}\hat{\mathbf{z}}\right)\ .\label{eq:distance_v1}
  309. \end{align}
  310. \end_inset
  311. Let
  312. \begin_inset Formula $D_{z}$
  313. \end_inset
  314. be the distance between
  315. \family roman
  316. \series medium
  317. \shape up
  318. \size normal
  319. \emph off
  320. \bar no
  321. \strikeout off
  322. \uuline off
  323. \uwave off
  324. \noun off
  325. \color none
  326. \begin_inset Formula $\mathbf{z}$
  327. \end_inset
  328. and
  329. \begin_inset Formula $\hat{\mathbf{z}}$
  330. \end_inset
  331. ,
  332. \begin_inset Formula
  333. \begin{align}
  334. D_{z} & =\left(\mathbf{z}-\hat{\mathbf{z}}\right)^{T}\left(\mathbf{z}-\hat{\mathbf{z}}\right)\nonumber \\
  335. & =2-2\mathbf{z}^{T}\hat{\mathbf{z}}\ .\label{eq:distance-Dz}
  336. \end{align}
  337. \end_inset
  338. We can then rewrite
  339. \begin_inset CommandInset ref
  340. LatexCommand eqref
  341. reference "eq:distance_v1"
  342. \end_inset
  343. as
  344. \begin_inset Formula
  345. \begin{equation}
  346. D=\left(g-\hat{g}\right)^{2}+g\hat{g}D_{z}\ ,\label{eq:pvq_distortion}
  347. \end{equation}
  348. \end_inset
  349. which separates the gain quantization from the quantization of the unit
  350. vector
  351. \begin_inset Formula $\mathbf{z}$
  352. \end_inset
  353. .
  354. \end_layout
  355. \begin_layout Part
  356. Distortion from theta PVQ
  357. \end_layout
  358. \begin_layout Standard
  359. Let the normalized theta-PVQ vector be
  360. \begin_inset Formula
  361. \[
  362. \mathbf{z}=\left[\begin{array}{c}
  363. \cos\theta\\
  364. \mathbf{x}\sin\theta
  365. \end{array}\right]\ ,
  366. \]
  367. \end_inset
  368. where
  369. \begin_inset Formula $\mathbf{x}$
  370. \end_inset
  371. is the unit-vector coded with the PVQ quantizer, the distortion
  372. \begin_inset Formula $D$
  373. \end_inset
  374. between the unquantized
  375. \begin_inset Formula $\mathbf{z}$
  376. \end_inset
  377. and its quantized version
  378. \begin_inset Formula $\hat{\mathbf{z}}$
  379. \end_inset
  380. is
  381. \begin_inset Formula
  382. \begin{align}
  383. D_{z} & =\left(\mathbf{z}-\hat{\mathbf{z}}\right)^{T}\left(\mathbf{z}-\hat{\mathbf{z}}\right)\nonumber \\
  384. & =\left(\cos\theta-\cos\hat{\theta}\right)^{2}+\left(\mathbf{x}\sin\theta-\hat{\mathbf{x}}\sin\hat{\theta}\right)^{T}\left(\mathbf{x}\sin\theta-\hat{\mathbf{x}}\sin\hat{\theta}\right)\nonumber \\
  385. & =\cos^{2}\theta-2\cos\theta\cos\hat{\theta}+\cos^{2}\hat{\theta}+\sin^{2}\theta+\sin^{2}\hat{\theta}-2\sin\theta\sin\hat{\theta}\mathbf{x}^{T}\hat{\mathbf{x}}\nonumber \\
  386. & =2-2\cos\theta\cos\hat{\theta}-2\sin\theta\sin\hat{\theta}\mathbf{x}^{T}\hat{\mathbf{x}}\ .\label{eq:distortion-1}
  387. \end{align}
  388. \end_inset
  389. \family roman
  390. \series medium
  391. \shape up
  392. \size normal
  393. \emph off
  394. \bar no
  395. \strikeout off
  396. \uuline off
  397. \uwave off
  398. \noun off
  399. \color none
  400. Using the identity
  401. \begin_inset CommandInset ref
  402. LatexCommand eqref
  403. reference "eq:distance-Dz"
  404. \end_inset
  405. , we can then rewrite
  406. \begin_inset CommandInset ref
  407. LatexCommand eqref
  408. reference "eq:distortion-1"
  409. \end_inset
  410. as
  411. \begin_inset Formula
  412. \begin{align}
  413. D_{z} & =2-2\cos\theta\cos\hat{\theta}-\sin\theta\sin\hat{\theta}\left(2-D_{x}\right)\nonumber \\
  414. & =2-2\cos\left(\theta-\hat{\theta}\right)+\sin\theta\sin\hat{\theta}D_{x}\nonumber \\
  415. & =D_{\theta}+\sin\theta\sin\hat{\theta}D_{x}\ ,\label{eq:distortion-final}
  416. \end{align}
  417. \end_inset
  418. where
  419. \begin_inset Formula $D_{\theta}=2-2\cos\left(\theta-\hat{\theta}\right)$
  420. \end_inset
  421. is the mean square error due to quantizing
  422. \begin_inset Formula $\theta$
  423. \end_inset
  424. .
  425. So essentially, the total error is the sum of the error due to quantization
  426. of
  427. \begin_inset Formula $\theta$
  428. \end_inset
  429. and the error in the PVQ quantization assuming a radius that's the geometric
  430. mean of the quantized and unquantized radius.
  431. \end_layout
  432. \begin_layout Standard
  433. Putting
  434. \begin_inset CommandInset ref
  435. LatexCommand eqref
  436. reference "eq:distortion-final"
  437. \end_inset
  438. into
  439. \begin_inset CommandInset ref
  440. LatexCommand eqref
  441. reference "eq:pvq_distortion"
  442. \end_inset
  443. , we obtain
  444. \begin_inset Formula
  445. \begin{equation}
  446. D=\left(g-\hat{g}\right)^{2}+g\hat{g}\left(D_{\theta}+\sin\theta\sin\hat{\theta}D_{x}\right)\ .\label{eq:total_pvq_theta_dist}
  447. \end{equation}
  448. \end_inset
  449. \end_layout
  450. \begin_layout Part
  451. Biorthogonality and quantization noise
  452. \end_layout
  453. \begin_layout Standard
  454. A biorthogonal transform defined as
  455. \begin_inset Formula
  456. \[
  457. \mathbf{H}\mathbf{G}^{T}=I
  458. \]
  459. \end_inset
  460. where the columns of
  461. \begin_inset Formula $\mathbf{G}$
  462. \end_inset
  463. are the analysis basis functions and the columns of
  464. \begin_inset Formula $\mathbf{H}$
  465. \end_inset
  466. are the columns of the synthesis basis functions.
  467. We define the diagonal matrix
  468. \begin_inset Formula $\mathbf{S}$
  469. \end_inset
  470. such that the diagonal elements
  471. \begin_inset Formula $s_{i,i}=\sqrt{\mathbf{h}_{i}^{T}\mathbf{h}_{i}}$
  472. \end_inset
  473. are the magnitudes of the synthesis basis functions.
  474. For an input vector
  475. \begin_inset Formula $\mathbf{x}$
  476. \end_inset
  477. , the quantization process can be modeled as adding an uncorrelated noise
  478. vector
  479. \begin_inset Formula $\mathbf{n}$
  480. \end_inset
  481. such that the reconstruction
  482. \begin_inset Formula $\mathbf{y}$
  483. \end_inset
  484. is
  485. \begin_inset Formula
  486. \begin{align*}
  487. \mathbf{y} & =\mathbf{H}\mathbf{S}^{-1}\left(\mathbf{S}\mathbf{G}^{T}\mathbf{x}+\mathbf{n}\right)\\
  488. & =\mathbf{x}+\mathbf{H}\mathbf{S}^{-1}\mathbf{n}
  489. \end{align*}
  490. \end_inset
  491. \end_layout
  492. \begin_layout Standard
  493. The distortion due to quantization is
  494. \begin_inset Formula
  495. \begin{align*}
  496. D & =\left(\mathbf{x}-\mathbf{y}\right)^{T}\left(\mathbf{x}-\mathbf{y}\right)\\
  497. & =\left(\mathbf{H}\mathbf{S}^{-1}\mathbf{n}\right)^{T}\mathbf{H}\mathbf{S}^{-1}\mathbf{n}\\
  498. & =\mathbf{n}^{T}\left(\mathbf{S}^{T}\right)^{-1}\mathbf{H}^{T}\mathbf{H}\mathbf{S}^{-1}\mathbf{n}\\
  499. & =\mathbf{n}^{T}\mathbf{R}\mathbf{n}
  500. \end{align*}
  501. \end_inset
  502. where
  503. \begin_inset Formula $\mathbf{R}=\left(\mathbf{S}^{-1}\right)^{T}\mathbf{H}^{T}\mathbf{H}\mathbf{S}^{-1}$
  504. \end_inset
  505. .
  506. Rewriting
  507. \begin_inset Formula $D$
  508. \end_inset
  509. as a summation, we have
  510. \begin_inset Formula
  511. \[
  512. D=\sum_{i}\sum_{j}r_{i,i}n_{i}n_{j}
  513. \]
  514. \end_inset
  515. This is different from the orthonormal case where
  516. \begin_inset Formula
  517. \[
  518. D=\sum_{i}n_{i}^{2}
  519. \]
  520. \end_inset
  521. due to
  522. \begin_inset Formula $\mathbf{R}$
  523. \end_inset
  524. being the identity matrix (also known as Parseval's theorem).
  525. \end_layout
  526. \begin_layout Standard
  527. Since the noise is uncorrelated and since the diagonal of
  528. \begin_inset Formula $\mathbf{R}$
  529. \end_inset
  530. is equal to 1, then the expectation of the noise power is
  531. \begin_inset Formula $E\{D\}=E\{\mathbf{n}^{T}\mathbf{n}\}$
  532. \end_inset
  533. , like in the orthonormal case.
  534. This shows that multiplying each transformed coefficient
  535. \begin_inset Formula $x_{i}$
  536. \end_inset
  537. by the magnitude of the corresponding synthesis function
  538. \begin_inset Formula $s_{i,i}$
  539. \end_inset
  540. prior to quantization is sufficient to obtain the same
  541. \emph on
  542. average
  543. \emph default
  544. noise behaviour.
  545. In practice, it
  546. \emph on
  547. may
  548. \emph default
  549. be possible to do some clever trick in the quantization search to obtain
  550. a smaller distortion than the orthonormal case, partially compensating
  551. for the entropy cost of the biorthogonal transform.
  552. \end_layout
  553. \begin_layout Standard
  554. The average distortion we find also supports the use of the squared magnitude
  555. of the synthesis basis function in the computation of the coding gain.
  556. \end_layout
  557. \begin_layout Part
  558. Temporal RDO
  559. \end_layout
  560. \begin_layout Standard
  561. Let's assume two sequences of
  562. \begin_inset Formula $N$
  563. \end_inset
  564. samples each being quantized with a resolution
  565. \begin_inset Formula $Q$
  566. \end_inset
  567. .
  568. One sequence is constant, while the other isn't.
  569. The total distortion will be
  570. \begin_inset Formula
  571. \[
  572. D=\frac{2NQ^{2}}{12}\ .
  573. \]
  574. \end_inset
  575. \end_layout
  576. \begin_layout Standard
  577. If we assume that we can skip encoding of the constant sequence at no cost
  578. and shift
  579. \begin_inset Formula $b$
  580. \end_inset
  581. bits away from the variable sequence to the constant one, it costs only
  582. \begin_inset Formula $b/N$
  583. \end_inset
  584. bits per sample on the variable sequence and we get a distortion
  585. \begin_inset Formula
  586. \begin{align*}
  587. D & =N\frac{\left(2^{-b}Q\right)^{2}}{12}+N\frac{\left(2^{b/N}Q\right)^{2}}{12}\\
  588. & =\frac{NQ^{2}}{12}\left(2^{-2b}+2^{2b/N}\right)
  589. \end{align*}
  590. \end_inset
  591. We solve for
  592. \begin_inset Formula $\partial D/\partial b=0$
  593. \end_inset
  594. to minimize distortion:
  595. \begin_inset Formula
  596. \begin{gather*}
  597. \frac{\partial D}{\partial b}=\frac{NQ^{2}}{12}\left(-2b\log22^{-2b}+\frac{2b\log2}{N}2^{2b/N}\right)=0\\
  598. \frac{2b2^{2b/N}\log2}{N}=2b2^{-2b}\log2\\
  599. \frac{2^{2b/N}}{N}=2^{-2b}
  600. \end{gather*}
  601. \end_inset
  602. Taking the base-2 log on both side:
  603. \begin_inset Formula
  604. \begin{align*}
  605. 2b/N-\log_{2}N & =-2b\\
  606. \frac{2b\left(N+1\right)}{N} & =\log_{2}N\\
  607. b & =\frac{N\log_{2}N}{2\left(N+1\right)}
  608. \end{align*}
  609. \end_inset
  610. \end_layout
  611. \begin_layout Section*
  612. Slowly varying sequence
  613. \end_layout
  614. \begin_layout Standard
  615. Let's see what happens with a slowly varying sequence rather than a constant
  616. one...
  617. \end_layout
  618. \end_body
  619. \end_document