Digital Signal Processing Reference
In-Depth Information
%% Indicate overflow
fprintf( '\nOverflow counter = %g\n' ,OC)
% Search for limit cycle
start = 0; period = 0; CYCLE = 'false' ;
for n = N-1:-1:1
if s(:,N) == s(:,n)
start = n; period = N-n;
LIMCYC = 'true' ;
% limit cycle discovered
break
end
end
if LIMCYC
fprintf( 'Limit cycle detected\n' )
fprintf( ' Start %4i\n Period %4i\n' ,start,period)
fprintf( ' Minimum %4i*LSB\n Maximum %4i*LSB\n' ,...
min(s(1,start:start+period)/LSB),max(s(1,start:start+period)/LSB))
else
fprintf( 'No limit cycle detected\n' )
end
%% Graphics
FIG1 = figure( 'Name' , 'dsplab18_1 : 2nd order block with quantized
arithmetic' ,...
'NumberTitle' , 'off' , 'Units' , 'normal' , 'Position' ,[.30 .30 .55 .55]);
subplot(2,1,1), plot(0:N-1,y/LSB, 'o' ,0:N-1,yref/LSB, 'x' ); grid
xlabel( '{\itn} \rightarrow' ); ylabel( '{\ity}[{\itn}] / LSB
\rightarrow' )
if LIMCYC % limit cycle detected
n1 = start; n2 = start + period;
subplot(2,1,2), plot(s(1,n1:n2)/LSB,s(2,n1:n2)/LSB, 'ro' ,...
s(1,n1:n2)/LSB,s(2,n1:n2)/LSB, 'b' )
grid; title([ 'limit cycle with periode ' ,num2str(period)]);
xlabel( '{\its}_1[{\itn}] / LSB \rightarrow' )
ylabel( '{\its}_2[{\itn}] / LSB \rightarrow' )
end
Programmbeispiel 18-2 System 2. Ordnung mit Arithmetik im Zweierkomplement-Format
function [y,s,OC] = filt2_rc(b,a,x,si,w)
% 2nd order block for IIR filter with quantization by
% rounding and two's-complement overflow mode
% - signals and filter coefficients in two's-complement format
% [y,s,OC] = filt2_rc(b,a,x,si,w)
% b : numerator coefficients [b0 b1 b2]
% a : denominator coefficients [1 a1 a2]
% x : input sequence
% si : initial values for state space variables [s1 s2]
% w : word length
% y : output sequence
% s : sequences of state space variables
% s(1,:) = s1[n] and s(2,:) = s2[n]
% OC : overflow counter
% filt2_rc.m * mw * 15Apr2011
LSB = 2^(-w+1); % least significant bit
% Memory allocations
N = length(x); s = zeros(2,N+1); y = zeros(1,N); OC = 0;
Search WWH ::




Custom Search