sum will temporarily store the sum of cosine signals
sum = 0 ; for ( k = 0 ; k < m ; k ++ ) { for ( l = 0 ; l < n ; l ++ ) { dct1 = matrix [ k , l ] * Math . Cos ( ( 2 * k + 1 ) * i * pi / ( 2 * m ) ) * Math . Cos ( ( 2 * l + 1 ) * j * pi / ( 2 * n ) ) ; sum = sum + dct1 ; } } dct [ i , j ] = ci * cj * sum ; } } for ( i = 0 ; i < m ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { Console . Write ( dct [ i , j ] ) ; } Console . WriteLine ( ) ; } }