MATLAB: How to convert a system with delay from continuous to discrete and from discrete to continuous and the result be the same

c2d d2c delayControl System Toolbox

How can I run this code and the first and the third results be the same?
sys=tf(1,[1 1],'InputDelay',0.4)
sysd=c2d(sys,0.3)
sysagain=d2c(sysd)

Best Answer

When you convert your continuous transfer function to discrete with sample time as 0.3, every step happens at the times of 0.3, like 0.3, 0.6, 0.9... So when your continuous transfer function has 0.4 delay, your conversion loses accuracy or should I say your conversion is not done right. Look at the discrete transfer function, it is z^(-2) which means 0.6 second delay. You can also see it when you convert it back to continuous. So the problem is not that sample time and delay are dependent. The problem is that your sample time is not appropriate to for that specific delay time.
>> sys=tf(1,[1 1],'InputDelay',0.4)
Transfer function:
1
exp(-0.4*s) * -----
s + 1
>> sysd=c2d(sys,0.3)
Transfer function:
0.1813 z + 0.07791
z^(-2) * ------------------
z - 0.7408
Sampling time: 0.3
>> sysagain=d2c(sysd)
Transfer function:
0.1813 s + 1
exp(-0.6*s) * ------------
s + 1