Thursday, May 31, 2012

ANALYSIS OF FINITE WORD-LENGTH EFFECTS


ANALYSIS OF FINITE WORD-LENGTH EFFECTS

ANALYSIS OF FINITE WORD-LENGTH EFFECTS

The MATLAB function a2dR given below can be used to generate the decimal equivalent of the binary representation in sign-magnitude form of a decimal number with a specified number of bits for the fractional part obtained by rounding.

function beq = a2dR(d,n)
% BEQ = A2DR(D, N) generates the decimal
% equivalent beq of the binary representation
% of a decimal number D with N bits for the
% magnitude part obtained by rounding
%
m = 1; d1 = abs(d);
while fix(d1) > 0
d1 = abs(d)/(10^m);
m = m+1;
end
beq = 0;d1 = d1 + 2^(-n-1);
for k = 1:n
beq = fix(d1*2)/(2^k) + beq;
d1 = (d1*2) - fix(d1*2);
end
beq = sign(d).*beq.*10^(m-1);

To compare the performance of the direct-form realization of an IIR transfer
function with that of a cascade realization with both realized with quantized coefficients.
Program P9 2 evaluates the effect of multiplier coefficient quantizations on the cascade
form realization

% Program
% Coefficient Quantization Effects on Cascade
% Realization of an IIR Transfer Function
clf;
[z,p,k] = ellip(6,0.05,60,0.4);
[b,a] = zp2tf(z,p,k);
[g,w] = gain(b,a);
sos = zp2sos(z,p,k);
sosq = a2dT(sos,6);
R1 = sosq(1,:);R2 = sosq(2,:);R3 = sosq(3,:);
b1 = conv(R1(1:3),R2(1:3));bq = conv(R3(1:3),b1);
a1 = conv(R1(4:6),R2(4:6));aq = conv(R3(4:6),a1);
[gq,w] = gain(bq,aq);
plot(w/pi,g,’b’, w/pi,gq,’r--’);
axis([0 1 -80 1]);grid
xlabel(’\omega /\pi’);ylabel(’Gain, dB’);
title(’original - solid line; quantized - dashed line’);
pause
zplane(b,a);
hold on;
pzplot(bq,aq);
title(’Original pole-zero locations: x, o; New pole-zero locations: +, *’)

The above two programs can be modified easily to investigate the multiplier coefficient
effects on an FIR transfer function, as illustrated by Program P9 3 given below for the
direct-form realization.

% Program
% Coefficient Quantization Effects on Direct Form
% Realization of an FIR Transfer Function
%
clf;
f = [0 0.4 0.45 1];
m = [1 1 0 0];
b = firpm(19, f, m);
[g,w] = gain(b,1);
bq = a2dT(b,5);
[gq,w] = gain(bq, 1);
plot(w/pi,g,’b-’,w/pi,gq,’r--’);
\axis([0 1 -60 10]);grid
xlabel(’\omega /\pi’); ylabel(’Gain, dB’);
legend(’original’, ’quantized’);
pause zplane(b);
hold on
pzplot(bq);
hold off
title(’Original pole-zero locations: x, o; New pole-zero locations: +, *’)

to investigate the propagation of input quantization-noise to the output of a causal, stable LTI digital filter, the function noisepwr1 given below can be employed

function nvar = noisepwr1(num,den)
% Computes the output noise variance due
% to input quantization of a digital filter
% based on a partial-fraction approach
%
% num and den are the numerator and denominator
% polynomial coefficients of the IIR transfer function
%
[r,p,K] = residue(num,den);
R = size(r,1);
R2 = size(K,1);
if R2 > 1
disp(’Cannot continue...’);
return;
end
if R2 == 1
nvar = K^2;
else
nvar = 0;
end
% Compute roundoff noise variance
for k = 1:R,
for m = 1:R,
integral = r(k)*conj(r(m))/(1-p(k)*conj(p(m)));
nvar = nvar + integral;
end
end
disp(’Output Noise Variance = ’);disp(real(nvar))}

No comments:

Post a Comment