02.10.2019 Views

UploadFile_6417

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

568 Chapter 10 ROUND-OFF EFFECTS IN DIGITAL FILTERS<br />

close all; clc;<br />

% Example Parameters<br />

B = 6;<br />

% # of fractional bits<br />

N = 100000;<br />

% # of samples<br />

xn = (2*rand(1,N)-1); % Input sequence - Uniform Distribution<br />

a = 0.9;<br />

% Filter parameter<br />

Xm = 1-abs(a); % Scaling factor<br />

% Local variables<br />

bM = 7; DbM = 2^bM; % bin parameter<br />

BB = 2^B;<br />

% useful factor in quantization<br />

M = round(DbM/2); % Half number of bins<br />

bins = [-M+0.5:1:M-0.5]; % Bin values from -M to M<br />

Q = bins/DbM; % Normalized bins<br />

YTN = 2^(-bM);<br />

% Ytick marks interval<br />

YLM = 4*YTN;<br />

% Yaxis limit<br />

% Quantize the input and the filter coefficients<br />

xn = QFix(Xm*xn,B,’round’,’satur’); % Scaled Input quant to B bits<br />

a = QFix(a,B,’round’,’satur’); % a quantized to B bits<br />

% Filter output without multiplication quantization<br />

yn = filter(1,[1,-a],xn); % output using filter routine<br />

% Filter output with multiplication quantization<br />

yq = zeros(1,N);<br />

% Initialize quantized output array<br />

yq(1) = xn(1);<br />

% Calculation of the first sample yq(1)<br />

for I = 2:N;<br />

A1Y = QFix(a*yq(I-1),B,’round’,’satur’); % Quantization of a*y(n-1)<br />

yq(I) = QFix(A1Y+xn(I),B,’round’,’satur’); % I-th sample yq(I)<br />

end<br />

% Output Error Analysis<br />

en = yn-yq;<br />

% Output error sequence<br />

varyn = var(yn); varen = var(en); % Signal and noise power<br />

eemax = max(en); eemin = min(en); % Maximum and minimum of the error<br />

enmax = max(abs([eemax,eemin])); % Absolute maximum range of the error<br />

enavg = mean(en); enstd = std(en); % Mean and std dev of the error<br />

en = round(en*(2^bM)/(2*enmax)+0.5); % Normalized en (integer between -M & M)<br />

en = sort([en,-M:1:(M+1)]); %<br />

H = diff(find(diff(en)))-1; % Error histogram<br />

H = H/N;<br />

% Normalized histogram<br />

Hmax = max(H); Hmin = min(H);<br />

% Max and Min of the normalized histogram<br />

% Output SNRs<br />

SNR_C = 10*log10(varyn/varen); % Computed SNR<br />

SNR_T = 6.02 + 6.02*B + 20*log10(Xm); % Theoretical SNR<br />

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).<br />

Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!