Contents
% simulation of 2nd order filter in state-space representation with % respect to direct form II and normal form with l2 scaling of the % system and the states % lab4_3.m * mw * 02/21/2007
2nd order system
b = [1 2 1]; a = [1 -1.4 .74]; % numerator and denominator h = filter(b,a,[1 zeros(1,100)]); % impulse response b = b / sqrt(sum(h.^2)); % l2 scaling ssr = ssr_ABCD(b,a,'DF2'); % direct form II
l2 scaling of states
T = [sqrt(6.2682) 0; 0 sqrt(6.2682)]; ssr = ssr_trans(ssr,T);
Simulation parameter
h2d = [40,-1,1,40,-1,1]; % 2d histrogram V = [1e-4 1e-3 1e-2 1e-1]; % contour lines N = 1e6; % number of simulation cycles = N + 1 rand('state',0); % return generator to its default initial state x = 2*rand(1,N)-1; % input signal (impulse) x = x*sqrt(3)/5; % crest factor 5
Filtering
s = zeros(2,length(x)+1); % state variables y = zeros(1,length(x)); % output signal for n=1:length(x) y(n) = ssr.C*s(:,n) + ssr.D*x(n); % compute output signal s(:,n+1) = ssr.A*s(:,n) + ssr.B*x(n); % update state variables end % mean and variance mean_s1 = mean(s(1,:)); var_s1 = var(s(1,:)); mean_s2 = mean(s(2,:)); var_s2 = var(s(2,:)); min1 = min(s(1,:)); max1 = max(s(1,:)); min2 = min(s(2,:)); max2 = max(s(2,:)); fprintf('lab 4.3\n') fprintf('state-space repr. - %s\n',ssr.form) fprintf('mean(s1) = %g : var(s1) = %g\n',mean_s1,var_s1) fprintf('mean(s2) = %g : var(s2) = %g\n',mean_s2,var_s2) fprintf('min(s1) = %g : max(s1) = %g\n',min1,max1) fprintf('min(s2) = %g : max(s2) = %g\n',min2,max2)
lab 4.3 state-space repr. - DF2_T mean(s1) = 0.000313257 : var(s1) = 0.0400379 mean(s2) = 0.000313182 : var(s2) = 0.0400379 min(s1) = -0.731134 : max(s1) = 0.758918 min(s2) = -0.731134 : max(s2) = 0.758918
Graphics - 2D histogram, contour lines, and scatter plot
2d histogramm
[c1,c2,f2d] = hist2D(s(1,:),s(2,:),h2d); FIG1 = figure('Name',['lab4_3 : bidim. pdf of state variables - ',ssr.form],'NumberTitle',... 'off','Units','normal','Position',[.4 .3 .45 .55]); delta1 = (h2d(3)-h2d(2))/h2d(1); delta2 =(h2d(6)-h2d(5))/h2d(4); f2d = f2d/(N*delta1*delta2); % pdf surfl(c1,c2,f2d) xlabel('s_1 \rightarrow'), ylabel('\leftarrow s_2') zlabel('f(s_1,s_2) \rightarrow') title('2D histogram of state variables') % contour lines FIG2 = figure('Name',['lab4_3 : Contour lines of bidim. pdf - ',ssr.form],... 'NumberTitle','off','Units','normal','Position',[.4 .27 .45 .55]); [CS,CH] = contour(c1,c2,f2d,V); grid % contour lines clabel(CS,CH,V); axis('square'); xlabel('s_1 \rightarrow'), ylabel('s_2 \rightarrow') title('Contour lines of 2D histogram') % scatter plot h = [100 h2d(2) h2d(3) 100 h2d(5) h2d(6)]; [c1,c2,f2d] = hist2D(s(1,:),s(2,:),h); s_sc = []; for n=1:100 for m=1:100 if f2d(n,m)>0 si = [c1(n); c2(m)]; s_sc = [s_sc si]; end end end FIG3 = figure('Name',['lab4_3 : Scatter plot of state variables - ',ssr.form],... 'NumberTitle','off','Units','normal','Position',[.4 .24 .45 .55]); plot(s_sc(1,:),s_sc(2,:),'.'),grid axis([h2d(2) h2d(3) h2d(5) h2d(6)],'square'); ylabel('s_2 \rightarrow'), xlabel('s_1 \rightarrow') title('Scatter plot of state variables')