Contents

% simulation of 2nd order filter in state-space representation
% in minimum round-off noise form
% lab6_2.m * mw * 03/10/2007

2nd order system

b = [1 2 1]; a = [1 -1.4 .74]; % numerator and denominator
ssr = ssr_mron(b,a);           % state-space representation

Simulation parameter

N = 1e6;                 % number of simulation cycles = N + 1
w = 8;                  % word length
rand('state',0);
x = 2*rand(1,N)-1;       % input signal
x = x*sqrt(3)/5;         % crest factor 5
% x=[1 zeros(1,100)];    % impulse
xq = quant2c(x,w,'r');   % quantization (rounding)

Filtering and analysis

[y,S]      = ssr_filter(ssr,xq);     % ideal filter
[yq,Sq,OC] = ssr_filter2c(ssr,xq,w); % quantized filter (rounding)
fprintf('lab6_2 (%s)\n',ssr.form)
fprintf('Wordlength : %g bit\n',w)
fprintf('Overflow counter : %g\n',OC)
Ni = var(y-yq); % variance of inner noise
fprintf('Variance %g dB\n',10*log10(Ni))
FIG = figure('Name',['lab6_2 : Output signal (',ssr.form,')'],...
  'NumberTitle','off','Units','normal','Position',[.3 .3 .65 .55]);
plot(0:200,y(1:201),':',0:200,y(1:201),'+',0:200,yq(1:201),'o'), grid
axis([0 200 -.6 .6]);
xlabel('n \rightarrow'), ylabel('y[n], y_q[n] \rightarrow')
legend('MATLAB','MATLAB',['quantized, w = ',num2str(w),' bit'],'Location','Best')
title(['Output signal (',ssr.form,')'])
lab6_2 (MNF)
Wordlength : 8 bit
Overflow counter : 0
Variance -46.3756 dB