Contents

% cauer lowpass with 2nd order sections
% lab7_1.m * mw * 03/12/2007

Zero-pole plot

load cauer
[b,a] = sos2tf(SOS,G);
FIG1 = figure('Name','lab7_1 : Zero-pole plot ','NumberTitle',...
  'off','Units','normal','Position',[.3 .3 .55 .55]);
zplane(b,a)
title('Zero-pole plot')

Scaling of 2nd order sections with respect to the frequency response

H1 = abs(freqz(SOS(1,1:3),SOS(1,4:6),1024));
M1 = max(H1);
H1 = H1 / M1;
H2 = abs(freqz(SOS(2,1:3),SOS(2,4:6),1024));
M2 = max(H1.*H2);
H2 = H2 / M2;
H3 = abs(freqz(SOS(3,1:3),SOS(3,4:6),1024));
M3 = max(H1.*H2.*H3);
H3 = H3 / M3;
H  = H1.*H2.*H3;
SOS(1,1:3) = SOS(1,1:3)/M1; % scaling
SOS(2,1:3) = SOS(2,1:3)/M2; % scaling
SOS(3,1:3) = SOS(3,1:3)/M3; % scaling
G(1) = G(1)*M1*M2*M3;       % scaling

Graphics - Frequency response after scaling of 2nd order sections

FIG2 = figure('Name','lab7_1 : Frequency response : cascade form after scaling ','NumberTitle',...
  'off','Units','normal','Position',[.3 .27 .55 .55]);
f = 0:1023; f = f/1024;
subplot(4,2,1), plot(f,H1), grid
xlabel('\Omega / \pi \rightarrow'), ylabel('|H_1(e^{j\Omega})| \rightarrow')
axis([0 1 0 5]);
subplot(4,2,2), plot(f,20*log10(H1)), grid
xlabel('\Omega / \pi \rightarrow'), ylabel('|H_1(e^{j\Omega})| \rightarrow')
axis([0 1 -100 20]);
subplot(4,2,3), plot(f,H2), grid
xlabel('\Omega / \pi \rightarrow'), ylabel('|H_2(e^{j\Omega})| \rightarrow')
axis([0 1 0 5]);
subplot(4,2,4), plot(f,20*log10(H2)), grid
xlabel('\Omega / \pi \rightarrow'), ylabel('|H_2(e^{j\Omega})| \rightarrow')
axis([0 1 -100 20]);
subplot(4,2,5), plot(f,H3), grid
xlabel('\Omega / \pi \rightarrow'), ylabel('|H_3(e^{j\Omega})| \rightarrow')
axis([0 1 0 5]);
subplot(4,2,6), plot(f,20*log10(H3)), grid
xlabel('\Omega / \pi \rightarrow'), ylabel('|H_3(e^{j\Omega})| \rightarrow')
axis([0 1 -100 20]);
subplot(4,2,7), plot(f,H), grid
xlabel('\Omega / \pi \rightarrow'), ylabel('|H(e^{j\Omega})| \rightarrow')
axis([0 1 0 1]);
subplot(4,2,8), plot(f,20*log10(H)), grid
xlabel('\Omega / \pi \rightarrow'), ylabel('|H(e^{j\Omega})| in dB \rightarrow')
axis([0 1 -100 20]);

State-space representation and noise figures of 2nd order sections

Form = 'MNF';
for k=1:3
    ssr(k) = ssr2b_ABCDKW(SOS(k,1:3),SOS(k,4:6),1,Form,'no');
end
% noise figures in dB (structur with accumulators)
Ri = zeros(1,3);
for k=1:3
    if strcmp(ssr(k).form,'DF2')
        Ri(k) = 10*log10(ssr(k).W(2,2)+1);
    elseif strcmp(ssr(k).form,'MNF')
        Ri(k) = 10*log10(ssr(k).W(1,1)+ssr(k).W(2,2)+1);
    end
end
fprintf('lab7_1 (%s)\n',Form)
fprintf('Noise figures Ri of second order sections 1,2 and 3\n')
fprintf('%g dB,   %g dB,   %g dB\n',Ri)
lab7_1 (MNF)
Noise figures Ri of second order sections 1,2 and 3
1.36633 dB,   4.25284 dB,   10.8032 dB

