~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to man/eng/scicos/VARIABLE_DELAY.htm

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
 
2
 
 
3
<!--Converted with LaTeX2HTML 2002-2-1 (1.70)
 
4
original version by:  Nikos Drakos, CBLU, University of Leeds
 
5
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
 
6
* with significant contributions from:
 
7
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
 
8
<HTML>
 
9
<HEAD>
 
10
<TITLE>Variable delay </TITLE>
 
11
<META NAME="description" CONTENT="Variable delay ">
 
12
<META NAME="keywords" CONTENT="main">
 
13
<META NAME="resource-type" CONTENT="document">
 
14
<META NAME="distribution" CONTENT="global">
 
15
 
 
16
<META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1">
 
17
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
 
18
 
 
19
<LINK REL="STYLESHEET" HREF="main.css">
 
20
 
 
21
</HEAD>
 
22
 
 
23
<BODY bgcolor="#FFFFFF">
 
24
 
 
25
<!--Table of Child-Links-->
 
26
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
 
27
 
 
28
<UL>
 
29
<LI><A NAME="tex2html5141"
 
30
  HREF="VARIABLE_DELAY.htm#SECTION005811100000000000000">Library</A>
 
31
<LI><A NAME="tex2html5142"
 
32
  HREF="VARIABLE_DELAY.htm#SECTION005811200000000000000">Description</A>
 
33
<LI><A NAME="tex2html5143"
 
34
  HREF="VARIABLE_DELAY.htm#SECTION005811300000000000000">Dialog Box</A>
 
35
<LI><A NAME="tex2html5144"
 
36
  HREF="VARIABLE_DELAY.htm#SECTION005811400000000000000">Default properties</A>
 
37
<LI><A NAME="tex2html5145"
 
38
  HREF="VARIABLE_DELAY.htm#SECTION005811500000000000000">Interfacing function</A>
 
39
<LI><A NAME="tex2html5146"
 
40
  HREF="VARIABLE_DELAY.htm#SECTION005811600000000000000">Computational function (type 4)</A>
 
41
</UL>
 
42
<!--End of Table of Child-Links-->
 
43
<HR>
 
44
 
 
45
<H2><A NAME="SECTION005811000000000000000"></A><A NAME="VARIABLE_DELAY"></A>
 
46
<BR>
 
47
Variable delay 
 
48
</H2>
 
49
<DIV ALIGN="CENTER">
 
50
<!-- MATH
 
51
 $\epsfig{file=VARIABLE_DELAY.eps,width=90.00pt}$
 
52
 -->
 
53
<IMG
 
54
 WIDTH="143" HEIGHT="161" ALIGN="BOTTOM" BORDER="0"
 
55
 SRC="img151.gif"
 
56
 ALT="\epsfig{file=VARIABLE_DELAY.eps,width=90.00pt}">
 
57
</DIV>
 
58
<H3><font color="blue"><A NAME="SECTION005811100000000000000">
 
59
Library</A>
 
60
</font></H3>
 
61
Linear
 
62
 
 
63
<H3><font color="blue"><A NAME="SECTION005811200000000000000">
 
64
Description</A>
 
65
</font></H3>
 
66
The Variable Transport Delay block can be used to simulate a variable
 
67
time delay. The block might be used to model a system with a pipe
 
68
where the speed of a motor pumping fluid in the pipe is variable. The
 
69
block accepts two inputs: the first input is the signal that passes
 
70
through the block; the second input is the time delay. 
 
71
 
 
72
<H3><font color="blue"><A NAME="SECTION005811300000000000000">
 
73
Dialog Box</A>
 
74
</font></H3>
 
75
<DIV ALIGN="CENTER">
 
76
<TABLE CELLPADDING=3 BORDER="1">
 
77
<TR><TD ALIGN="CENTER">Set delay parameters</TD>
 
78
<TD></TD>
 
79
</TR>
 
80
<TR><TD ALIGN="CENTER">Max delay</TD>
 
81
<TD ALIGN="CENTER">1</TD>
 
82
</TR>
 
83
<TR><TD ALIGN="CENTER">initial input</TD>
 
84
<TD ALIGN="CENTER">0</TD>
 
85
</TR>
 
86
<TR><TD ALIGN="CENTER">Buffer size</TD>
 
87
<TD ALIGN="CENTER">1024</TD>
 
88
</TR>
 
89
</TABLE>
 
90
</DIV>
 
91
 
 
92
<UL>
 
93
<LI>Max delay:It defines the largest value the time delay input
 
94
  can have.The value cannot be negative.    
 
95
</LI>
 
96
<LI>initial input:The output generated by the block until the
 
97
  simulation time first exceeds the time delay input. 
 
98
</LI>
 
99
<LI>Buffer size: The number of points the block can store. 
 
100
</LI>
 
101
</UL>
 
102
 
 
103
<H3><font color="blue"><A NAME="SECTION005811400000000000000">
 
104
Default properties</A>
 
105
</font></H3>
 
106
 
 
107
<UL>
 
108
<LI>always active: no
 
109
</LI>
 
110
<LI>direct-feedthrough: yes
 
111
</LI>
 
112
<LI>zero-crossing: no
 
113
</LI>
 
114
<LI>mode: no
 
115
</LI>
 
116
<LI>number/sizes of inputs: 2 / -1  1
 
117
</LI>
 
118
<LI>number/sizes of outputs: 1 / -1
 
119
</LI>
 
120
<LI>number/sizes of activation inputs: 0 / 
 
121
</LI>
 
122
<LI>number/sizes of activation outputs: 0 / 
 
123
</LI>
 
124
<LI>continuous-time state: no
 
