Understanding DCT and DST [3]: Discrete Sine Transform

This article mainly deduces the principles and formulas of the previous blogDiscrete Fourier Transform DFT, Discrete Cosine Transform DCT, Discrete Sine Transform DST Modified from pictures to Markdown scripts to facilitate readers' browsing, and added some content. However, since the article has too many characters to fit all on one blog, I split the previous article into three parts, and you can view the other parts through the links below.

3 Discrete Sine Transform (DST)

The discrete sine transform is similar to the discrete cosine transform, except that unlike the discrete cosine transform, which extends a finite-length asymmetric real sequence into a finite-length symmetric real sequence, the discrete sine transform extends a finite-length asymmetric real sequence into a finite-length antisymmetric real sequence. .

It can be seen from Section 1.5.5 that for a finite-length antisymmetric real sequence, its DFT sequence multiplied by the imaginary unit j is also a finite-length antisymmetric real sequence. Similar to a finite-length symmetric real sequence, the calculation of the DFT of a finite-length antisymmetric real sequence only requires half of the sampling point data of the sequence, and can be converted into a real number operation involving only the sine function, so it has similar calculations to the discrete cosine transform the complexity. Similarly, the discrete sine transform corresponds to the non-redundant part of the discrete Fourier transform of the antisymmetric continuation sequence of an asymmetric finite-length real sequence. Different continuation methods correspond to different continuation sequence lengths and different discrete Fourier transforms. The leaf transform coefficients therefore correspond to different discrete sine transform coefficients. According to the analysis in Section 1.5.6, the non-redundant part of the discrete Fourier transform coefficients, that is, the number of independent components, is consistent with the number of independent components in the original sequence, so the number of discrete sine transform coefficients also corresponds to The number of independent components in the continuation sequence.

Mathematically, the discrete sine transform defines a total of 8 forms, which is just opposite to the continuation method of the discrete cosine transform, that is, changing the symmetrical part to antisymmetry, and changing the antisymmetrical part to symmetrical, thus corresponding to 8 finite length non-linear transformations. The antisymmetric continuation methods of symmetric real sequences are represented by DST-I ~ DST-VIII respectively. In the H.266 video encoding and decoding standard, DST-VII is mainly used. The following is mainly derivation and analysis. For other types of DST, only the corresponding extension methods and corresponding formula definitions are given.

3.1 DST-VII

The finite-length asymmetric real sequence shown in Figure 2-1 x [ n ] x[n] DST-VII objection for x[n] The scale and period extension are shown in Figure 3-1. To be precise, the formulaic definition of the continuation sequence is as shown in Equation (3-1), where the wavy line represents the periodic continuation of the corresponding finite-length sequence. Then, the finite-length antisymmetric real sequence y [ m ] y[m] y[m]'s longevity 4 N + 2 4N+2 4N+2, there are only independent quantities N N N, so it can be predicted that the independent components of its DFT are only N N N 个.

y ~ [ m + k ( 4 N + 2 ) ] = sign ⁡ ( m ) ⋅ { x ~ [ ∣ m ∣ − 1 ] , ∣ m ∣ ⩽ N x ~ [ 2 N − ∣ m ∣ ] , N + 1 ⩽ ∣ m ∣ ⩽ 2 N 0 , ∣ m ∣ = 2 N + 1 w h e r e   m = − 2 N − 1 , − 2 N , . . . , 2 N . (3-1) \begin{gathered} \tilde y\left[ {m + k\left( {4N + 2} \right)} \right] = \operatorname{sign} (m) \cdot \left\{ {\begin{array}{l} {\tilde x\left[ {\left| m \right| - 1} \right],}&{\left| m \right| \leqslant N} \\ {\tilde x\left[ {2N - \left| m \right|} \right],}&{N + 1 \leqslant \left| m \right| \leqslant 2N} \\ {0,}&{\left| m \right| = 2N + 1} \end{array}} \right. \\ where{\text{ }}m = - 2N - 1, - 2N,...,2N. \\ \end{gathered} \tag{3-1} and~[m+k(4N+2)]=sign(m) x~[m1],x~[2Nm],0,mNN+1m2Nm=2N+1where m=2N1,2N,...,2N.(3-1)

Figure 3-1 DST-VII extension
Figure 3-2 DFT sequence of DST-VII continuation sequence

According to the previous content, there are

j Y ~ [ l ] = j ∑ m = − 2 N − 1 2 N y ~ [ m ] e − j 2 π l m 4 N + 2 = j ∑ m = 1 2 N − 2 y [ m ] ( e − j π l m 2 N + 1 − e j π l m 2 N + 1 ) = 2 ∑ m = 1 2 N y [ m ] sin ⁡ ( π l m 2 N + 1 ) = 2 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π l ( n + 1 ) 2 N + 1 ] + 2 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π l ( 2 N + 1 − n − 1 ) 2 N + 1 ] = 2 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π l ( n + 1 ) 2 N + 1 ] + 2 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π l − π l ( n + 1 ) 2 N + 1 ] = 2 ⋅ [ 1 − ( − 1 ) l ] ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π l ( n + 1 ) 2 N + 1 ] (3-2) \begin{aligned} j\tilde Y[l] &= j\sum\limits_{m = - 2N - 1}^{2N} {\tilde y[m]{e^{ - j\frac{ {2\pi lm}}{ {4N + 2}}}}} = j\sum\limits_{m = 1}^{2N - 2} {y[m]\left( { {e^{ - j\frac{ {\pi lm}}{ {2N + 1}}}} - {e^{j\frac{ {\pi lm}}{ {2N + 1}}}}} \right)} \\ &= 2\sum\limits_{m = 1}^{2N} {y[m]\sin \left( {\frac{ {\pi lm}}{ {2N + 1}}} \right)} \\ &= 2\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi l\left( {n + 1} \right)}}{ {2N + 1}}} \right]} + 2\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi l\left( {2N + 1 - n - 1} \right)}}{ {2N + 1}}} \right]} \\ &= 2\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi l\left( {n + 1} \right)}}{ {2N + 1}}} \right]} + 2\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\pi l - \frac{ {\pi l\left( {n + 1} \right)}}{ {2N + 1}}} \right]} \\ &= 2 \cdot \left[ {1 - { {\left( { - 1} \right)}^l}} \right]\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi l\left( {n + 1} \right)}}{ {2N + 1}}} \right]} \\ \end{aligned} \tag{3-2} jAND~[l]=jm=2N12Nand~[m]ej4N+22πlm=jm=12N2y[m](ej2N+1πlmIt isj2N+1πlm)=2m=12Ny[m]sin(2N+1πlm)=2n=0N1x[n]sin[2N+1πl(n+1)]+2n=0N1x[n]sin[2N+1πl(2N+1n1)]=2n=0N1x[n]sin[2N+1πl(n+1)]+2n=0N1x[n]sin[πl2N+1πl(n+1)]=2[1(1)l]n=0N1x[n]sin[2N+1πl(n+1)](3-2)

The following properties can be obtained,

j Y ~ [ 2 l ] = 0 ,   j Y ~ [ l ] = − j Y ~ [ − l ] j Y ~ [ 4 N + 2 − l ] = − j Y ~ [ l ] j Y ~ [ 2 N + 1 ] = − j Y ~ [ 4 N + 2 − 2 N − 1 ] = − j Y ~ [ 2 N + 1 ] = 0 (3-3) \begin{gathered} j\tilde Y[2l] = 0,{\text{ }}j\tilde Y[l] = - j\tilde Y[ - l] \\ j\tilde Y[4N + 2 - l] = - j\tilde Y[l] \\ j \tilde Y[2N + 1] = - j\tilde Y[4N + 2 - 2N - 1] = - j\tilde Y[2N + 1] = 0 \\ \end{gathered} \tag{3-3}jAND~[2l]=0, jAND~[l]=jAND~[l]jAND~[4N+2l]=jAND~[l]jAND~[2N+1]=jAND~[4N+22N1]=jAND~[2N+1]=0(3-3)

So, finite length antisymmetric real sequence y [ m ] y[m] y[m] 4 N + 2 4N+2 4N+2 The independent components in the point DFT are indeed only N N N items. As an example, the DFT of the continuation sequence defined in Figure 3-1 is shown in Figure 3-2.

According to the above properties, its inverse transformation can be obtained as

y [ m ] = 1 4 N + 2 ∑ l = 0 4 N + 1 Y [ l ] e j 2 π l m 4 N + 2 = − j 4 N + 2 ∑ l = 0 4 N + 1 j Y [ l ] e j 2 π l m 4 N + 2 = − j 4 N + 2 ∑ l = 0 N − 1 j Y [ 2 l + 1 ] [ e j 2 π ( 2 l + 1 ) m 4 N + 2 − e j 2 π ( 4 N + 2 − 2 l − 1 ) m 4 N + 2 ] = − j 4 N + 2 ∑ l = 0 N − 1 j Y [ 2 l + 1 ] [ e j π ( 2 l + 1 ) m 2 N + 1 − e − j π ( 2 l + 1 ) m 2 N + 1 ] = 1 2 N + 1 ∑ l = 0 N − 1 j Y [ 2 l + 1 ] sin ⁡ [ π ( 2 l + 1 ) m 2 N + 1 ] (3-4) \begin{aligned} y[m] &= \frac{1}{ {4N + 2}}\sum\limits_{l = 0}^{4N + 1} {Y[l]{e^{j\frac{ {2\pi lm}}{ {4N + 2}}}}} = \frac{ { - j}}{ {4N + 2}}\sum\limits_{l = 0}^{4N + 1} {jY[l]{e^{j\frac{ {2\pi lm}}{ {4N + 2}}}}} \\ &= \frac{ { - j}}{ {4N + 2}}\sum\limits_{l = 0}^{N - 1} {jY[2l + 1]\left[ { {e^{j\frac{ {2\pi \left( {2l + 1} \right)m}}{ {4N + 2}}}} - {e^{j\frac{ {2\pi \left( {4N + 2 - 2l - 1} \right)m}}{ {4N + 2}}}}} \right]} \\ &= \frac{ { - j}}{ {4N + 2}}\sum\limits_{l = 0}^{N - 1} {jY[2l + 1]\left[ { {e^{j\frac{ {\pi \left( {2l + 1} \right)m}}{ {2N + 1}}}} - {e^{ - j\frac{ {\pi \left( {2l + 1} \right)m}}{ {2N + 1}}}}} \right]} \\ &= \frac{1}{ {2N + 1}}\sum\limits_{l = 0}^{N - 1} {jY[2l + 1]\sin \left[ {\frac{ {\pi \left( {2l + 1} \right)m}}{ {2N + 1}}} \right]} \\ \end{aligned} \tag{3-4} y[m]=4N+21l=04N+1Y[l]ej4N+22πlm=4N+2jl=04N+1jY[l]ej4N+22πlm=4N+2jl=0N1jY[2l+1][ej4N+22π(2l+1)mIt isj4N+22π(4N+22l1)m]=4N+2jl=0N1jY[2l+1][ej2N+1π(2l+1)mIt isj2N+1π(2l+1)m]=2N+11l=0N1jY[2l+1]sin[2N+1Pi(2l+1)m](3-4)

Therefore, the calculation formula of DST-VII is defined as follows,

