# APPENDIX 2 More in Relation to the ZOH

APPENDIX 2 More in Relation to the ZOH

The ZOH is a D/A converter. In words, it converts numbers at discrete times, , to voltages, etc. defined over continuous time. To arrive at a mathematical formulation for the ZOH as a transfer function between continuous-time inputs and outputs, consider the number 1.0 that the ZOH will hold as 1.0 volt over the time interval T. If we view the number as the continuous-time input , then the output is , where is the unit step function. Since this output is the response to an impulse, it is, by definition, the system impulse response. Hence, the system transfer function is

.(A2.1)

While this might seem like just another transfer function, recall that inputs to it are not defined for just any time, t. they are weighted impulse functions located at times with weights , which are the numbers to be held.

Write (A2.1) as: .(A2.2)

The fact that the input is viewed as a sequence of weighted impulse functions means that we can write it as

.(A2.3)

Taking the Laplace transform of (A2.3) gives

.(A2.4)

We express (A2.4) as to emphasize the fact that, even though it is related to continuous-time, it is a generalized input, in the sense that it is the Laplace transform of equally spaced, weighted Dirac-delta functions. While is the Laplace transform of this sequence of delta functions, it is also the z-transform of the number sequence .

From (A2.4) we can write (A2.2) as:

.(A2.5)

Equation (A2.5) highlights the fact that the output of the ZOH is a function of not only s, but also .

Example A2.1 To demonstrate the impulse train nature of the input to the ZOH, we will create this as a continuous-time transfer function, and compute the system impulse response via the command sequence:

s=tf('s');

T=2*pi/50;

z1=exp(-s*T);

ZOH=(1-z1)/s;

t=0:T/100:5*T;

h0=impulse(ZOH,t);

n=length(t);

u=zeros(1,n);

u(1)=100/T;

h1=lsim(ZOH,u,t);

figure(1)

stairs(t,h0,'k','LineWidth',2)

hold on

stairs(t,h1,'r.','LineWidth',2)

grid

legend('h_0(t) via IMPULSE','h_1(t) via LSIM')

xlabel('Time (sec)')

title('ZOH Impulse Response h(t) for T=0.1257 sec')

Figure A2.1 ZOH impulse response via ‘impulse’ and ‘lsim’.

The astute reader might note that the ‘lsim’ response has a value of zero at , and jumps to 1.0 at .Using ‘impulse’ the value at equals 1.0. We can conclude that the ‘impulse’ command compute the result by basically using a table of Laplace transform pairs; not by simulating the time-domain response. □

Example A2.2 We will now compute the response to a weighted impulse train.

%EXAMPLE 2:

nT=100;

dt=T/nT;

t=0:dt:10*T;

n=length(t);

u=zeros(1,n);

u(1)=1/dt; u(nT+1)=3*u(1); u(2*nT+1)=u(1);

h=lsim(ZOH,u,t);

figure(2)

stairs(t,h,'LineWidth',2)

xlabel('Time (sec)')

title('ZOH Response to x=[1 3 1 0 ...]')

grid

Figure A2.2 ZOH response to a weighted pulse train sequence.

Example A2.3 We will now compare the impulse and step response for versus . To this end, note that the impulse response of is a pulse of width T and height 1.0. As an input to , this in no way resembles an impulse. Hence, the impulse into must have weight .

%EXAMPLE 3:

G=1/(s+1);

t=0:dt:50*T;

%Impulse Response

g=impulse(G,t);

n=length(t);

u=zeros(1,n); u(1)=1/(dt*T);

GZ=ZOH*G;

gg=lsim(GZ,u,t);

figure(3)

plot(t,g,'LineWidth',2)

hold on

plot(t,gg,'r','LineWidth',2)

title('Impulse Response for G(s) and ZOH(s)G(s)')

xlabel('Time (sec)')

grid

%Step Response

u=zeros(1,n);

for k=1:nT:n

u(k)=1/dt;

end

g=step(G,t);

gg=lsim(GZ,u,t);

figure(4)

plot(t,g,'LineWidth',2)

hold on

plot(t,gg,'r--','LineWidth',2)

title('Step Response for G(s) and ZOH(s)G(s)')

xlabel('Time (sec)')

grid

Figure A2.3 Impulse and step response for and .

Choosing T- Rule of Thumb vs. Actual Thinking- And its Relation to Test Engineering

Among engineers, there are many ‘rule of thumb’ decision devices. One is in relation to choosing the appropriate sampling time, T, associated with an A/D converter such as the ZOH. In this section we disclothe this ‘rule of thumb’. In fact, it has everything to do with the concept of bandwidth (BW), inputs, and outputs. In other words, if the input to a system has a BW that is less than the system BW, then it will not excite high frequency system dynamics. They will remain ‘hidden’.

The ideal pulse for exciting all of the dynamics of a system (but also with the distinct possibility of damaging that system in the process) is the Dirac δ-function, . Because its Laplace transform equals 1.0, it excites all frequencies with an equal amount of energy. Of course, however, such a function doesn’t exist. It is approximated by a short duration, high amplitude pulse. Consider, for example, the pulse that is the impulse response of . As shown in Figure A2.1, it has width T. It is the response to the number . By exciting this response by the number , it becomes an approximation of . It is this type of pulse that is the input to a continuous-time system . We will now look into the details of this pulse. Recall that this pulse has the Laplace transform pair relation:

