These are the sin and cosine transforms as defined by Charles Van Loan (1992) in Computational frameworks for the fast Fourier transform published by SIAM. See page 229. Some other authors use slightly different conventions. All the functions call the fast Fourier transforms and require an even transform length, denoted by m in these notes. As with the FFT m should be the product of numbers less than about 10 for fast execution.
The functions I define are
DCT(U,V); // U, V are ColumnVectors, length m+1 DCT_inverse(U,V); // inverse of DCT DST(U,V); // U, V are ColumnVectors, length m+1 DST_inverse(U,V); // inverse of DST DCT_II(U,V); // U, V are ColumnVectors, length m DCT_II_inverse(U,V); // inverse of DCT_II DST_II(U,V); // U, V are ColumnVectors, length m DST_II_inverse(U,V); // inverse of DST_IIwhere U is the input and V is the output. V = U is OK. The length of V is set by the functions.
Here are the formulae:
m-1 k v[k] = u[0]/2 + SUM { u[j] cos (pi jk/m) } + (-) u[m]/2 j=1for k = 0...m, where u[j] and v[k] are stored in U(j+1) and V(k+1).
m-1 v[k] = SUM { u[j] sin (pi jk/m) } j=1for k = 1...(m-1), where u[j] and v[k] are stored in U(j+1) and V(k+1). u[0] and u[m] are ignored and v[0] and v[m] are set to zero.
m-1 v[k] = SUM { u[j] cos (pi (j+1/2)k/m) } j=0for k = 0...(m-1), where u[j] and v[k] are stored in U(j+1) and V(k+1).
m v[k] = SUM { u[j] sin (pi (j-1/2)k/m) } j=1for k = 1...m, where u[j] and v[k] are stored in U(j) and V(k).
Note that the relationship between the subscripts in the formulae and those used in newmat is different for DST_II (and DST_II_inverse).