Modified discrete cosine transform: Difference between revisions

Content deleted Content added
m Definition: fmt., punct.
 
(3 intermediate revisions by the same user not shown)
Line 31:
== Window functions ==
 
[[file:MDCT_WF.png|thumb|upright=1.8|'''MDCT window functions:'''<br> blue:{{snd}} Cosinecosine, red:{{snd}} Sine–Cosinesine–cosine, green:{{snd}} modified Kaiser–Bessel]]
 
In typical signal-compression applications, the transform properties are further improved by using a [[window function]] ''w''<sub>''n''</sub> (''n'' = 0, ..., 2''N''−1&nbsp;−&nbsp;1) that is multiplied with ''x''<sub>''n''</sub> in the MDCT and with ''y''<sub>''n''</sub> in the IMDCT formulas, above, in order to avoid discontinuities at the ''n'' = 0 and 2''N'' boundaries by making the function go smoothly to zero at those points. (That is, the window function is applied to the data ''before'' the MDCT or ''after'' the IMDCT.) In principle, ''x'' and ''y'' could have different window functions, and the window function could also change from one block to the next (especially for the case where data blocks of different sizes are combined), but for simplicity we consider the common case of identical window functions for equal-sized blocks.
 
The transform remains invertible (that is, TDAC works), for a symmetric window ''w''<sub>''n''</sub> = ''w''<sub>2''N''−1−''n''</sub>, as long as ''w'' satisfies the Princen-BradleyPrincen–Bradley condition:
: <math>w_n^2 + w_{n + N}^2 = 1.</math>.
 
:<math>w_n^2 + w_{n + N}^2 = 1</math>.
 
Various window functions are used. A window that produces a form known as a modulated lapped transform (MLT)<ref>H. S. Malvar, "Lapped Transforms for Efficient Transform/Subband Coding", ''IEEE Trans. on Acoustics, Speech, and Signal Processing'', vol. 38, no. 6, pp. 969–978 (Equation 22), June 1990.</ref><ref>H. S. Malvar, "Modulated QMF Filter Banks with Perfect Reconstruction", ''Electronics Letters'', vol. 26, no. 13, pp. 906–907 (Equation 13), June 1990.</ref> is given by
 
:<math>w_n = \sin \left[\frac{\pi}{2N} \left(n+\frac{1}{2}\right) \right]</math>
 
Various window functions are used. A window that produces a form known as a modulated lapped transform (MLT)<ref>H. S. Malvar, "Lapped Transforms for Efficient Transform/Subband Coding", ''IEEE Trans. on Acoustics, Speech, and Signal Processing'', vol. &nbsp;38, no. &nbsp;6, pp. &nbsp;969–978 (Equation &nbsp;22), June 1990.</ref><ref>H. S. Malvar, "Modulated QMF Filter Banks with Perfect Reconstruction", ''Electronics Letters'', vol. &nbsp;26, no. &nbsp;13, pp. &nbsp;906–907 (Equation &nbsp;13), June 1990.</ref> is given by
: <math>w_n = \sin \left[\frac{\pi}{2N} \left(n + \frac{1}{2}\right) \right]</math>
and is used for MP3 and MPEG-2 AAC, and
: <math>w_n = \sin \left( \frac{\pi}{2} \sin^2 \left[\frac{\pi}{2N} \left(n + \frac{1}{2}\right) \right] \right)</math>
 
:<math>w_n = \sin \left( \frac{\pi}{2} \sin^2 \left[\frac{\pi}{2N} \left(n+\frac{1}{2}\right) \right] \right)</math>
 