X [ k ] = D S T 7 [ x [ n ] ] = j Y [ 2 k + 1 ] = 4 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( 2 k + 1 ) ( n + 1 ) 2 N + 1 ] x [ n ] = I D S T 7 [ X [ k ] ] = y [ n + 1 ] = 1 2 N + 1 ∑ k = 0 N − 1 X [ k ] sin ⁡ [ π ( 2 k + 1 ) ( n + 1 ) 2 N + 1 ] w h e r e   n , k = 0 , 1 , . . . , N − 1. (3-5) \begin{gathered} X[k] = DS{T_7}\left[ {x[n]} \right] = jY[2k + 1] = 4\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {n + 1} \right)}}{ {2N + 1}}} \right]} \\ x[n] = IDS{T_7}\left[ {X[k]} \right] = y[n + 1] = \frac{1}{ {2N + 1}}\sum\limits_{k = 0}^{N - 1} {X[k]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {n + 1} \right)}}{ {2N + 1}}} \right]} \\ where{\text{ }}n,k = 0,1,...,N - 1. \\ \end{gathered} \tag{3-5} X[k]=DST7[x[n]]=jY[2k+1]=4n=0N1x[n]sin[2N+1Pi(2k+1)(n+1)]x[n]=IDST7[X[k]]=y[n+1]=2N+11k=0N1X[k]sin[2N+1Pi(2k+1)(n+1)]where n,k=0,1,...,N1.(3-5)

For the consistency of the formula, the coefficients of equation (3-5) are evenly distributed to both sides, then we have

X [ k ] = D S T 7 [ x [ n ] ] = 2 2 N + 1 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( 2 k + 1 ) ( n + 1 ) 2 N + 1 ] x [ n ] = I D S T 7 [ X [ k ] ] = 2 2 N + 1 ∑ k = 0 N − 1 X [ k ] sin ⁡ [ π ( 2 k + 1 ) ( n + 1 ) 2 N + 1 ] w h e r e   n , k = 0 , 1 , . . . , N − 1. (3-6) \begin{gathered} X[k] = DS{T_7}\left[ {x[n]} \right] = \frac{2}{ {\sqrt {2N + 1} }}\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {n + 1} \right)}}{ {2N + 1}}} \right]} \\ x[n] = IDS{T_7}\left[ {X[k]} \right] = \frac{2}{ {\sqrt {2N + 1} }}\sum\limits_{k = 0}^{N - 1} {X[k]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {n + 1} \right)}}{ {2N + 1}}} \right]} \\ where{\text{ }}n,k = 0,1,...,N - 1. \\ \end{gathered} \tag{3-6} X[k]=DST7[x[n]]=2N+1 2n=0N1x[n]sin[2N+1Pi(2k+1)(n+1)]x[n]=IDST7[X[k]]=2N+1 2k=0N1X[k]sin[2N+1Pi(2k+1)(n+1)]where n,k=0,1,...,N1.(3-6)

It is easy to prove that, similar to the discrete cosine transform, the discrete sine transform defined by Equation (3-6) is also an orthogonal transform and will not be described again here.

3.2 DST-I

The formulation of DST-I continuation is as follows,

y ~ [ m + k ( 2 N + 2 ) ] = sign ⁡ ( m ) ⋅ { x ~ [ ∣ m ∣ − 1 ] , ∣ m ∣ ⩽ N 0 , m = − N − 1 w h e r e   m = − N − 1 , − N , . . . , N . (3-7) \begin{gathered} \tilde y\left[ {m + k\left( {2N + 2} \right)} \right] = \operatorname{sign} \left( m \right) \cdot \left\{ {\begin{array}{l} {\tilde x\left[ {\left| m \right| - 1} \right],}&{\left| m \right| \leqslant N} \\ {0,}&{m = - N - 1} \end{array}} \right. \\ where{\text{ }}m = - N - 1, - N,...,N. \\ \end{gathered} \tag{3-7} and~[m+k(2N+2)]=sign(m){ x~[m1],0,mNm=N1where m=N1,N,...,N.(3-7)

As an example, the DST-I antisymmetry and periodic continuation of the finite-length asymmetric real sequence defined in Figure 2-1 is shown in Figure 3-3, and its corresponding discrete Fourier transform sequence is shown in Figure 3-4 .

Figure 3-3 DST-I extension
Figure 3-4 DFT sequence of DST-I continuation sequence

It is easy to get the discrete sine transform formula corresponding to DST-I as follows,

X [ k ] = D S T 1 [ x [ n ] ] = 2 N + 1 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( k + 1 ) ( n + 1 ) N + 1 ] x [ n ] = I D S T 1 [ X [ k ] ] = 2 N + 1 ∑ k = 0 N − 1 X [ k ] sin ⁡ [ π ( k + 1 ) ( n + 1 ) N + 1 ] w h e r e   n , k = 0 , 1 , . . . , N − 1. (3-8) \begin{gathered} X[k] = DS{T_1}\left[ {x[n]} \right] = \sqrt {\frac{2}{ {N + 1}}} \sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {k + 1} \right)\left( {n + 1} \right)}}{ {N + 1}}} \right]} \\ x[n] = IDS{T_1}\left[ {X[k]} \right] = \sqrt {\frac{2}{ {N + 1}}} \sum\limits_{k = 0}^{N - 1} {X[k]\sin \left[ {\frac{ {\pi \left( {k + 1} \right)\left( {n + 1} \right)}}{ {N + 1}}} \right]} \\ where{\text{ }}n,k = 0,1,...,N - 1.\\ \end{gathered} \tag{3-8} X[k]=DST1[x[n]]=N+12 n=0N1x[n]sin[N+1Pi(k+1)(n+1)]x[n]=IDST1[X[k]]=N+12 k=0N1X[k]sin[N+1Pi(k+1)(n+1)]where n,k=0,1,...,N1.(3-8)

3.3 DST-II

