1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
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 -->
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">
16
<META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1">
17
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
19
<LINK REL="STYLESHEET" HREF="main.css">
23
<BODY bgcolor="#FFFFFF">
25
<!--Table of Child-Links-->
26
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
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>
42
<!--End of Table of Child-Links-->
45
<H2><A NAME="SECTION005811000000000000000"></A><A NAME="VARIABLE_DELAY"></A>
51
$\epsfig{file=VARIABLE_DELAY.eps,width=90.00pt}$
54
WIDTH="143" HEIGHT="161" ALIGN="BOTTOM" BORDER="0"
56
ALT="\epsfig{file=VARIABLE_DELAY.eps,width=90.00pt}">
58
<H3><font color="blue"><A NAME="SECTION005811100000000000000">
63
<H3><font color="blue"><A NAME="SECTION005811200000000000000">
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.
72
<H3><font color="blue"><A NAME="SECTION005811300000000000000">
76
<TABLE CELLPADDING=3 BORDER="1">
77
<TR><TD ALIGN="CENTER">Set delay parameters</TD>
80
<TR><TD ALIGN="CENTER">Max delay</TD>
81
<TD ALIGN="CENTER">1</TD>
83
<TR><TD ALIGN="CENTER">initial input</TD>
84
<TD ALIGN="CENTER">0</TD>
86
<TR><TD ALIGN="CENTER">Buffer size</TD>
87
<TD ALIGN="CENTER">1024</TD>
93
<LI>Max delay:It defines the largest value the time delay input
94
can have.The value cannot be negative.
96
<LI>initial input:The output generated by the block until the
97
simulation time first exceeds the time delay input.
99
<LI>Buffer size: The number of points the block can store.
103
<H3><font color="blue"><A NAME="SECTION005811400000000000000">
104
Default properties</A>
108
<LI>always active: no
110
<LI>direct-feedthrough: yes
112
<LI>zero-crossing: no
116
<LI>number/sizes of inputs: 2 / -1 1
118
<LI>number/sizes of outputs: 1 / -1
120
<LI>number/sizes of activation inputs: 0 /
122
<LI>number/sizes of activation outputs: 0 /
124
<LI>continuous-time state: no
126
<LI>discrete-time state: no
128
<LI>name of computational function: <EM>variable_delay</EM>
131
<H3><font color="blue"><A NAME="SECTION005811500000000000000">
132
Interfacing function</A>
134
<TT>scilab/macros/scicos_blocks/linear/VARIABLE_DELAY.sci</TT>
136
<H3><font color="blue"><A NAME="SECTION005811600000000000000">
137
Computational function (type 4)</A>
140
<PRE>#include "scicos_block.h"
141
#include <math.h>
142
#include "../machine.h"
148
extern void sciprint __PARAMS((char *fmt,...));
150
void variable_delay(scicos_block *block,int flag)
151
{/* rpar[0]=max delay, rpar[1]=init value, ipar[0]=buffer length */
155
if (flag == 4){/* the workspace is used to store previous values */
156
if ((*block->work=
157
scicos_malloc(sizeof(int)+sizeof(double)*
158
block->ipar[0]*(1+block->insz[0])))== NULL ) {
159
set_block_error(-16);
163
pw[0]=-block->rpar[0]*block->ipar[0];
164
for(i=1;i< block->ipar[0];i++){
165
pw[i]=pw[i-1]+block->rpar[0];
166
for(j=1;j< block->insz[0]+1;j++){
167
pw[i+block->ipar[0]*j]=block->rpar[1];
170
iw=(int *) (pw+block->ipar[0]*(1+block->insz[0]));
172
}else if (flag == 5){
173
scicos_free(*block->work);
174
} else if (flag==1) {
175
if (get_phase_simulation()==1) do_cold_restart();
177
iw=(int *) (pw+block->ipar[0]*(1+block->insz[0]));
179
del=min(max(0,block->inptr[1][0]),block->rpar[0]);
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");
185
if (t>pw[(block->ipar[0]+*iw-1)%block->ipar[0]]){
186
for(j=1;j< block->insz[0]+1;j++){
187
pw[*iw +block->ipar[0]*j]=block->inptr[0][j-1];
190
*iw=(*iw+1)%block->ipar[0];
192
for(j=1;j< block->insz[0]+1;j++){
193
pw[(block->ipar[0]+*iw-1)%block->ipar[0] +block->ipar[0]*j]=block->inptr[0][j-1];
195
pw[(block->ipar[0]+*iw-1)%block->ipar[0]]=t;
198
i=0;j= block->ipar[0]-1;
202
if (td<pw[(k+*iw)%block->ipar[0]]) {
204
}else if (td>pw[(k+*iw)%block->ipar[0]]) {
212
i=(i+*iw)%block->ipar[0];
213
j=(j+*iw)%block->ipar[0];
216
for (k=1;k<block->insz[0]+1;k++){
217
block->outptr[0][k-1]=((pw[j]-td)*pw[i+block->ipar[0]*k] +
218
(td-pw[i])*pw[j+block->ipar[0]*k])/del;
221
for (k=1;k<block->insz[0]+1;k++){
222
block->outptr[0][k-1]=pw[i+block->ipar[0]*k];