Contents
Zero-pole plot
load cauer
[b,a] = sos2tf(SOS,G);
FIG1 = figure('Name','lab7_3 : 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;
SOS(2,1:3) = SOS(2,1:3)/M2;
SOS(3,1:3) = SOS(3,1:3)/M3;
G(1) = G(1)*M1*M2*M3;
Graphics - Frequency response after scaling of the 2nd order sections
FIG2 = figure('Name','lab7_3 : 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]);
Quantization of 2nd order sections
w = 8;
SOSq = SOS;
SOSq(:,1:3) = quant2c(SOSq(:,1:3),w,'r');
SOSq(:,5) = 2*quant2c(SOSq(:,5)/2,w,'r');
SOSq(:,6) = quant2c(SOSq(:,6),w,'r');
Simulation of impulse response
x = [1 zeros(1,2048)];
yq1 = tdf2D_filter(SOSq(1,1:3),SOSq(1,4:6),x);
yq2 = tdf2D_filter(SOSq(2,1:3),SOSq(2,4:6),yq1);
yq3 = tdf2D_filter(SOSq(3,1:3),SOSq(3,4:6),yq2);
Graphics - Frequency response of quantized 2nd order sections
Hq = abs(fft(yq3,2048));
FIG1 = figure('Name',['lab7_3 : Frequency response (cTDF2Dq,',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 (cTDF2q,',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 (cTDF2q,',num2str(w),'bit)'])
legend('MATLAB',['quantized, w = ',num2str(w),' bit'],'Location','Best')
Round-off noise and noise figures 2nd order sections
N = 1e6;
rand('state',0);
x = 2*rand(1,N)-1;
x = x*sqrt(3)/5;
xq = quant2c(x,w,'r');
Filtering and analysis
y1 = tdf2D_filter(SOSq(1,1:3),SOSq(1,4:6),xq);
y2 = tdf2D_filter(SOSq(2,1:3),SOSq(2,4:6),y1);
y3 = tdf2D_filter(SOSq(3,1:3),SOSq(3,4:6),y2);
[yq1,OC1] = tdf2D_filterq(SOSq(1,1:3),SOSq(1,4:6),xq,w);
[yq2,OC2] = tdf2D_filterq(SOSq(2,1:3),SOSq(2,4:6),yq1,w);
[yq3,OC3] = tdf2D_filterq(SOSq(3,1:3),SOSq(3,4:6),yq2,w);
fprintf('Wordlength = %g, structure = TDF2Dq\n',w)
fprintf('Overflow counters : %g , %g , %g\n',OC1,OC2,OC3)
Ni1 = var(y1-yq1);
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))
Wordlength = 8, structure = TDF2Dq
Overflow counters : 0 , 0 , 0
Noise variances: -39.7301 dB, -37.446 dB, -32.9665 dB
Graphics - Output signal
FIG4 = figure('Name',['lab7_3 : Filter output signal (TDF2Dq,',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 (cTDF2Dq,',num2str(w),'bit)'])
legend('MATLAB',['quantized, w = ',num2str(w),' bit'],'Location','Best')
Sin = var(xq);
Sout = var(y3);
fprintf('Signal powers and SNR : Sin = %g dB , Sout = %g dB , SNR = %g dB\n',...
10*log10(Sin),10*log10(Sout),10*log10(Sout/Ni3))
Signal powers and SNR : Sin = -13.9784 dB , Sout = -21.9785 dB , SNR = 10.9881 dB