The finite-length asymmetric real sequence shown in Figure 2-1 x [ n ] x[n] DST-II for x[n] is opposed The scale and period extension are shown in Figure 3-5(a). Since the sequence is shifted to the right by 1/2, all sampling points are at non-integer index positions, so it is necessary to perform 2 times zero-insertion upsampling on the sequence, and the discrete sequence is obtained as shown in Figure 3-5(b). To be precise, the formulaic definition of the continuation sequence is as shown in Equation (3-9), where the wavy line represents the periodic continuation of the corresponding finite-length sequence, and the non-integer index position defaults to 0. The DFT sequence of the continuation sequence shown in Figure 3-5(b) is shown in Figure 3-6.

y ~ [ m + 4 k N ] = sign ⁡ ( m ) ⋅ x ~ [ ∣ m ∣ − 1 2 ] ,   m = − 2 N , − 2 N + 1 , . . . , 2 N − 1. (3-9) \tilde y\left[ {m + 4kN} \right] = \operatorname{sign} \left( m \right) \cdot \tilde x\left[ {\frac{ {\left| m \right| - 1}}{2}} \right],{\text{ }}m = - 2N, - 2N + 1,...,2N - 1.\tag{3-9} and~[m+4kN]=sign(m)x~[2m1], m=2N,2N+1,...,2N1.(3-9)

Figure 3-5 DST-II continuation (a) and its zero-insertion upsampling (b)
Figure 3-6 DFT sequence of DST-II continuation sequence

The discrete sine transform formula corresponding to DST-II can be easily obtained as follows,

X [ k ] = D S T 2 [ x [ n ] ] = 2 N η k ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( k + 1 ) ( 2 n + 1 ) 2 N ] x [ n ] = I D S T 2 [ X [ k ] ] = 2 N η k ∑ k = 0 N − 1 X [ k ] sin ⁡ [ π ( k + 1 ) ( 2 n + 1 ) 2 N ] w h e r e   n , k = 0 , 1 , . . . , N − 1. (3-10) \begin{gathered} X[k] = DS{T_2}\left[ {x[n]} \right] = \sqrt {\frac{2}{N}} {\eta _k}\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {k + 1} \right)\left( {2n + 1} \right)}}{ {2N}}} \right]} \\ x[n] = IDS{T_2}\left[ {X[k]} \right] = \sqrt {\frac{2}{N}} {\eta _k}\sum\limits_{k = 0}^{N - 1} {X[k]\sin \left[ {\frac{ {\pi \left( {k + 1} \right)\left( {2n + 1} \right)}}{ {2N}}} \right]} \\ where{\text{ }}n,k = 0,1,...,N - 1. \\ \end{gathered} \tag{3-10} X[k]=DST2[x[n]]=N2 thekn=0N1x[n]sin[2NPi(k+1)(2n+1)]x[n]=IDST2[X[k]]=N2 thekk=0N1X[k]sin[2NPi(k+1)(2n+1)]where n,k=0,1,...,N1.(3-10)

in

η k = { 1 2 , k = N − 1 1 , k ≠ N − {\eta _k} = \left{{\begin{array}{l}{\frac{1}{ {\sqrt 2}},}&{k = N-1}\\{1,}&{k \ne N-1}\end{array}}\right .. thek={ 2 1,1,k=N1k=N1.

3.4 DST-III

The formulation of DST-III continuation is as follows,

y ~ [ m + 4 k N ] = sign ⁡ ( m ) ⋅ { x [ ∣ m ∣ − 1 ] , ∣ m ∣ ⩽ N x [ 2 N − 1 − ∣ m ∣ ] , N ⩽ ∣ m ∣ ⩽ 2 N − 1 0 , ∣ m ∣ = 2 N w h e r e   m = − 2 N , − 2 N + 1 , . . . , 2 N − 1. (3-11) \begin{gathered} \tilde y[m + 4kN] = \operatorname{sign} \left( m \right) \cdot \left\{ {\begin{array}{l} {x\left[ {\left| m \right| - 1} \right],}&{\left| m \right| \leqslant N} \\ {x\left[ {2N - 1 - \left| m \right|} \right],}&{N \leqslant \left| m \right| \leqslant 2N - 1} \\ {0,}&{\left| m \right| = 2N} \end{array}} \right. \\ where{\text{ }}m = - 2N, - 2N + 1,...,2N - 1. \\ \end{gathered} \tag{3-11} and~[m+4kN]=sign(m) x[m1],x[2N1m],0,mNNm2N1m=2Nwhere m=2N,2N+1,...,2N1.(3-11)

As an example, the DST-III antisymmetry and periodic continuation of the finite-length asymmetric real sequence defined in Figure 2-1 is shown in Figure 3-7, and its corresponding discrete Fourier transform sequence is shown in Figure 3-8 .

Figure 3-7 DST-III extension
Figure 3-8 DFT sequence of DST-III continuation sequence

It is easy to get the discrete sine transform formula corresponding to DST-III as follows,

X [ k ] = D S T 3 [ x [ n ] ] = 2 N η n ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( 2 k + 1 ) ( n + 1 ) 2 N ] x [ n ] = I D S T 3 [ X [ k ] ] = 2 N η n ∑ k = 0 N − 1 X [ k ] sin ⁡ [ π ( 2 k + 1 ) ( n + 1 ) 2 N ] w h e r e   n , k = 0 , 1 , . . . , N − 1. (3-12) \begin{gathered} X[k] = DS{T_3}\left[ {x[n]} \right] = \sqrt {\frac{2}{N}} {\eta _n}\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {n + 1} \right)}}{ {2N}}} \right]} \\ x[n] = IDS{T_3}\left[ {X[k]} \right] = \sqrt {\frac{2}{N}} {\eta _n}\sum\limits_{k = 0}^{N - 1} {X[k]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {n + 1} \right)}}{ {2N}}} \right]} \\ where{\text{ }}n,k = 0,1,...,N - 1. \\ \end{gathered} \tag{3-12} X[k]=DST3[x[n]]=N2 thenn=0N1x[n]sin[2NPi(2k+1)(n+1)]x[n]=IDST3[X[k]]=N2 thenk=0N1X[k]sin[2NPi(2k+1)(n+1)]where n,k=0,1,...,N1.(3-12)

