FFT程序
static private int BitReverse(int j)
{
int j2;
int j1 = j;
int k = 0;
for (int i = 1; i <= nu; i++)
{
j2 = j1 / 2;
k = 2 * k + j1 - 2 * j2;
j1 = j2;
}
return k;
}
static public double[] FFTDb(ref double[] x)
{
// Assume n is a power of 2
n = x.Length;
nu = (int)(Math.Log(n) / Math.Log(2));
int n2 = n / 2;
int nu1 = nu - 1;
double[] xre = new double[n];
double[] xim = new double[n];
double[] decibel = new double[n2];
double tr, ti, p, arg, c, s;
for (int i = 0; i < n; i++)
{
xre = 0.0f;
xim = x;
}
int k = 0;
for (int l = 1; l <= nu; l++)
{
while (k < n)
{
for (int i = 1; i <= n2; i++)
{
p = BitReverse(k >> nu1);
arg = 2 * (double)Math.PI * p / n;
c = (double)Math.Cos(arg);
s = (double)Math.Sin(arg);
tr = xre[k + n2] * c + xim[k + n2] * s;
ti = xim[k + n2] * c - xre[k + n2] * s;
xre[k + n2] = xre[k] - tr;
xim[k + n2] = xim[k] - ti;
xre[k] += tr;
xim[k] += ti;
k++;
}
k += n2;
}
k = 0;
nu1--;
n2 = n2 / 2;
}
k = 0;
int r;
while (k < n)
{
r = BitReverse(k);
if (r > k)
{
tr = xre[k];
ti = xim[k];
xre[k] = xre[r];
xim[k] = xim[r];
xre[r] = tr;
xim[r] = ti;
}
k++;
}
采频方程:
static public double[] xAx(ref double[] x)
{
n = x.Length;
double[] myX = new double[n/2];
for (int i = 0; i < (n/2); i++)
myX =(double)i* 44100 / n;
不懂C#,我感觉这句代码有问题,不知道对不对。
for (int i = 0; i < (n/2); i++)
myX =(double)i* 44100 / n;
myX是个数组,好像应该这样赋值:
for (int i = 0; i < (n/2); i++)
myX [ i ]=(double)i* 44100 / n;
static private int n;
static public double[] xAx(ref double[] x)
{
n = x.Length;
double[] myX = new double[n/2];
for (int i = 0; i < (n/2); i++)
myX [ i ] = (double)i * 44100 / n ;
return myX;
}
and i think there must be another mistake or something, should be thought about. But now i dont know. By the way i am in oversee and cant write chinese now, sorry,but thx your answer.