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;
}
weixin_42138713
发布了7 篇原创文章 · 获赞 0 · 访问量 117
私信
关注