Quantized 2nd order sections and overall frequency response

w = 8; % wordlength
for k=1:3
    ssrq(k) = ssr_quant2c(ssr(k),w); % for ssr(k) see lab7_2 !!
end
% simulation of impulse response of the quantized systems with ideal arithmetic
x = [1 zeros(1,2048)];
yq1 = ssr_filter(ssrq(1),x);
yq2 = ssr_filter(ssrq(2),yq1);
yq3 = ssr_filter(ssrq(3),yq2);

Graphics - Frequency response of quantized 2nd order sections

Hq  = abs(fft(yq3,2048));
FIG1 = figure('Name',['lab7_1 : Frequency responses (',ssr(1).form,', ',num2str(w),'bit)'],'NumberTitle',...
  'off','Units','normal','Position',[.3 .24 .55 .55]);
f = 0:1023; f = f/1024;
subplot(2,1,1), plot(f(1:256),H(1:256),f(1:256),Hq(1:256)), grid
xlabel('\Omega / \pi \rightarrow'), ylabel('|H(e^{j\Omega})| \rightarrow')
axis([0 .25 0 1.2]);
title(['Frequency response (',ssr(1).form,', ',num2str(w),'bit)'])
legend('MATLAB',['quantized, w = ',num2str(w),' bit'],'Location','Best')
subplot(2,1,2), plot(f,20*log10(H),f,20*log10(Hq(1:1024))), grid
xlabel('\Omega / \pi \rightarrow'), ylabel('|H(e^{j\Omega})| \rightarrow')
axis([0 1 -100 20]);
title(['Frequency response (',ssr(1).form,', ',num2str(w),'bit)'])
legend('MATLAB',['quantized, w = ',num2str(w),' bit'],'Location','Best')

Filtering, round-off noise and noise figures of 2nd order sections

N  = 1e6;              % number of simulation cycles = N + 1
rand('state',0);
x = 2*rand(1,N)-1;     % input signal
x = x*sqrt(3)/5;       % crest factor 5
xq = quant2c(x,w,'r'); % quantization (rounding)
[y1,S] = ssr_filter(ssrq(1),xq); % ideal filter
[y2,S] = ssr_filter(ssrq(2),y1);
[y3,S] = ssr_filter(ssrq(3),y2);
[yq1,S,OC1] = ssr_filter2c(ssrq(1),xq,w); % quantized filter (rounding)
[yq2,S,OC2] = ssr_filter2c(ssrq(2),yq1,w);
[yq3,S,OC3] = ssr_filter2c(ssrq(3),yq2,w);
fprintf('Wordlength = %g, structure = %s\n',w,ssrq(1).form)
fprintf('Overflow counters : %g ,  %g ,  %g\n',OC1,OC2,OC3)
Ni1 = var(y1-yq1); % variance of inner noise
Ni2 = var(y2-yq2);
Ni3 = var(y3-yq3);
fprintf('Noise variances:  %g dB,  %g dB,  %g dB\n',10*log10(Ni1),10*log10(Ni2),10*log10(Ni3))
FIG4 = figure('Name',['lab7_1 : Filter output signal (',ssrq(1).form,', ',num2str(w),'bit)'],'NumberTitle',...
  'off','Units','normal','Position',[.3 .21 .55 .55]);
n = 0:400;
plot(n,y3(1:401),'--',n,yq3(1:401),'o'), grid
axis([0 400 -.4 .4]);
xlabel('n \rightarrow'), ylabel('y[n] \rightarrow')
title(['Output signal (',ssr(1).form,', ',num2str(w),'bit)'])
legend('MATLAB',['quantized, w = ',num2str(w),' bit'],'Location','Best')
% signal-to-noise ratio
Sin  = var(xq);
Sout = var(y3);
fprintf('Signal powers and SNR \n')
fprintf('Sin = %g dB , Sout = %g dB , SNR = %g dB\n',10*log10(Sin),10*log10(Sout),10*log10(Sout/Ni3))
Wordlength = 8, structure = MNFq
Overflow counters : 0 ,  0 ,  0
Noise variances:  -51.5823 dB,  -47.483 dB,  -39.4517 dB
Signal powers and SNR 
Sin = -13.9784 dB , Sout = -21.0976 dB , SNR = 18.3542 dB