【发布时间】:2017-06-02 06:03:25
【问题描述】:
我已使用 WinFilter 程序计算 C 代码上的 FIR 滤波器,但我遇到了一个问题:
程序只提供 16 位有符号数组,我需要这个向量是一个无符号整数。所以我正在寻找一个简单的解决方案来将数组值重新定位到下一个“值”。
int16_t FIRCoef[Ntap] = {
-1029,
-1560,
-1188,
0,
1405,
2186,
1718,
0,
-2210,
-3647,
-3095,
0,
5160,
10947,
15482,
17197,
15482,
10947,
5160,
0,
-3095,
-3647,
-2210,
0,
1718,
2186,
1405,
0,
-1188,
-1560,
-1029,
0
};
uint16_t fir(uint16_t NewSample) {
static uint16_t x[Ntap]; //input samples
uint32_t y=0; //output sample
int n;
//shift the old samples
for(n=Ntap-1; n>0; n--)
x[n] = x[n-1];
//Calculate the new output
x[0] = NewSample;
for(n=0; n<Ntap; n++)
y += FIRCoef[n] * x[n]; // calculo da convolucao na amostra
// Calculation of the convolution in the sample
return y / DCgain;
}
我认为一个解决方案应该是这样的:
uint16_t--------int16_t---------index
0 -32767 1
1 -32766 2
2 -32765 3
... ... ...
65535 32767 65535
有什么提示吗?
【问题讨论】:
-
-32768 怎么样,可以表示为
int16_t?那不应该是映射到0的值吗?如果“索引”值从 1 开始并运行到 65535,但对应的uint16_t值从 0 开始并运行到 65535,那么会跳过哪个uint16_t值? -
return y / DCgain;这看起来不对。我希望int32_t iy=0; ... return iy / DCgain; -
考虑“一个解决方案应该是这样的:
0...65535是偶数到奇数,-32767 ... 32767是奇数到奇数。这是映射 65,536 @ 987654331@ 转换为 65,535int16_t。有些东西不见了。 -
fir()函数对这个问题是否必不可少?我看不出它的哪个方面会影响答案的内容。 -
fir() 函数已经修复。事实上,我实际上并不需要 32 位输出值。