discretizing and resampling models -凯发k8网页登录
this example shows how to use the commands for continuous/discrete, discrete/continuous, and discrete/discrete conversions.
related commands
control system toolbox™ offers extensive support for discretization and resampling of linear systems including:
c2d
discretizes continuous-time modelsd2c
compute continuous-time extensions of discrete-time modelsd2d
resamples discrete-time models.
several algorithms are available to perform these operations, including:
zero-order hold
first-order hold
impulse invariant
tustin
matched poles/zeros.
continuous/discrete conversion
for example, consider the second-order system with delay:
to compute its zero-order hold (zoh) discretization with sampling rate of 10 hz, type
g = tf([1 -2],[1 3 20],'inputdelay',1); ts = 0.1; % sampling interval gd = c2d(g,ts)
gd = 0.07462 z - 0.09162 z^(-10) * ---------------------- z^2 - 1.571 z 0.7408 sample time: 0.1 seconds discrete-time transfer function.
compare the continuous and discrete step responses:
step(g,'b',gd,'r') legend('continuous','discretized')
discrete/continuous conversion
conversely, you can use d2c
to compute a continuous-time "interpolant" for a given discrete-time system. starting with the discretization gd
computed above, convert it back to continuous and compare with the original model g
:
gc = d2c(gd); step(g,'b',gd,'r',gc,'g--') legend('original','discretized','d2c interpolant')
the two continuous-time responses match perfectly. you may not always obtain a perfect match especially when your sampling interval ts
is too large and aliasing occurs during discretization:
ts = 1; % 10 times larger than previously hd = c2d(g,ts); hc = d2c(hd); step(g,'b',hd,'r',hc,'g--',10) legend('original','discretized','d2c interpolant')
resampling of discrete-time systems
resampling consists of changing the sampling interval of a discrete-time system. this operation is performed with d2d
. for example, consider the 10 hz discretization gd
of our original continuous-time model g
. you can resample it at 40 hz using:
gr = d2d(gd,0.025)
gr = 0.02343 z - 0.02463 z^(-40) * ---------------------- z^2 - 1.916 z 0.9277 sample time: 0.025 seconds discrete-time transfer function.
compare this with a direct discretization at 40 hz:
step(g,'b',gr,'r',c2d(g,0.025),'g--',4) legend('continuous','resampled from 0.1 to 0.025','discretized with ts=0.025')
notice that both approaches lead to the same answer.
which algorithm and sampling rate to choose?
see the example entitled discretizing a notch filter for more details on how the choice of algorithm and sampling rate affect the discretization accuracy.