Monday, May 10, 2010

generate discrete cosine transform matrix in java

public class DCTMatrix
{
public static void main(String args[])
{
double dct[][] = new double[8][8];
int N = dct.length;

for(int k=0;k {
for(int n=0;n {
if(k==0)
{
dct[k][n] = 1.0/(Math.sqrt(N));
}
else if(1<=k)
{
dct[k][n] = Math.sqrt(2.0/N) * Math.cos((Math.PI*(2*n+1)*k)/(2*N));
}
}
}

for(int i=0;i {
for(int j=0;j {
System.out.print(" "+dct[i][j]);
}
System.out.println();
}
}
}

1 comment: