如何在MATLAB中使用fdatool创建uint8或int16类型的定点过滤器?

时间:2018-01-06 19:06:11

标签: python matlab signal-processing

我需要将过滤器的系数设为uint8int16。我使用fdatool创建HPF。当我选择定点选项并导出系数时,它们仍然是浮点数。

另外,我如何选择系数的数量?

1 个答案:

答案 0 :(得分:0)

我不知道为什么fdatool不输出整数系数但是一旦你有浮点系数,你就可以按照documentation中描述的方法转换成所需的精度。 / p>

首先,将系数导出到MATLAB工作空间,这里我假设系数导出为变量b

int16

signed = true;
B = 16; % Number of bits

bq = fi(b, signed, B);
L = bq.FractionLength;
bsc = b*2^L;

h = dfilt.dffir(bsc);
h.Arithmetic = 'fixed';
h.CoeffWordLength = B;
h.signed = signed;

% check results
all(h.Numerator == int16(h.Numerator))
fvtool(h);

uint8

signed = false;
B = 8; % Number of bits

bq = fi(b, signed, B);
L = bq.FractionLength;
bsc = b*2^L;

h = dfilt.dffir(bsc);
h.Arithmetic = 'fixed';
h.CoeffWordLength = B;
h.signed = signed;

% check results
all(h.Numerator == uint8(h.Numerator))
fvtool(h);

定点系数存储在h.Numerator

要选择系数的数量,请设置"过滤顺序" fdatool中的选项,如下图所示。系数的数量等于1加上滤波器顺序。

enter image description here