.(A2.6)

Example A2.4 To view the frequency content of (A2.6) that will excite we need only use the Matlab ‘bode’ command. The plots in Figure A2.4 are the Bode magnitude plots for various values of T.

%Example 4:

Tvec =[1 0.1 0.01];

wvec=logspace(0,3,1000);

nw=length(wvec);

Mmat=zeros(3,nw);

for k=1:3

Z1=exp(-s*Tvec(k));

ZOH=(1-Z1)/(s*Tvec(k));

[M,P]=bode(ZOH,wvec);

Mmat(k,:)=20*log10(abs(M));

end

figure(5)

semilogx(wvec,Mmat)

xlabel('Frequency (r/s)')

ylabel('dB')

title('Bode Plot of ZOH Magnitude')

legend('T=1','T=.01','T=.01','Location','SouthWest')

grid

Figure A2.4 Bode magnitude for for various T values.

This figure reveals that the -3dB bandwidth is inversely proportional to T, and that above this BW the spectral energy in the pulse rolls off at 20dB/decade. The first ‘null’ in the spectral energy occurs at , and the -3dB BW is . Recall that the Nyquist frequency is the analysis BW for the sampled system. Hence, we find that the -3dB BW of the pulse spectral energy is:

.(A2.7)

Equation (A2.7) is of utmost importance. If the pulse width T (or sampling frequency ) is chosen so that the spectral BW (A2.7) does not excite all of the dynamics of , then those dynamics remain subdued. However, as seen in Figure A2.4, those dynamics will be excited by the energy sidelobes. For example, the peak of the first sidelobe is only 13dB down from the low frequency energy. Hence, if has dynamics in that region, they will be excited to a certain extent. In relation to controlling a system, the issue is not so much about exciting all the system modes as it is acknowledging their existence. Specifically, the Nyquist frequency in (A2.7) must be chosen to be greater than the highest mode that could possibly be excited, lest that mode alias itself as a low-frequency mode. We have the following

Conclusion- One should choose T in such a manner that the dynamics above the pulse -3dB BW frequency (A2.7) can be assumed to be negligible.

For example, suppose that we assume that the dynamics of are negligible at levels greater than 20dB below the system maximum magnitude (which in this case is 0dB). The -20dB frequency is 10 rad/sec. Hence, we would want the pulse spectral BW (A2.7) to be equal to this frequency. In other words, we would want . If we take a more conservative view of assuming that the dynamics are negligible at levels greater than 40dB below the system maximum, then since the -40dB frequency is 100 rad/sec. we would choose . □

Matlab code for Appendix 2

%PROGRAM NAME: c2dAPP2.m

%EXAMPLE 1:

s=tf('s');

T=2*pi/50;

z1=exp(-s*T);

ZOH=(1-z1)/s;

t=0:T/100:5*T;

h0=impulse(ZOH,t);

n=length(t);

u=zeros(1,n);

u(1)=100/T;

h1=lsim(ZOH,u,t);

figure(1)

stairs(t,h0,'k','LineWidth',2)

hold on

stairs(t,h1,'r.','LineWidth',2)

grid

legend('h_0(t) via IMPULSE','h_1(t) via LSIM')

xlabel('Time (sec)')

title('ZOH Impulse Response h(t) for T=0.1257 sec')

%======

%EXAMPLE 2:

nT=100;

dt=T/nT;

t=0:dt:10*T;

n=length(t);

u=zeros(1,n);

u(1)=1/dt; u(nT+1)=3*u(1); u(2*nT+1)=u(1);

h=lsim(ZOH,u,t);

figure(2)

stairs(t,h,'LineWidth',2)

xlabel('Time (sec)')

title('ZOH Response to x=[1 3 1 0 ...]')

grid

%======

%EXAMPLE 3:

G=1/(s+1);

t=0:dt:50*T;

%Impulse Response

g=impulse(G,t);

n=length(t);

u=zeros(1,n); u(1)=1/(dt*T);

GZ=ZOH*G;

gg=lsim(GZ,u,t);

figure(3)

plot(t,g,'LineWidth',2)

hold on

plot(t,gg,'r','LineWidth',2)

title('Impulse Response for G(s) and ZOH(s)G(s)')

xlabel('Time (sec)')

grid

%Step Response

u=zeros(1,n);

for k=1:nT:n

u(k)=1/dt;

end

g=step(G,t);

gg=lsim(GZ,u,t);

figure(4)

plot(t,g,'LineWidth',2)

hold on

plot(t,gg,'r--','LineWidth',2)

title('Step Response for G(s) and ZOH(s)G(s)')

xlabel('Time (sec)')

grid

%======

%Example 4:

Tvec =[1 0.1 0.01];

wvec=logspace(0,3,1000);

nw=length(wvec);

Mmat=zeros(3,nw);

for k=1:3

Z1=exp(-s*Tvec(k));

ZOH=(1-Z1)/(s*Tvec(k));

[M,P]=bode(ZOH,wvec);

Mmat(k,:)=20*log10(abs(M));

end

figure(5)

semilogx(wvec,Mmat)

xlabel('Frequency (r/s)')

ylabel('dB')

title('Bode Plot of ZOH Magnitude')

legend('T=1','T=.01','T=.01','Location','SouthWest')

grid