# Xcos CLOCK\_c Period Setting

**URL:** <https://scilab.discourse.group/t/xcos-clock-c-period-setting/277>\
**Category:** Modeling and simulation\
**Created:** [November 29, 2023, 12:47pm UTC](https://scilab.discourse.group/t/xcos-clock-c-period-setting/277 "2023-11-29T12:47:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Smart](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Smart](https://scilab.discourse.group/u/Smart)\
**Post date:** [November 29, 2023, 12:47pm UTC](https://scilab.discourse.group/t/xcos-clock-c-period-setting/277/1 "2023-11-29T12:47:27Z")

</div>

Hello,

Enclosed, please find a screenshot along with the xcos model.

I am seeking clarification on why the scope output varies with changes in the period time of CLOCK\_c.

I’m unsure where my approach might be incorrect. The model with a period time of 0.001 aligns with my measured data, which was obtained with a sampling rate of 10 milliseconds.

I would greatly appreciate any insights or feedback. Thank you!

```auto
p = [0.1472152 13.846622 0.301877 3.]
xcos("X:\Period.zcos")

```

 ![xcos_period](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/4480b9c79b6eaef42eab51612fd511b3040f013b.png)

[Period.zcos](https://scilab.discourse.group/uploads/short-url/qvOZQ0S8xSf8RElQgXUjtKyT4LU.zcos) (4.1 KB)

---

<div class="post-metadata">

**Author:** ![Smart](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Smart](https://scilab.discourse.group/u/Smart)\
**Post date:** [November 29, 2023, 1:50pm UTC](https://scilab.discourse.group/t/xcos-clock-c-period-setting/277/2 "2023-11-29T13:50:02Z")

</div>

**Please increase the buffer of “To Workspace sim Variable”**

I tried to compare my results between the Xcos Simulation and Scilab.  
After you run the above simulation, it exports the data to the Workspaxe variable ‘sim’

Unfortunately the results do not fit. What is it, that I am doing wrong?

```auto
// run xcos Model in Scilab
importXcosDiagram("X:\Period.zcos")
typeof(scs_m) //The diagram data structure
scs_m.props.context //the embedded definition
xcos_simulate(scs_m, 4);

t=0:0.01:15;
p = [0.1472152 13.846622 0.301877 3.]
yfit = p(1)+p(2) * (1 - exp(-t / p(3))).^p(4); 

// sim variable created by the xcos model

//compare model with yfit function

plot2d(sim.time,sim.values)
plot2d(td,yfit,-1)

```

---

<div class="post-metadata">

**Author:** ![davidcl](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/davidcl/32/1029_2.png) [@davidcl](https://scilab.discourse.group/u/davidcl)\
**Post date:** [November 29, 2023, 2:33pm UTC](https://scilab.discourse.group/t/xcos-clock-c-period-setting/277/3 "2023-11-29T14:33:29Z")

</div>

Hello, I might get it wrong but it looks ok to me.

With a 0.1 period made from scratch, I got:  
 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/873e22d3971863026090775dcb8514b8b8c6db19.png)

With your schema and minor tweaks to render the same, I got:  
 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/aa920ed20100654cb6d2fac0dc6c6748e6821b0d.png)

They both looks alright to me. Might be different from the Scilab result which is not using a solver for dynamic systems.

---

<div class="post-metadata">

**Author:** ![Smart](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Smart](https://scilab.discourse.group/u/Smart)\
**Post date:** [November 30, 2023, 8:09am UTC](https://scilab.discourse.group/t/xcos-clock-c-period-setting/277/4 "2023-11-30T08:09:21Z")

</div>

Thank you, davidcl, for your insight. It’s now working for me as well.

Here’s the method I used:

I fitted some measurements using the following formula:  
p = [0.1472152 13.846622 0.301877 3.]  
yfit = p(1) + p(2) \* (1 - exp(-t / p(3))).^p(4);

I then applied the Laplace transform to this function to develop the model shown in the Period.zcos (as mentioned in my initial post).

However, I’m puzzled as to why the results from the model don’t align with the yfit function.

Next, I plan to conduct tests using Matlab and also attempt to convert the function into StateSpace using Scilab.

---

<div class="post-metadata">

**Author:** ![Smart](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Smart](https://scilab.discourse.group/u/Smart)\
**Post date:** [November 30, 2023, 9:59am UTC](https://scilab.discourse.group/t/xcos-clock-c-period-setting/277/5 "2023-11-30T09:59:11Z")

</div>

Okay, i have to rethink the transfer function. Simulink online got the same result.

 ![simulink_period](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/5bd5400f96f44a9d0578f75fa10e0bc69b98d0d4.png)

---

<div class="post-metadata">

**Author:** ![Smart](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Smart](https://scilab.discourse.group/u/Smart)\
**Post date:** [November 30, 2023, 11:28am UTC](https://scilab.discourse.group/t/xcos-clock-c-period-setting/277/6 "2023-11-30T11:28:49Z")

</div>

I am currently experiencing some confusion. It’s possible that I have incorrectly identified the transfer function. Could Scilab be used to generate the transfer function for the system’s behavior in the time domain? The equations are:

[y(t) = p2 \times (1 - e^{-t/p3})^3]  
[TF = \frac{p2}{(1 + p3 \times s)^3}]

---

<div class="post-metadata">

**Author:** ![Smart](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Smart](https://scilab.discourse.group/u/Smart)\
**Post date:** [November 30, 2023, 1:08pm UTC](https://scilab.discourse.group/t/xcos-clock-c-period-setting/277/7 "2023-11-30T13:08:04Z")

</div>

There is defnitly something wrong in my Transferfunction. Hope to figure it out, soon. In the following I minimized the problem to a PT1 model system.

```auto
function PT1model()

    t=0:0.01:2;
    T1 = 0.2;
    K = 5;
    yfit = K*(1-exp(-t/T1));
    plot(t,yfit,'r-')
    
    s=poly(0,'s')
    g = K/(1+T1*s)
    g = syslin('c',g) // define tf
    gs = csim('step',t,g);
    plot(t,gs,'g-.');
    title('PT1model')
endfunction

function PT3model()

    t=0:0.01:2;
    T1 = 0.2;
    K = 5;
    yfit = K*(1-exp(-t/T1)).^3;
    plot(t,yfit,'r-')
    
    s=poly(0,'s')
    g = K/(1+T1*s)^3
    g = syslin('c',g) // define tf
    gs = csim('step',t,g);
    plot(t,gs,'g-.');
    title('PT3model')
endfunction

```

![PT1model](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/5aa7caace07b63689f9596c07fdf861e32feac9f.png)  
 ![PT3model](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/438e886d0c9093d37c934a089bf0250351fcca13.png)

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [November 30, 2023, 1:17pm UTC](https://scilab.discourse.group/t/xcos-clock-c-period-setting/277/8 "2023-11-30T13:17:07Z")

</div>

Hello,

Which is the target, the signal in the time domain or the transfer function ? Because the ones you have defined above cannot match. A product in the frequency domain amounts to a convolution in the time domain.

S.

---

<div class="post-metadata">

**Author:** ![Smart](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Smart](https://scilab.discourse.group/u/Smart)\
**Post date:** [November 30, 2023, 1:24pm UTC](https://scilab.discourse.group/t/xcos-clock-c-period-setting/277/9 "2023-11-30T13:24:24Z")

</div>

I have analyzed the step responses from my measurements and discovered that the function  
yfit = K\*(1-exp(-t/T1)).^3;  
accurately describes the behavior.

I am realizing now that I seem to have lost my expertise after what feels like 20 years of practice.

Perhaps I need to reformulate yfit in order to develop a PT3 model for the Laplace domain. I think I might have a conceptual error here.

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [November 30, 2023, 4:38pm UTC](https://scilab.discourse.group/t/xcos-clock-c-period-setting/277/10 "2023-11-30T16:38:25Z")

</div>

> **[LaplaceTransform\[(1-E^(-(t/T)))^3,t,s\] - Wolfram|Alpha](https://www.wolframalpha.com/input?i=LaplaceTransform%5B%281-E%5E%28-%28t%2FT%29%29%29%5E3%2Ct%2Cs%5D)**
>
> Wolfram|Alpha brings expert-level knowledge and capabilities to the broadest possible range of people—spanning all professions and education levels.

---

<div class="post-metadata">

**Author:** ![Smart](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Smart](https://scilab.discourse.group/u/Smart)\
**Post date:** [December 1, 2023, 8:16am UTC](https://scilab.discourse.group/t/xcos-clock-c-period-setting/277/11 "2023-12-01T08:16:33Z")

</div>

Sure, i’ve forgotten about this page. Thanks for the hint 🙂