in

η n = { 1 2 , n = N − 1 1 , n ≠ N − 1 . {\eta _n} = \left\{ {\begin{array}{l} {\frac{1}{ {\sqrt 2 }},}&{n = N - 1} \\ {1,}&{n \ne N - 1} \end{array}} \right.. then={ 2 1,1,n=N1n=N1.

3.5 DST-IV

The finite-length asymmetric real sequence shown in Figure 2-1 x [ n ] x[n] DST-IV objection for x[n] The scale and period extension are shown in Figure 3-9(a). Since the sequence is shifted to the right by 1/2, all sampling points are at non-integer index positions, so it is necessary to perform 2 times zero-insertion upsampling on the sequence, and the discrete sequence is obtained as shown in Figure 3-9(b). To be precise, the formulaic definition of the continuation sequence is as shown in Equation (3-13), where the wavy line represents the periodic continuation of the corresponding finite-length sequence, and the non-integer index position defaults to 0. The DFT sequence of the continuation sequence shown in Figure 3-9(b) is shown in Figure 3-10.

y ~ [ m + 8 k N ] = sign ⁡ ( m ) ⋅ { x ~ [ ∣ m ∣ − 1 2 ] , ∣ m ∣ ⩽ 2 N − 1 x ~ [ 4 N − 1 − ∣ m ∣ 2 ] , ∣ m ∣ ⩾ 2 N w h e r e   m = − 4 N , − 4 N + 1 , . . . , 4 N − 1. (3-13) \begin{gathered} \tilde y\left[ {m + 8kN} \right] = \operatorname{sign} \left( m \right) \cdot \left\{ {\begin{array}{l} {\tilde x\left[ {\frac{ {\left| m \right| - 1}}{2}} \right],}&{\left| m \right| \leqslant 2N - 1} \\ {\tilde x\left[ {\frac{ {4N - 1 - \left| m \right|}}{2}} \right],}&{\left| m \right| \geqslant 2N} \end{array}} \right. \\ where{\text{ }}m = - 4N, - 4N + 1,...,4N - 1. \\ \end{gathered} \tag{3-13} and~[m+8kN]=sign(m) x~[2m1],x~[24N1m],m2N1m2Nwhere m=4N,4N+1,...,4N1.(3-13)

Figure 3-9 DST-IV continuation (a) and its zero-insertion upsampling (b)
Figure 3-10 DFT sequence of DST-IV continuation sequence

The discrete sine transform formula corresponding to DST-IV can be easily obtained as follows,

X [ k ] = D S T 4 [ x [ n ] ] = 2 N ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( 2 k + 1 ) ( 2 n + 1 ) 4 N ] x [ n ] = I D S T 4 [ X [ k ] ] = 2 N ∑ k = 0 N − 1 X [ k ] sin ⁡ [ π ( 2 k + 1 ) ( 2 n + 1 ) 4 N ] w h e r e   n , k = 0 , 1 , . . . , N − 1. (3-14) \begin{gathered} X[k] = DS{T_4}\left[ {x[n]} \right] = \sqrt {\frac{2}{N}} \sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {2n + 1} \right)}}{ {4N}}} \right]} \\ x[n] = IDS{T_4}\left[ {X[k]} \right] = \sqrt {\frac{2}{N}} \sum\limits_{k = 0}^{N - 1} {X[k]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {2n + 1} \right)}}{ {4N}}} \right]} \\ where{\text{ }}n,k = 0,1,...,N - 1. \\ \end{gathered} \tag{3-14} X[k]=DST4[x[n]]=N2 n=0N1x[n]sin[4NPi(2k+1)(2n+1)]x[n]=IDST4[X[k]]=N2 k=0N1X[k]sin[4NPi(2k+1)(2n+1)]where n,k=0,1,...,N1.(3-14)

3.6 DST-V

The formulation of DST-V continuation is as follows,

y ~ [ m + k ( 2 N + 1 ) ] = sign ⁡ ( m ) ⋅ x ~ [ ∣ m ∣ − 1 ] ,   m = − N , − N + 1 , . . . , N . (3-15) \tilde y\left[ {m + k\left( {2N + 1} \right)} \right] = \operatorname{sign} \left( m \right) \cdot \tilde x\left[ {\left| m \right| - 1} \right],{\text{ }}m = - N, - N + 1,...,N. \tag{3-15} and~[m+k(2N+1)]=sign(m)x~[m1], m=N,N+1,...,N.(3-15)

As an example, the DST-V antisymmetry and periodic continuation of the finite-length asymmetric real sequence defined in Figure 2-1 is shown in Figure 3-11, and its corresponding discrete Fourier transform sequence is shown in Figure 3-12.

Figure 3-11 DST-V extension
Figure 3-12 DFT sequence of DST-V continuation sequence

It is easy to get the discrete sine transform formula corresponding to DST-V as follows,

X [ k ] = D S T 5 [ x [ n ] ] = 2 2 N + 1 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ 2 π ( k + 1 ) ( n + 1 ) 2 N + 1 ] x [ n ] = I D S T 5 [ X [ k ] ] = 2 2 N + 1 ∑ k = 0 N − 1 X [ k ] sin ⁡ [ 2 π ( k + 1 ) ( n + 1 ) 2 N + 1 ] w h e r e   n , k = 0 , 1 , . . . , N − 1. (3-16) \begin{gathered} X[k] = DS{T_5}\left[ {x[n]} \right] = \frac{2}{ {\sqrt {2N + 1} }}\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {2\pi \left( {k + 1} \right)\left( {n + 1} \right)}}{ {2N + 1}}} \right]} \\ x[n] = IDS{T_5}\left[ {X[k]} \right] = \frac{2}{ {\sqrt {2N + 1} }}\sum\limits_{k = 0}^{N - 1} {X[k]\sin \left[ {\frac{ {2\pi \left( {k + 1} \right)\left( {n + 1} \right)}}{ {2N + 1}}} \right]} \\ where{\text{ }}n,k = 0,1,...,N - 1. \\ \end{gathered} \tag{3-16} X[k]=DST5[x[n]]=2N+1 2n=0N1x[n]sin[2N+12π(k+1)(n+1)]x[n]=IDST5[X[k]]=2N+1 2k=0N1X[k]sin[2N+12π(k+1)(n+1)]where n,k=0,1,...,N1.(3-16)

3.7 DST-VI

Finite length asymmetric real sequence of Figure 2-1 x [ n ] x[n] DST-VI objection for x[n] The scale and period extension are shown in Figure 3-13(a). Since the sequence is shifted to the right by 1/2, all sampling points are at non-integer index positions, so the sequence needs to be upsampled by 2 times zero interpolation, and the discrete sequence is obtained as shown in Figure 3-13(b). To be precise, the formulaic definition of the continuation sequence is as shown in Equation (3-17), where the wavy line represents the periodic continuation of the corresponding finite-length sequence, and the non-integer index position defaults to 0. The DFT sequence of the continuation sequence shown in Figure 3-13(b) is shown in Figure 3-14.

y ~ [ m + k ( 4 N + 2 ) ] = sign ⁡ ( m ) ⋅ { x ~ [ ∣ m ∣ − 1 2 ] , ∣ m ∣ ⩽ 2 N 0 , ∣ m ∣ = 2 N + 1 w h e r e   m = − 2 N − 1 , − 2 N , . . . , 2 N . (3-17) \begin{gathered} \tilde y\left[ {m + k\left( {4N + 2} \right)} \right] = \operatorname{sign} \left( m \right) \cdot \left\{ {\begin{array}{l} {\tilde x\left[ {\frac{ {\left| m \right| - 1}}{2}} \right],}&{\left| m \right| \leqslant 2N} \\ {0,}&{\left| m \right| = 2N + 1} \end{array}} \right. \\ where{\text{ }}m = - 2N - 1, - 2N,...,2N. \\ \end{gathered} \tag{3-17} and~[m+k(4N+2)]=sign(m){ x~[2m1],0,m2Nm=2N+1where m=2N1,2N,...,2N.(3-17)

The discrete cosine transform formula corresponding to DST-VI can be easily obtained as follows:

X [ k ] = D S T 6 [ x [ n ] ] = 2 2 N + 1 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( k + 1 ) ( 2 n + 1 ) 2 N + 1 ] x [ n ] = I D S T 6 [ X [ k ] ] = 2 2 N + 1 ∑ k = 0 N − 1 X [ k ] sin ⁡ [ π ( k + 1 ) ( 2 n + 1 ) 2 N + 1 ] w h e r e   n , k = 0 , 1 , . . . , N − 1. (3-18) \begin{gathered} X[k] = DS{T_6}\left[ {x[n]} \right] = \frac{2}{ {\sqrt {2N + 1} }}\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {k + 1} \right)\left( {2n + 1} \right)}}{ {2N + 1}}} \right]} \\ x[n] = IDS{T_6}\left[ {X[k]} \right] = \frac{2}{ {\sqrt {2N + 1} }}\sum\limits_{k = 0}^{N - 1} {X[k]\sin \left[ {\frac{ {\pi \left( {k + 1} \right)\left( {2n + 1} \right)}}{ {2N + 1}}} \right]} \\ where{\text{ }}n,k = 0,1,...,N - 1. \\ \end{gathered} \tag{3-18} X[k]=DST6[x[n]]=2N+1 2n=0N1x[n]sin[2N+1Pi(k+1)(2n+1)]x[n]=IDST6[X[k]]=2N+1 2k=0N1X[k]sin[2N+1Pi(k+1)(2n+1)]where n,k=0,1,...,N1.(3-18)

Figure 3-13 DST-VI continuation (a) and its zero-insertion upsampling (b)
Figure 3-14 DFT sequence of DST-VI continuation sequence

3.8 DST-VIII

Finite length asymmetric real sequence of Figure 2-1 x [ n ] x[n] DST-VIII objection for x[n] The scale and period extension are shown in Figure 3-15(a). Since the sequence is shifted to the right by 1/2, all sampling points are at non-integer index positions, so the sequence needs to be upsampled by 2 times zero interpolation, and the discrete sequence is obtained as shown in Figure 3-15(b). To be precise, the formulaic definition of the continuation sequence is as shown in Equation (3-19), where the wavy line represents the periodic continuation of the corresponding finite-length sequence, and the non-integer index position defaults to 0. The DFT sequence of the continuation sequence shown in Figure 3-15(b) is shown in Figure 3-16.

y ~ [ m + k ( 8 N − 4 ) ] = sign ⁡ ( m ) ⋅ { x ~ [ ∣ m ∣ − 1 2 ] , ∣ m ∣ ⩽ 2 N − 1 x ~ [ 4 N − 3 − ∣ m ∣ 2 ] , ∣ m ∣ ⩾ 2 N w h e r e   m = − 4 N + 2 , − 4 N + 3 , . . . , 4 N − 3. (3-19) \begin{gathered} \tilde y\left[ {m + k\left( {8N - 4} \right)} \right] = \operatorname{sign} \left( m \right) \cdot \left\{ {\begin{array}{l} {\tilde x\left[ {\frac{ {\left| m \right| - 1}}{2}} \right],}&{\left| m \right| \leqslant 2N - 1} \\ {\tilde x\left[ {\frac{ {4N - 3 - \left| m \right|}}{2}} \right],}&{\left| m \right| \geqslant 2N} \end{array}} \right. \\ where{\text{ }}m = - 4N + 2, - 4N + 3,...,4N - 3. \\ \end{gathered} \tag{3-19} and~[m+k(8N4)]=sign(m) x~[2m1],x~[24N3m],m2N1m2Nwhere m=4N+2,4N+3,...,4N3.(3-19)

Figure 3-15 DST-VIII continuation (a) and its zero-insertion upsampling (b)
Figure 3-16 DFT sequence of DST-VIII continuation sequence

The discrete sine transform formula corresponding to DST-VIII can be easily obtained as follows,

X [ k ] = D S T 8 [ x [ n ] ] = 2 2 N − 1 η k η n ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( 2 k + 1 ) ( 2 n + 1 ) 4 N − 2 ] x [ n ] = I D S T 8 [ X [ k ] ] = 2 2 N − 1 η k η n ∑ k = 0 N − 1 X [ k ] sin ⁡ [ π ( 2 k + 1 ) ( 2 n + 1 ) 4 N − 2 ] w h e r e   n , k = 0 , 1 , . . . , N − 1. (3-20) \begin{gathered} X[k] = DS{T_8}\left[ {x[n]} \right] = \frac{2}{ {\sqrt {2N - 1} }}{\eta _k}{\eta _n}\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {2n + 1} \right)}}{ {4N - 2}}} \right]} \\ x[n] = IDS{T_8}\left[ {X[k]} \right] = \frac{2}{ {\sqrt {2N - 1} }}{\eta _k}{\eta _n}\sum\limits_{k = 0}^{N - 1} {X[k]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {2n + 1} \right)}}{ {4N - 2}}} \right]} \\ where{\text{ }}n,k = 0,1,...,N - 1. \\ \end{gathered} \tag{3-20} X[k]=DST8[x[n]]=2N1 2thekthenn=0N1x[n]sin[4N2Pi(2k+1)(2n+1)]x[n]=IDST8[X[k]]=2N1 2thekthenk=0N1X[k]sin[4N2Pi(2k+1)(2n+1)]where n,k=0,1,...,N1.(3-20)

in,

η p = { 1 2 , p = N − 1 1 , p ≠ N − {\eta_p} = \left\{{\begin{array}{l}{\frac{1}{ {\sqrt 2}},}&{p = N-1}\\{1,}&{p\ne N-1}\end{array}}\right .. thep={ 2 1,1,p=N1p=N1.

Appendix A 8 extension methods of DST

Appendix B 8 transformation formulas of DST

DST-I

X [ k ] = D S T 1 [ x [ n ] ] = 2 N + 1 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( k + 1 ) ( n + 1 ) N + 1 ] . X[k] = DS{T_1}\left[ {x[n]} \right] = \sqrt {\frac{2}{ {N + 1}}} \sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {k + 1} \right)\left( {n + 1} \right)}}{ {N + 1}}} \right]} . X[k]=DST1[x[n]]=N+12 n=0N1x[n]sin[N+1Pi(k+1)(n+1)].

DST-II

X [ k ] = D S T 2 [ x [ n ] ] = 2 N η k ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( k + 1 ) ( 2 n + 1 ) 2 N ] . X[k] = DS{T_2}\left[ {x[n]} \right] = \sqrt {\frac{2}{N}} {\eta _k}\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {k + 1} \right)\left( {2n + 1} \right)}}{ {2N}}} \right]} . X[k]=DST2[x[n]]=N2 thekn=0N1x[n]sin[2NPi(k+1)(2n+1)].

DST-III

X [ k ] = D S T 3 [ x [ n ] ] = 2 N η n ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( 2 k + 1 ) ( n + 1 ) 2 N ] . X[k] = DS{T_3}\left[ {x[n]} \right] = \sqrt {\frac{2}{N}} {\eta _n}\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {n + 1} \right)}}{ {2N}}} \right]} . X[k]=DST3[x[n]]=N2 thenn=0N1x[n]sin[2NPi(2k+1)(n+1)].

DST-IV

X [ k ] = D S T 4 [ x [ n ] ] = 2 N ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( 2 k + 1 ) ( 2 n + 1 ) 4 N ] . X[k] = DS{T_4}\left[ {x[n]} \right] = \sqrt {\frac{2}{N}} \sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {2n + 1} \right)}}{ {4N}}} \right]} . X[k]=DST4[x[n]]=N2 n=0N1x[n]sin[4NPi(2k+1)(2n+1)].

DST-V

X [ k ] = D S T 5 [ x [ n ] ] = 2 2 N + 1 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ 2 π ( k + 1 ) ( n + 1 ) 2 N + 1 ] . X[k] = DS{T_5}\left[ {x[n]} \right] = \frac{2}{ {\sqrt {2N + 1} }}\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {2\pi \left( {k + 1} \right)\left( {n + 1} \right)}}{ {2N + 1}}} \right]} . X[k]=DST5[x[n]]=2N+1 2n=0N1x[n]sin[2N+12π(k+1)(n+1)].
DST-VI

X [ k ] = D S T 6 [ x [ n ] ] = 2 2 N + 1 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( k + 1 ) ( 2 n + 1 ) 2 N + 1 ] . X[k] = DS{T_6}\left[ {x[n]} \right] = \frac{2}{ {\sqrt {2N + 1} }}\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {k + 1} \right)\left( {2n + 1} \right)}}{ {2N + 1}}} \right]} . X[k]=DST6[x[n]]=2N+1 2n=0N1x[n]sin[2N+1Pi(k+1)(2n+1)].

DST-VII

