10.3 ROUND-OFF EFFECTS IN FIR DIGITAL FILTERS
10.3.2 ANALYSIS USING MATLAB This simulation in MATLAB can be done in parallel fashion since there
Only the final sum will be quantized and saturated. In the case of one quantizer, we need the’satur’mode. These simulation steps are detailed in the following example.
EXAMPLE 10.13 Let a fourth-order (M = 5) FIR filter be given by
H(z) = 0.1 + 0.2z−1+ 0.4z−2+ 0.2z−3+ 0.1z−4 (10.89) which is implemented as a direct form with B = 12 fractional bit quantiz- ers. Compute SNRs for models in Figure 10.26b and c and verify them using MATLAB simulations.
Solution We will need the quantities
|h(n)|2and (
|h(n)|)2. These quantities should be computed using 12-bit quantization of the filter coefficients. These values using the quantized numbers are
|h(n)|2= 0.2599 and (
|h(n)|)2 = 1. Using (10.88), the output SNR is 65.42 dB for 5 multipliers and is 72.41 dB for 1 multiplier. The following MATLAB script evaluates these and other quantities.
% Example Parameters
B = 12; % # of fractional bits
N = 100000; % # of samples
xn = (2*rand(1,N)-1); % Input sequence - Uniform Distribution h = [0.1,0.2,0.4,0.2,0.1]; % Filter parameters
M = length(h);
% Local variables
bM = 7; DbM = 2^bM; % bin parameter
BB = 2^B; % useful factor in quantization K = round(DbM/2); % Half number of bins
bins = [-K+0.5:1:K-0.5]; % Bin values from -K to K Q = bins/DbM; % Normalized bins
YTN = 2^(-bM); % Ytick marks interval YLM = 4*YTN; % Yaxis limit
% Quantize the input and the filter coefficients h = QFix(h,B,’round’,’satur’); % h quantized to B bits Xm = 1/sum(abs(h)); % Scaling factor
xn = QFix(Xm*xn,B,’round’,’satur’);% Scaled Input quant to B bits
% Filter output without multiplication quantization yn = filter(h,1,xn); % output using filter routine
% Filter output with multi quant (5 multipliers)
x1 = [zeros(1,1),xn(1:N-1)]; x2 = [zeros(1,2),xn(1:N-2)];
x3 = [zeros(1,3),xn(1:N-3)]; x4 = [zeros(1,4),xn(1:N-4)];
h0x0 = QFix(h(1)*xn,B,’round’,’twosc’);
h1x1 = QFix(h(2)*x1,B,’round’,’twosc’);
h2x2 = QFix(h(3)*x2,B,’round’,’twosc’);
h3x3 = QFix(h(4)*x3,B,’round’,’twosc’);
h4x4 = QFix(h(5)*x4,B,’round’,’twosc’);
yq = h0x0+h1x1+h2x2+h3x3+h4x4;
yq = QFix(yq,B,’round’,’satur’);
% Output Error Analysis
qn = yn-yq; % Outout error sequence
varyn = var(yn); varqn = var(qn); % Signal and noise power
qqmax = max(qn); qqmin = min(qn); % Maximun and minimum of the error qnmax = max(abs([qqmax,qqmin])); % Absolute maximum range of the error qnavg = mean(qn); qnstd = std(qn); % Mean and std dev of the error
qn = round(qn*(2^bM)/(2*qnmax)+0.5); % Normalized en (interger between -K & K) qn = sort([qn,-K:1:(K+1)]); %
H = diff(find(diff(qn)))-1; % Error histogram
H = H/N; % Normalized histogram
Hmax = max(H); Hmin = min(H); % Max and Min of the normalized histogram
% Output SNRs
SNR_C = 10*log10(varyn/varqn); % Computed SNR
SNR_T = 6.02 + 6.02*B + 10*log10(sum(h.*h)/Xm^2) - 10*log10(M); % Theoretical SNR
% Filter output with multi quant (1 multiplier) yq = QFix(yn,B,’round’,’satur’);
% Output Error Analysis
qn = yn-yq; % Outout error sequence
varyn = var(yn); varqn = var(qn); % Signal and noise power
qqmax = max(qn); qqmin = min(qn); % Maximun and minimum of the error qnmax = max(abs([qqmax,qqmin])); % Absolute maximum range of the error qnavg = mean(qn); qnstd = std(qn); % Mean and std dev of the error
qn = round(qn*(2^bM)/(2*qnmax)+0.5); % Normalized en (interger between -K & K) qn = sort([qn,-K:1:(K+1)]); %
H = diff(find(diff(qn)))-1; % Error histogram
H = H/N; % Normalized histogram
Hmax = max(H); Hmin = min(H); % Max and Min of the normalized histogram
% Output SNRs
SNR_C = 10*log10(varyn/varqn); % Computed SNR
SNR_T = 6.02 + 6.02*B + 10*log10(sum(h.*h)/Xm^2); % Theoretical SNR
The computed and theoretical SNRs as well as output error histograms for the two models are shown in Figure 10.27. The top plot shows the histogram when five multipliers are used. The output error has Gaussian-like distribution with SNR equal to 65.42 dB, which agrees with the theoretical value. The bottom plot show the histogram when one multiplier is used. As expected, the error is uniformly distributed with SNR equal to 72.43 dB, which also agrees with the
theoretical one.
Cascade-form realization Let the filter be realized by a cascade of K, 2nd-order (M = 3) sections given by
H(z) = K i=1
Hi(z) whereHi(z) =β0i+β1iz−1+β2iz−2 (10.90) as shown in Figure 10.28. The overall length of the filter is M = 2K+ 1.
Figure 10.28 also shows the finite word-length model for the cascade form,
0 0.1 0.2 0.3 0.4 0.5 0.0078
0 0.0156 0.0234 0.0313
Five Multipliers SAMPLE SIZE N = 100000
FILT LENGTH M = 5 SNR(THEORY) = 65.4187
ROUNDED TO B = 12 BITS ERROR MEAN = 1.9514e–007 SNR(COMPUTED) = 65.4241
0 0.1 0.2 0.3 0.4 0.5
0 0.0078 0.0156 0.0234 0.0313
One Multiplier SAMPLE SIZE N = 100000
FILT LENGTH M = 5 SNR(THEORY) = 72.4084
ROUNDED TO B = 12 BITS ERROR MEAN = 1.9514e–007 SNR(COMPUTED) = 72.4324
−0.5 −0.4 −0.3 −0.2 −0.1
−0.5 −0.4 −0.3 −0.2 −0.1
Distribution of Output ErrorDistribution of Output Error
Normalized Error
FIGURE 10.27 Multiplication quantization effects for the direct-form FIR filter in Example 10.13
in which quantization noise sources, ei(n) 1 ≤i ≤ K, at each section’s output are incorporated. Let y(n) be the output due to input x(n), and let q(n) be the output due to all noise sources. We make the following reasonable assumptions:
1. The sections are implemented using the MAC (multiply-accumulate) architecture so that there is only one independent noise source in each section that contributes toei(n). The other possibility of three multi- pliers in each section is straightforward.
x(n) H1(z) H2(z) HK(z)
e1(n) e2(n) eK−1(n) eK(n)
y(n) = y(n) + q(n)ˆ
FIGURE 10.28 Cascade form FIR filter structure with noise sources inserted for multiplication quantization
2. The noise sources are independent of each other—that is, ei(n)⊥ej(n) fori=j
3. Each noise source is a white noise source withσe2i = 2−2B/12.
We will now consider the issues of round-off noise and scaling (to prevent overflow) for the cascade-form realization.
Round-off noise Let the noise impulse response at the output from theei(n) node be denoted bygi(n). Then the length ofgi(n) is equal to (M −2i). Let qi(n) be the output noise due toei(n). Then its power is given by
σq2i =σe2i
M−2i 0
|gi(n)|2= 2−2B 12
M−2i 0
|gi(n)|2 (10.91) Sinceq(n) =K
i=1qi(n) we obtain the total noise power as σq2=
K i=1
σq2i= 2−2B 12
K
i=1 M−2i
n=1
|gi(n)|2
(10.92) The expressionK
i=1
M−2i
n=1 |gi(n)|2shows that the error power depends on the order of the cascade connections. It has been shown that for the majority of the orderings the noise power is approximately the same.
Scaling to prevent overflow From Figure 10.28 we note that one must prevent overflow at each node. Let hk(n) be the impulse response at each nodek; then we need a scaling constantXmax as
Xmax= 1 maxk
|hk(n)|
so that |y(n)| ≤ 1. Clearly, this is a very conservative value. A better approach is to scale the impulse responses of every section {hi(n)} so that
|hi|= 1 for each i. Hence the output of every section is limited between−1 and +1 if the inputx(n) is distributed over the same interval.
Assuming that x(n) is uniformly distributed over [−1,+1] and is white, the output signal power is
σy2=σ2x
M−1
0
|h(n)|2=1 3
M−1
0
|h(n)|2 (10.93) where h(n) is the overall impulse response of the filter. Let ˆgi be the corresponding scaled impulse responses in (10.92). Now the output SNR can be computed as
SNR = σ2y
σ2q = 22(B+1)
M−1 0 |h(n)|2 K
i=1
M−2i
n=1 |gˆi(n)|2 (10.94)
or
SNRdB= 6.02(B+1)+10 log10 M−1
0
|h(n)|2
−10 log10 K
i=1 M−2i
n=1
|ˆgi(n)|2
(10.95)
10.3.3 ANALYSIS USING MATLAB