振幅总出现在采用频点的右侧(大于采频)FFT
大家好,我在做一个声音采样分析,目前做好了一个程序包(C#),有三部分: 声音采样,FFT分析,以及坐标图。现在出现了问题,我把信号发生器频率调到1000Hz,但在正弦波下,其峰值出现在2700Hz处,我调了几个频率值,出现的峰值均是采样频率的2.7倍。这是什么问题呢?我觉得这个问题不属于修正范围内的。
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;
double[] xim = new double;
double[] decibel = new double;
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 * c + xim * s;
ti = xim * c - xre * s;
xre = xre - tr;
xim = xim - ti;
xre += tr;
xim += 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;
ti = xim;
xre = xre;
xim = xim;
xre = tr;
xim = ti;
}
k++;
}
采频方程:
static public double[] xAx(ref double[] x)
{
n = x.Length;
double[] myX = new double;
for (int i = 0; i < (n/2); i++)
myX =(double)i* 44100 / n;
return myX;
}
请高手指点,多谢。 不懂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;
[ 本帖最后由 erdgzw 于 2008-4-23 10:05 编辑 ] hi erdgzw,
you are right, actualy my code is :
static private int n;
static public double[] xAx(ref double[] x)
{
n = x.Length;
double[] myX = new double;
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 thxyour answer.
best regards
sam
[ 本帖最后由 samdhy 于 2008-4-23 15:33 编辑 ]
页:
[1]