filter2_fixed.m

来自「MATLAB code for signal filtering with fi」· M 代码 · 共 52 行

M
52
字号
function ques2_fixed;
INPUT       = [-0.234, 0.5432,0.223];
X           = zeros(1,3);
Y           = zeros(1,3);
A           = [1, 0.5, 0.25];
B           = [0, 0.25, 0.125];
fixed    = zeros(1,3);

% pass 2 - creating quantizer objects
a=quantizer('fixed','round','saturate',[16 14]);
b=quantizer('fixed','round','saturate',[16 14]);
c=quantizer('fixed','round','saturate',[16 14]);
d=quantizer('fixed','round','saturate',[16 14]);
e=quantizer('fixed','round','saturate',[16 14]);
f=quantizer('fixed','round','saturate',[16 14]);
g=quantizer('fixed','round','saturate',[16 14]);
h=quantizer('fixed','round','saturate',[16 14]);
i=quantizer('fixed','round','saturate',[16 14]);
j=quantizer('fixed','round','saturate',[16 14]);
k=quantizer('fixed','round','saturate',[16 14]);
l=quantizer('fixed','round','saturate',[16 14]);
m=quantizer('fixed','round','saturate',[16 14]);
n=quantizer('fixed','round','saturate',[16 14]);

% pass 2 - using the quantize objects to convert to Q2.14 format
input   = quantize(a,INPUT);
x       = quantize(b,X);
y       = quantize(c,Y);
a       = quantize(d,A);
b       = quantize(e,B);

% pass 1 - levelization has been done inside the for loop
% scalarization hadn't been required. the code was already in that format
for(counter = 1:1:3)
    x(3)    =   x(2);
    x(2)    =   x(1);
    x(1)    =   input(counter);
    y(3)    =   y(2);
    y(2)    =   y(1);
    temp1   = quantize(f,y(2)*b(2));
    temp2   = quantize(g,y(3)*b(3));
    tempA   = quantize(h,temp1 + temp2);
    temp3   = quantize(i,x(1)*a(1));
    tempB   = quantize(j,temp3 - tempA);
    temp4   = quantize(k,x(2)*a(2));
    tempC   = quantize(l,tempB + temp4);    
    temp5   = quantize(m,x(3)*a(3));
    y(1)    = quantize(n,tempC + temp5);   
    fixed(counter)   = y(1);
end
fixed
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?