# Difference in sample time of discrete model and input

2 views (last 30 days)
Jatin Sharma on 5 May 2020
Answered: Abhishek Kumar on 13 Dec 2020
I was going through the algorithms on how MATLAB evaluates convolution in CT system. Example code given on MATLAB is
w2 = 62.83^2;
h = tf(w2,[1 2 w2]);
dt = 0.016;
ts = 0:dt:5;
us = (rem(ts,1) >= 0.5);
hd = c2d(h,dt);
lsim(hd,us)
In the above example sample time of input and TF are the same. I have removed ts from lsim because it was making no difference in this case. So in the output I got 313 samples.
w2 = 62.83^2;
h = tf(w2,[1 2 w2]);
dt = 0.016;
ts = 0:0.02:5;
us = (rem(ts,1) >= 0.5);
hd = c2d(h,dt);
lsim(hd,us)
In the above code sample time of input and TF are different. If i put Ts then it gave an error but when I removed it worked fine. So in the output I had 250 samples. Some of the starting samples matched also.
So my question is how the matlab calculates output in 2nd case ??

Abhishek Kumar on 13 Dec 2020
Hi Jatin, given the two codes you have used, the continuous time transfer function is same in both the cases, the differnce is in length of number of samples
>> h1
h1 =
3948
----------------
s^2 + 2 s + 3948
Continuous-time transfer function.
>>dt1 = 0.016;
>>ts1 = 0:dt1:5;
>> length(ts1)
ans =
313
>> h2
h2 =
3948
----------------
s^2 + 2 s + 3948
Continuous-time transfer function.
>>dt2 = 0.016;
>>ts2 = 0:0.02:5;
>> length(ts2)
ans =
251
hence, some of the coefficients are similar you can go through the documentation of functions used for better understanding..

R2019b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by