125
</LI>
 
126
<LI>discrete-time state: no
 
127
</LI>
 
128
<LI>name of computational function: <EM>variable_delay</EM>
 
129
</LI>
 
130
</UL>
 
131
<H3><font color="blue"><A NAME="SECTION005811500000000000000">
 
132
Interfacing function</A>
 
133
</font></H3>
 
134
<TT>scilab/macros/scicos_blocks/linear/VARIABLE_DELAY.sci</TT>
 
135
 
 
136
<H3><font color="blue"><A NAME="SECTION005811600000000000000">
 
137
Computational function (type 4)</A>
 
138
</font></H3>
 
139
<BR>
 
140
<PRE>#include "scicos_block.h"
 
141
#include &lt;math.h&gt;
 
142
#include "../machine.h"
 
143
 
 
144
#if WIN32
 
145
#define NULL    0
 
146
#endif
 
147
 
 
148
extern void sciprint __PARAMS((char *fmt,...));
 
149
 
 
150
void variable_delay(scicos_block *block,int flag)
 
151
{/*  rpar[0]=max delay, rpar[1]=init value, ipar[0]=buffer length */
 
152
  double* pw,del,t,td;
 
153
  int* iw;
 
154
  int i,j,k;
 
155
  if (flag == 4){/* the workspace is used to store previous values */
 
156
    if ((*block-&gt;work=
 
157
         scicos_malloc(sizeof(int)+sizeof(double)* 
 
158
                       block-&gt;ipar[0]*(1+block-&gt;insz[0])))== NULL ) {
 
159
      set_block_error(-16);
 
160
      return;
 
161
    }
 
162
    pw=*block-&gt;work; 
 
163
    pw[0]=-block-&gt;rpar[0]*block-&gt;ipar[0];
 
164
    for(i=1;i&lt; block-&gt;ipar[0];i++){
 
165
      pw[i]=pw[i-1]+block-&gt;rpar[0];
 
166
      for(j=1;j&lt; block-&gt;insz[0]+1;j++){
 
167
        pw[i+block-&gt;ipar[0]*j]=block-&gt;rpar[1];
 
168
      }
 
169
    }
 
170
    iw=(int *) (pw+block-&gt;ipar[0]*(1+block-&gt;insz[0]));
 
171
    *iw=0;
 
172
  }else  if (flag == 5){
 
173
    scicos_free(*block-&gt;work);
 
174
  } else if (flag==1) {
 
175
    if (get_phase_simulation()==1) do_cold_restart();
 
176
    pw=*block-&gt;work; 
 
177
    iw=(int *) (pw+block-&gt;ipar[0]*(1+block-&gt;insz[0]));
 
178
    t=get_scicos_time();
 
179
    del=min(max(0,block-&gt;inptr[1][0]),block-&gt;rpar[0]);
 
180
    td=t-del;
 
181
    if(td&lt;pw[*iw]){
 
182
      sciprint("delayed time=%f but last stored time=%f \r\n", td, pw[*iw]);
 
183
      sciprint("Consider increasing the length of buffer in variable delay block\r\n");
 
184
    }
 
185
    if (t&gt;pw[(block-&gt;ipar[0]+*iw-1)%block-&gt;ipar[0]]){
 
186
      for(j=1;j&lt; block-&gt;insz[0]+1;j++){
 
187
        pw[*iw +block-&gt;ipar[0]*j]=block-&gt;inptr[0][j-1];
 
188
      }
 
189
      pw[*iw]=t;
 
190
      *iw=(*iw+1)%block-&gt;ipar[0];
 
191
    }else{
 
192
      for(j=1;j&lt; block-&gt;insz[0]+1;j++){
 
193
        pw[(block-&gt;ipar[0]+*iw-1)%block-&gt;ipar[0] +block-&gt;ipar[0]*j]=block-&gt;inptr[0][j-1];
 
194
      }
 
195
      pw[(block-&gt;ipar[0]+*iw-1)%block-&gt;ipar[0]]=t;
 
196
    }
 
197
 
 
198
    i=0;j= block-&gt;ipar[0]-1;
 
199
 
 
200
    while (j-i&gt;1) {
 
201
      k=(i+j)/2;
 
202
      if (td&lt;pw[(k+*iw)%block-&gt;ipar[0]]) {
 
203
        j=k;
 
204
      }else if (td&gt;pw[(k+*iw)%block-&gt;ipar[0]]) {
 
205
        i=k;
 
206
      }else{
 
207
        i=k;
 
208
        j=k;
 
209
        break;
 
210
      }
 
211
    }
 
212
    i=(i+*iw)%block-&gt;ipar[0];
 
213
    j=(j+*iw)%block-&gt;ipar[0];
 
214
    del=pw[j]-pw[i];
 
215
    if(del!=0.0){
 
216
      for (k=1;k&lt;block-&gt;insz[0]+1;k++){
 
217
        block-&gt;outptr[0][k-1]=((pw[j]-td)*pw[i+block-&gt;ipar[0]*k] +
 
218
                               (td-pw[i])*pw[j+block-&gt;ipar[0]*k])/del;
 
219
      }
 
220
    }else{
 
221
      for (k=1;k&lt;block-&gt;insz[0]+1;k++){
 
222
        block-&gt;outptr[0][k-1]=pw[i+block-&gt;ipar[0]*k];
 
223
      }
 
224
    }
 
225
  }
 
226
}
 
227
</PRE>
 
228
<HR>
 
229
<ADDRESS>
 
230
Ramine Nikoukhah
 
231
2004-06-22
 
232
</ADDRESS>
 
233
</BODY>
 
234
</HTML>