experiments

All kinds of coding experiments
Log | Files | Refs | Submodules

DCT.java (842B)


      1 public class DCT {
      2     private int M;
      3     Matrix A;   // transformation matrix
      4     Matrix AT;   // transported
      5 
      6     public DCT(int blockSize){
      7         this.M = blockSize;
      8         this.A = new Matrix(blockSize);
      9         this.generateTransformMatrix();
     10         this.AT = this.A.getTransposed();
     11     }
     12 
     13     public void generateTransformMatrix(){
     14         for (int c = 0; c < M; c++){
     15             A.set(0, c, Math.sqrt(1.0/M) );
     16         }
     17         double a = Math.sqrt(2.0/M);
     18         for (int r = 1; r < M; r++){
     19             for (int c = 0; c < M; c++) {
     20                 A.set(r, c, a*Math.cos( (2*c + 1) * r*Math.PI / (2 * M)) );
     21             }
     22         }
     23     }
     24 
     25     public Matrix transform(Matrix x){
     26         return this.A.multiply(x).multiply(this.AT);
     27     }
     28 
     29     @Override
     30     public String toString(){
     31         return this.A.toString();
     32     }
     33 }