X [ k ] = D S T 7 [ x [ n ] ] = 2 2 N + 1 ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( 2 k + 1 ) ( n + 1 ) 2 N + 1 ] . X[k] = DS{T_7}\left[ {x[n]} \right] = \frac{2}{ {\sqrt {2N + 1} }}\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {n + 1} \right)}}{ {2N + 1}}} \right]} . X[k]=DST7[x[n]]=2N+1 2n=0N1x[n]sin[2N+1Pi(2k+1)(n+1)].

DST-VIII

X [ k ] = D S T 8 [ x [ n ] ] = 2 2 N − 1 η k η n ∑ n = 0 N − 1 x [ n ] sin ⁡ [ π ( 2 k + 1 ) ( 2 n + 1 ) 4 N − 2 ] . X[k] = DS{T_8}\left[ {x[n]} \right] = \frac{2}{ {\sqrt {2N - 1} }}{\eta _k}{\eta _n}\sum\limits_{n = 0}^{N - 1} {x[n]\sin \left[ {\frac{ {\pi \left( {2k + 1} \right)\left( {2n + 1} \right)}}{ {4N - 2}}} \right]} . X[k]=DST8[x[n]]=2N1 2thekthenn=0N1x[n]sin[4N2Pi(2k+1)(2n+1)].

η p = { 1 2 , p = N − 1 1 , p ≠ N − 1 , k , n , p = 0 , 1 , . . . . . . . . , N − 1. {\eta _p} = \left{{\begin{array}{c}{\frac{1}{ {\sqrt 2}},}&{p = N-1}\\{1,}&{p\ne N-1}\end{array}}\right .,{\text{ }}k,n,p = 0.1,...,N - 1. thep={ 2 1,1,p=N1p=N1, k,n,p=0,1,...,N1.

Appendix C Base images corresponding to the 8 transformations of DST

DST base image generation script

# -*- coding: utf-8 -*-
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt

def dst1_kern(N):
    x = np.zeros([N, N])
    for k in range(N):
        x[k, :] = np.sin(np.pi * (k + 1) * (np.arange(N) + 1) / (N + 1))
    x *= np.sqrt(2. / (N + 1))
    return x

def dst2_kern(N):
    x = np.zeros([N, N])
    for k in range(N):
        x[k, :] = np.sin(np.pi * (k + 1) * (2 * np.arange(N) + 1) / (2 * N))
    x[-1, :] /= np.sqrt(2)
    x *= np.sqrt(2. / N)
    return x
    
def dst3_kern(N):
    x = np.zeros([N, N])
    for k in range(N):
        x[k] = np.sin(np.pi * (2 * k + 1) * (np.arange(N) + 1) / (2 * N))
    x[:, -1] /= np.sqrt(2)
    x *= np.sqrt(2. / N)
    return x

def dst4_kern(N):
    x = np.zeros([N, N])
    for k in range(N):
        x[k] = np.sin(np.pi * (2 * k + 1) * (2 * np.arange(N) + 1) / (4 * N))
    x *= np.sqrt(2. / N)
    return x

def dst5_kern(N):
    x = np.zeros([N, N])
    for k in range(N):
        x[k] = np.sin(2 * np.pi * (k + 1) * (np.arange(N) + 1) / (2 * N + 1))
    x *= np.sqrt(4. / (2 * N + 1))
    return x

def dst6_kern(N):
    x = np.zeros([N, N])
    for k in range(N):
        x[k] = np.sin(np.pi * (k + 1) * (2 * np.arange(N) + 1) / (2 * N + 1))
    x *= np.sqrt(4. / (2 * N + 1))
    return x

def dst7_kern(N):
    x = np.zeros([N, N])
    for k in range(N):
        x[k] = np.sin(np.pi * (2 * k + 1) * (np.arange(N) + 1) / (2 * N + 1))
    x *= np.sqrt(4. / (2 * N + 1))
    return x

def dst8_kern(N):
    x = np.zeros([N, N])
    for k in range(N):
        x[k] = np.sin(np.pi * (2 * k + 1) * (2 * np.arange(N) + 1) / (4 * N - 2))
    x[:, -1] /= np.sqrt(2)
    x[-1, :] /= np.sqrt(2)
    x *= np.sqrt(4. / (2 * N - 1))
    return x

if __name__ == '__main__':
    path = 'dst_img/basis/'
    num = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII']
    
    for n in range(1, 9):
        kern = globals().get('dst{}_kern'.format(n))(8)
        '''
        把变换矩阵按行分块,记第k行的转置为ak,那么 h=[a1.T, a2.T, ..., a8.T],
        用矩阵分块的知识得到 v.dot(h) 的每一个子块是 ai.dot(aj.T),
        这样一次性就可以得到64个基图像拼起来的64x64的总图像了。
        '''
        h = kern.reshape([1, -1])
        v = h.T
        img = v.dot(h)
        
        plt.figure(figsize=(8, 8))
        plt.imshow(img, 'gray')
        plt.savefig(path+'/dst8x8_{}_all.png'.format(n), dpi='figure')
        
        imgs = []
        for i in range(8):
            for j in range(8):
                imgs.append(img[8*i:8*i+8, 8*j:8*j+8])
                #imgs.append(kern[[i], :].T.dot(kern[[j], :])) # 这种方法就是基图像一个一个地求

        imgs = np.stack(imgs)
        vmin, vmax = np.min(imgs), np.max(imgs)
        
        plt.figure(figsize=(32, 33))
        for i in range(8):
            for j in range(8):
                plt.subplot(8, 8, i*8+j+1)
                plt.imshow(imgs[i*8+j], 'gray', vmin=vmin, vmax=vmax)
                plt.axis('off')
                plt.tight_layout()
        plt.subplots_adjust(0.02, 0.02, 0.98, 0.95, 0.1, 0.1)
        plt.suptitle('DST-'+num[n-1]+' basis', fontsize=48)
        plt.savefig(path+'/dst8x8_{}.png'.format(n), dpi=32)

Guess you like

Origin blog.csdn.net/qq_33552519/article/details/124962042