Java,Android 离散余弦变换 DCT

public double[] DCT(int direction, int length, double[] X)
{
    if (direction == 1 || direction == -1)
    {
        X=Discrete_Cosine_Transform(direction, length, X);

    }
    return X;
}

public double[] Discrete_Cosine_Transform(int direction, int length, double[] X)
{


    double[] x = new double[length];

    for (int i = 0; i < length; i++)
    {
        x[i] = X[i];
    }
    for (int k = 0; k < length; k++)
    {
        double sum = 0;

        if (direction == 1)
        {
            for (int n = 0; n < length; n++)
            {
                sum += ((k == 0) ? (Math.sqrt(0.5)) : (1)) * x[n] * Math.cos(pi * (n + 0.5) * k / length);
            }
        }
        else if (direction == -1)
        {
            for (int n = 0; n < length; n++)
            {
                sum += ((n == 0) ? (Math.sqrt(0.5)) : (1)) * x[n] * Math.cos(pi * n * (k + 0.5) / length);
            }
        }
        X[k] = sum * Math.sqrt(2.0 / length);
    }
    return X;
}
Java,Android 离散余弦变换 DCTJava,Android 离散余弦变换 DCT weixin_42138713 发布了7 篇原创文章 · 获赞 0 · 访问量 117 私信 关注
上一篇:基于vue2.0+weex开发app 之中遇到的问题(爬坑之旅)


下一篇:【MATLAB编程实例练习】-(8)迷路的牛牛