コード例 #1
0
	public DctComirva(int rows, int columns)
	{
		this.rows = rows;
		this.columns = columns;
		
		// Compute the DCT
		// This whole section is copied from GetDCTMatrix() from CoMirva package
		dctMatrix = new Matrix(rows, columns);
		
		// Compute constants for DCT
		// http://unix4lyfe.org/dct/
		double k1 = Math.PI/columns;
		double w1 = 1.0/(Math.Sqrt(columns));
		double w2 = Math.Sqrt(2.0/columns);

		// Generate 1D DCT-II matrix
		for(int i = 0; i < rows; i++) {
			for(int j = 0; j < columns; j++) {
				if(i == 0)
					dctMatrix.Set(i, j, w1 * Math.Cos(k1*i*(j + 0.5d)));
				else
					dctMatrix.Set(i, j, w2 * Math.Cos(k1*i*(j + 0.5d)));
			}
		}
	}
コード例 #2
0
ファイル: MFCC.cs プロジェクト: Bruhankovi4/Emotyper
		/// <summary>
		/// Generates the DCT matrix for the known number of filters (input vector) and
		/// for the known number of used coefficients (output vector). Therfore the
		/// DCT matrix has the dimensions (numberCoefficients x numberFilters).
		/// If useFirstCoefficient is set to false the matrix dimensions are
		/// (numberCoefficients-1 x numberFilters). This matrix is a submatrix of the
		/// full matrix. Only the frist row is missing.
		/// </summary>
		/// <returns>Matrix the appropriate DCT matrix</returns>
		public Matrix GetDCTMatrix()
		{
			//compute constants
			double k = Math.PI/numberFilters;
			double w1 = 1.0/(Math.Sqrt(numberFilters));
			double w2 = Math.Sqrt(2.0/numberFilters);

			//create new matrix
			Matrix matrix = new Matrix(numberCoefficients, numberFilters);

			//generate dct matrix
			for(int i = 0; i < numberCoefficients; i++)
			{
				for(int j = 0; j < numberFilters; j++)
				{
					if(i == 0)
						matrix.Set(i, j, w1 * Math.Cos(k*i*(j + 0.5d)));
					else
						matrix.Set(i, j, w2 * Math.Cos(k*i*(j + 0.5d)));
				}
			}

			//adjust index if we are using first coefficient
			if(!useFirstCoefficient)
				matrix = matrix.GetMatrix(1, numberCoefficients-1, 0, numberFilters-1);

			return matrix;
		}