for Vorbis. AC-3 uses a [[Kaiser_window#Kaiser–Bessel-derived_(KBD)_window|Kaiser–Bessel derived (KBD) window]], and MPEG-4 AAC can also use a KBD window.
 
Note that windows applied to the MDCT are different from windows used for some other types of signal analysis, since they must fulfill the Princen–Bradley condition. One of the reasons for this difference is that MDCT windows are applied twice, for both the MDCT (analysis) and the IMDCT (synthesis).
 
== Relationship to DCT-IV and Originorigin of TDAC ==
 
As can be seen by inspection of the definitions, for '''even''' ''N'' the MDCT is essentially equivalent to a DCT-IV, where the input is shifted by ''N''/2 and two ''N''-blocks of data are transformed at once. By examining this equivalence more carefully, important properties like TDAC can be easily derived.
 
In order to define the precise relationship to the DCT-IV, one must realize that the DCT-IV corresponds to alternating even/odd boundary conditions: even at its left boundary (around ''n''&nbsp;=&nbsp;&minus;1/2), odd at its right boundary (around ''n''&nbsp;=&nbsp;''N''&nbsp;&minus;&nbsp;1/2), and so on (instead of periodic boundaries as for a [[discrete Fourier transform|DFT]]). This follows from the identities
: <math>\cos\left[\frac{\pi}{N} \left(-n - 1 + \frac{1}{2}\right) \left(k + \frac{1}{2}\right)\right] =
\cos\left[\frac{\pi}{N} \left(n + \frac{1}{2}\right) \left(k + \frac{1}{2}\right)\right]</math>
and
: <math>\cos\left[\frac{\pi}{N} \left(2N - n - 1 + \frac{1}{2}\right) \left(k + \frac{1}{2}\right)\right] =
-\cos\left[\frac{\pi}{N} \left(n + \frac{1}{2}\right) \left(k + \frac{1}{2}\right)\right].</math>.
Thus, if its inputs are an array ''x'' of length ''N'', we can imagine extending this array to (''x'', &minus;''x''<sub>''R''</sub>, &minus;''x'', ''x''<sub>''R''</sub>, ...) and so on, where ''x''<sub>''R''</sub> denotes ''x'' in reverse order.
 
Consider an MDCT with 2''N'' inputs and ''N'' outputs, where we divide the inputs into four blocks (''a'', ''b'', ''c'', ''d'') each of size ''N''/2. If we shift these to the right by ''N''/2 (from the +''N''/2 term in the MDCT definition), then (''b'', ''c'', ''d'') extend past the end of the ''N'' DCT-IV inputs, so we must "fold" them back according to the boundary conditions described above.
 
: Thus, the MDCT of 2''N'' inputs (''a'', ''b'', ''c'', ''d'') is ''exactly'' equivalent to a DCT-IV of the ''N'' inputs: (&minus;''c''<sub>''R''</sub>&nbsp;&minus;&nbsp;''d'', ''a''&nbsp;&minus;&nbsp;''b''<sub>''R''</sub>), where ''R'' denotes reversal as above.
 
(In this way, any algorithm to compute the DCT-IV can be trivially applied to the MDCT.)
 
Similarly, the IMDCT formula above is precisely 1/2 of the DCT-IV (which is its own inverse), where the output is extended (via the boundary conditions) to a length 2''N'' and shifted back to the left by ''N''/2. The inverse DCT-IV would simply give back the inputs (&minus;''c''<sub>''R''</sub>&minus;''d'', ''a''&minus;''b''<sub>''R''</sub>) from above. When this is extended via the boundary conditions and shifted, one obtains:
 
(In this way, any algorithm to compute the DCT-IV can be trivially applied to the MDCT.)
:IMDCT&nbsp;(MDCT&nbsp;(''a'', ''b'', ''c'', ''d''))&nbsp;=&nbsp;(''a''&minus;''b''<sub>''R''</sub>, ''b''&minus;''a''<sub>''R''</sub>, ''c''+''d''<sub>''R''</sub>, ''d''+''c''<sub>''R''</sub>)&nbsp;/&nbsp;2.
 
Similarly, the IMDCT formula above is precisely 1/2 of the DCT-IV (which is its own inverse), where the output is extended (via the boundary conditions) to a length 2''N'' and shifted back to the left by ''N''/2. The inverse DCT-IV would simply give back the inputs (&minus;''c''<sub>''R''</sub>&nbsp;&minus;&nbsp;''d'', ''a''&nbsp;&minus;&nbsp;''b''<sub>''R''</sub>) from above. When this is extended via the boundary conditions and shifted, one obtains:
Half of the IMDCT outputs are thus redundant, as ''b''&minus;''a''<sub>''R''</sub> = &minus;(''a''&minus;''b''<sub>''R''</sub>)<sub>''R''</sub>, and likewise for the last two terms. If we group the input into bigger blocks ''A'',''B'' of size ''N'', where ''A''&nbsp;=&nbsp;(''a'', ''b'') and ''B''&nbsp;=&nbsp;(''c'', ''d''), we can write this result in a simpler way:
: IMDCT&nbsp;(MDCT&nbsp;(''a'', ''b'', ''c'', ''d''))&nbsp; =&nbsp; (''a''&minus;''b''<sub>''R''</sub>, ''b''&minus;''a''<sub>''R''</sub>, ''c'' + ''d''<sub>''R''</sub>, ''d'' + ''c''<sub>''R''</sub>)&nbsp;/&nbsp;2.
 
:Half of the IMDCT outputs are thus redundant, as ''b''&nbsp;(MDCT&minus;&nbsp;(''Aa'', <sub>''BR''))&nbsp;</sub> = &nbspminus;(''Aa''&nbsp;&minus;&nbsp;''Ab''<sub>''R''</sub>)<sub>''R''</sub>, and likewise for the last two terms. If we group the input into bigger blocks ''BA''+,''B''<sub> of size ''RN'', where ''A''&nbsp;=&nbsp;(''a'', ''b''</sub>) and ''B''&nbsp;/=&nbsp;2(''c'', ''d''), we can write this result in a simpler way:
: IMDCT(MDCT(''A'', ''B'')) = (''A'' − ''A''<sub>''R''</sub>, ''B'' + ''B''<sub>''R''</sub>)/2.
 
One can now understand how TDAC works. Suppose that one computes the MDCT of the subsequent, 50% overlapped, 2''N'' block (''B'', ''C''). The IMDCT will then yield, analogous to the above: (''B''&nbsp;&minus;&nbsp;''B''<sub>''R''</sub>, ''C''&nbsp;+&nbsp;''C''<sub>''R''</sub>)&nbsp;/&nbsp;2. When this is added with the previous IMDCT result in the overlapping half, the reversed terms cancel and one obtains simply ''B'', recovering the original data.
 
=== Origin of TDAC ===
Line 78 ⟶ 77:
''a'' and of ''b''<sub>''R''</sub> to the MDCT of (''a'', ''b'', ''c'', ''d''), or equivalently, to
the result of
: IMDCT&nbsp;(MDCT&nbsp;(''a'', ''b'', ''c'', ''d''))&nbsp;=&nbsp; (''a''&minus;''b''<sub>''R''</sub>, ''b''&minus;''a''<sub>''R''</sub>, ''c'' + ''d''<sub>''R''</sub>, ''d'' + ''c''<sub>''R''</sub>) / 2.
The combinations ''c''&minus;''d''<sub>''R''</sub> and so on, have precisely the right signs for the combinations to cancel when they are added.
 
For '''odd''' ''N'' (which are rarely used in practice), ''N''/2 is not an integer, so the MDCT is not simply a shift permutation of a DCT-IV. In this case, the additional shift by half a sample means that the MDCT/IMDCT becomes equivalent to the DCT-III/II, and the analysis is analogous to the above.
 
=== Smoothness and discontinuities ===
 
We have seen above that the MDCT of 2''N'' inputs (''a'', ''b'', ''c'', ''d'') is equivalent to a DCT-IV of the ''N'' inputs (−''c''<sub>''R''</sub> − ''d'', ''a'' − ''b''<sub>''R''</sub>).
The DCT-IV is designed for the case where the function at the right boundary is odd, and therefore the values near the right boundary are close to 0. If the input signal is smooth, this is the case: the rightmost components of ''a'' and ''b''<sub>''R''</sub> are consecutive in the input sequence (''a'', ''b'', ''c'', ''d''), and therefore their difference is small.
''c'', ''d'') is equivalent to a DCT-IV of the ''N'' inputs
Let us look at the middle of the interval: if we rewrite the above expression as (−''c''<sub>''R''</sub> − ''d'', ''a'' − ''b''<sub>''R''</sub>) = (−''d'', ''a'') − (''b'', ''c'')<sub>''R''</sub>, the second term, (''b'', ''c'')<sub>''R''</sub>, gives a smooth transition in the middle.
(&minus;''c''<sub>''R''</sub>&minus;''d'',
However, in the first term, (−''d'', ''a''), there is a potential discontinuity where the right end of −''d'' meets the left end of ''a''.
''a''&minus;''b''<sub>''R''</sub>).
This is the reason for using a window function that reduces the components near the boundaries of the input sequence (''a'', ''b'', ''c'', ''d'') towards 0.
The DCT-IV is designed for the
case where the function at the right boundary is odd, and therefore
the values near the right boundary are close to 0. If the input signal is smooth,
this is the case: the rightmost components of ''a'' and ''b''<sub>''R''</sub> are
consecutive in the input sequence (''a'', ''b'', ''c'', ''d''), and
therefore their difference is small.
Let us look at the middle of the interval:
if we rewrite the above expression as
(&minus;''c''<sub>''R''</sub>&minus;''d'',
''a''&minus;''b''<sub>''R''</sub>) = (&minus;''d'', ''a'')&minus;(''b'',''c'')<sub>''R''</sub>,
the second term, (''b'',''c'')<sub>''R''</sub>, gives a smooth
transition in the middle.
However, in the first term, (&minus;''d'', ''a''), there is a
potential discontinuity where the right end of
&minus;''d'' meets the left end of ''a''.
This is the reason for using a window function that reduces the components
near the boundaries of the input sequence (''a'', ''b'',
''c'', ''d'') towards 0.
 
=== TDAC for the windowed MDCT ===