?? dsexample1.m
字號:
function mod = dsexample1% Design example for a 5th-order binary lowpass modulator.% Altogether too much of the code is greared toward making the graphs% look 'pretty'.format compact;J = 1i;clcfprintf(1,'\t\t\t5th-Order Lowpass Example\n\n');% Design parametersorder = 5;R = 32;nlev = 2;f0 = 0;Hinf = 1.5;% NTF Synthesisfprintf(1,'Doing NTF synthesis... ');H = synthesizeNTF(order,R,2,Hinf,f0); %Optimized zero placementfprintf(1,'Done.\n');figure(1); clfset(1,'name','Poles and Zeros');set(1,'numbertitle','off');set(1,'position',[0 359 200 200]);plotPZ(H,{'r','g'});axis([-1 1 -1 1]); axis('square');set(gca,'position', [0.1 0.07, 0.9, 0.85]);drawnow;figure(2); clfset(2,'name','NTF Magnitude Response')set(2,'numbertitle','off');set(2,'position',[224 359 300 200]);f = [linspace(0,0.75/R,100) linspace(0.75/R,0.5,100)];z = exp(J*2*pi*f);magH = dbv(evalTF(H,z));NTFMagHandle = subplot('position', [0.1 0.58, 0.87, 0.4]);plot(f,magH,'r');hold on;plot([0 1/(2*R)], -100*[1 1],'-g','linewidth',3);axis([0 0.5 -100 10]);grid on;text(0.25,-85,'Normalized frequency (1\rightarrow f_s)','hor','center');fstart = 0.01;f = linspace(fstart,1.2,200)/(2*R); z = exp(J*2*pi*f);magH = dbv(evalTF(H,z));subplot('position', [0.1 0.07, 0.87, 0.4]);semilogx(f*2*R,magH,'r');axis([fstart 1.2 -100 -30]);grid onsigma_H = dbv(rmsGain(H,0,0.5/R));hold on;semilogx([fstart 1], sigma_H*[1 1]);semilogx([fstart 1], sigma_H*[1 1],'o');semilogx([fstart 1], -100*[1 1],'-g','linewidth',3);text(0.1, sigma_H+5, sprintf('in-band RMS gain = %5.0fdB',sigma_H),'hor','center');text(0.1, -90, 'Normalized frequency (1\rightarrow f_B)', 'hor', 'center');drawnow;% SNR Simulation (stability verification)fprintf(1,'Doing SNR simulations... ');figure(3); clf;set(3,'name','SNR curve');set(3,'numbertitle','off');set(3,'position',[544 359 235 200]);if nlev==2 [snr_pred,amp_pred] = predictSNR(H,R); plot(amp_pred,snr_pred,'-'); hold on;end[snr,amp] = simulateSNR(H,R,[],f0,nlev);fprintf(1,'Done.\n');plot(amp,snr,'og');grid on;figureMagic([-100 0], 10, 2, [0 100], 10, 2);xlabel('Input Level (dBFS)');ylabel('SNR (dB)');[peak_snr,peak_amp] = peakSNR(snr,amp);msg = sprintf('OSR=%d',R);text(-50,85,msg,'hor','center', 'vertical','middle');msg = sprintf('peak SNR = %4.1fdB \n@ amp=%4.1fdB ',peak_snr,peak_amp);text(0,15,msg,'hor','right');set(gca,'position', [0.15 0.1, 0.82, 0.87]);drawnow;% Realization and dynamic range scalingfprintf(1,'Doing dynamic range scaling... ');form = 'CRFB';[a,g,b,c] = realizeNTF(H,form);b = [b(1) zeros(1,length(b)-1)]; % Use a single feed-in for the inputABCD0 = stuffABCD(a,g,b,c,form);[junk G] = calculateTF(ABCD0);figure(2);subplot(NTFMagHandle); hold on;f = linspace(0,0.5); z = exp(2i*pi*f);plot(f,dbv(evalTF(G,z)),'g')hold off; drawnow;% [ABCD umax] = scaleABCD(ABCD0,nlev,f0,[],[],[],1e4);[ABCD umax] = scaleABCD(ABCD0,nlev,f0);[a,g,b,c] = mapABCD(ABCD,form);fprintf(1,'Done.\n');fprintf(1,'Verifying dynamic range scaling... ');u = linspace(0,0.95*umax,30);N = 1e4; T = ones(1,N);maxima = zeros(order,length(u));for i = 1:length(u) ui = u(i); [v,xn,xmax] = simulateDSM( ui(T), ABCD, nlev ); maxima(:,i) = xmax(:); if any(xmax>1e2) fprintf(1,'Warning, umax from scaleABCD was too high.\n'); umax = ui; u = u(1:i); maxima = maxima(:,1:i); break; endendfigure(4); clf;set(4,'name','State Maxima');set(4,'numbertitle','off');set(4,'position',[20 339 300 200]);colors = hsv(order);cmd = 'legend( handles';handles = [];for i = 1:order handles(i) = plot(u,maxima(i,:),'--','color',colors(i,:)); if i==1 hold on; end cmd = [ cmd ',''State ' num2str(i) '''' ]; plot(u,maxima(i,:),'o','color',colors(i,:));endhold off; grid on;text(umax/2,0.05,'DC input','hor','cen')axis([ 0 umax 0 1]);set(gca,'position', [0.1 0.07, 0.85, 0.85]);cmd = [cmd ',4);'];eval(cmd);drawnow;fprintf(1,'Done.\n');% The next step would be to size capacitors for each integrator state based % on noise (kT/C) limits and area.% Simulations modelling the effects of finite op-amp gain and capacitor % errors should also be performed.mod.NTF = H;mod.STF = G;mod.nlev = nlev;mod.ABCD = ABCD;mod.umax = umax;mod.peak_snr = peak_snr;mod.form = form;mod.coefficients.a = a;mod.coefficients.g = g;mod.coefficients.b = b;mod.coefficients.c = c;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -