<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Hello,<br>
<br>
Is there anyone here that uses to use the last filter() optional
argument?<br>
<br>
In the example of the thread reminded below:<br>
<pre wrap="">V = Z;
for i=2:n
V(i) = a*V(i-1) + b*Z(i);
end
</pre>
the input is Z, the output is V, a and b are fixed parameters.<br>
The filter() description tells:<br>
<br>
<blockquote type="cite">Syntax<br>
------<br>
[y,zf] = filter(B, A, x [,zi])<br>
<br>
Parameters<br>
----------<br>
B : real vector : the coefficients of the filter numerator in
decreasing power order, or<br>
a polynomial.<br>
A : real vector : the coefficients of the filter denominator
in decreasing power order,<br>
or a polynomial.<br>
x : real row vector : the input signal<br>
zi : real row vector of length max(length(a),length(b))-1: the
initial condition<br>
relative to a "direct form II transposed" state space
representation. The default<br>
value is a vector filled with zeros.<br>
</blockquote>
<br>
So here i assume that zi is V(0) (so actually Z(1)). Then, how to
get <br>
[Z(1) V(2:n)] <br>
as from the above loop? I have tried the following, without
success:<br>
<span style="color:rgb(0,0,0);"><span style="color:rgb(0,0,0);">y</span>
<span style="color:rgb(92,92,92);">=</span> <span
style="color:rgb(50,185,185);">filter</span><span
style="color:rgb(74,85,219);">(b</span><span
style="color:rgb(74,85,219);"></span><span
style="color:rgb(0,0,0);">, </span><span
style="color:rgb(74,85,219);">[</span><span
style="color:rgb(188,143,143);">1</span> <span
style="color:rgb(92,92,92);">-</span><span
style="color:rgb(0,0,0);">a</span><span
style="color:rgb(74,85,219);">]</span><span
style="color:rgb(0,0,0);">,</span> <span
style="color:rgb(0,0,0);">Z</span><span
style="color:rgb(0,0,0);"></span><span
style="color:rgb(0,0,0);"></span><span
style="color:rgb(74,85,219);"></span><span
style="color:rgb(188,143,143);"></span><span
style="color:rgb(74,85,219);"></span><span
style="color:rgb(92,92,92);"></span><span
style="color:rgb(0,0,0);"></span><span
style="color:rgb(92,92,92);"></span><span
style="color:rgb(74,85,219);"></span><span
style="color:rgb(188,143,143);"></span><span
style="color:rgb(92,92,92);"></span><span
style="color:rgb(74,85,219);"></span><span
style="color:rgb(74,85,219);">)</span><span
style="color:rgb(0,0,0);">;<br>
or<br>
</span><span style="color:rgb(0,0,0);">y</span> <span
style="color:rgb(92,92,92);">=</span> [Z(1) <span
style="color:rgb(50,185,185);">filter</span><span
style="color:rgb(74,85,219);">(b</span><span
style="color:rgb(74,85,219);"></span><span
style="color:rgb(0,0,0);">, </span><span
style="color:rgb(74,85,219);">[</span><span
style="color:rgb(188,143,143);">1</span> <span
style="color:rgb(92,92,92);">-</span><span
style="color:rgb(0,0,0);">a</span><span
style="color:rgb(74,85,219);">]</span><span
style="color:rgb(0,0,0);">,</span> <span
style="color:rgb(0,0,0);">Z</span><span
style="color:rgb(0,0,0);"></span><span
style="color:rgb(0,0,0);"></span><span
style="color:rgb(74,85,219);"></span><span
style="color:rgb(188,143,143);"></span><span
style="color:rgb(74,85,219);"></span><span
style="color:rgb(92,92,92);"></span><span
style="color:rgb(0,0,0);"></span><span
style="color:rgb(92,92,92);"></span><span
style="color:rgb(74,85,219);"></span><span
style="color:rgb(188,143,143);"></span><span
style="color:rgb(92,92,92);"></span><span
style="color:rgb(74,85,219);"></span><span
style="color:rgb(74,85,219);">(2:$), Z(1))</span><span
style="color:rgb(0,0,0);">];<br>
or<br>
</span>y</span> <span style="color:rgb(92,92,92);">=</span> <span
style="color:rgb(50,185,185);">filter</span><span
style="color:rgb(74,85,219);">(b</span><span
style="color:rgb(74,85,219);"></span><span
style="color:rgb(0,0,0);">, </span><span
style="color:rgb(74,85,219);">[</span><span
style="color:rgb(188,143,143);">1</span> <span
style="color:rgb(92,92,92);">-</span><span
style="color:rgb(0,0,0);">a</span><span
style="color:rgb(74,85,219);">]</span><span
style="color:rgb(0,0,0);">,</span> <span
style="color:rgb(0,0,0);">Z</span><span
style="color:rgb(0,0,0);">, </span> <span
style="color:rgb(0,0,0);">Z</span><span
style="color:rgb(74,85,219);">(</span><span
style="color:rgb(188,143,143);">1</span><span
style="color:rgb(74,85,219);">)</span><span
style="color:rgb(92,92,92);"></span><span
style="color:rgb(0,0,0);"></span><span
style="color:rgb(92,92,92);"></span><span
style="color:rgb(74,85,219);">*(</span><span
style="color:rgb(188,143,143);">1</span><span
style="color:rgb(92,92,92);">-b</span><span
style="color:rgb(74,85,219);"></span><span
style="color:rgb(74,85,219);">)/a</span><span
style="color:rgb(74,85,219);">)</span><span
style="color:rgb(0,0,0);">;<br>
</span><br>
The zi option has no example, and unless filter() is bugged, the
way zi works/is taken into account is unclear.<br>
<br>
Any hint (before analyzing its hard code..)?<br>
<br>
Regards<br>
Samuel<br>
<br>
<br>
Le 01/11/2018 à 15:16, Samuel Gougeon a écrit :<br>
</div>
<blockquote cite="mid:a1e8edc6-0ad3-74d5-3113-ec60da699ba0@free.fr"
type="cite">
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
<div class="moz-cite-prefix">Le 01/11/2018 à 13:40, Samuel Gougeon
a écrit :<br>
</div>
<blockquote
cite="mid:80d2cb85-40b9-2304-84c3-7b686139dc9e@free.fr"
type="cite">
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
<div class="moz-cite-prefix">Hello,<br>
<br>
Le 01/11/2018 à 09:27, Heinz Nabielek a écrit :<br>
</div>
<blockquote
cite="mid:A78DF6B7-A270-409B-BC9D-A449B6F2E756@me.com"
type="cite">
<pre wrap="">Sorry, Scilab friends, I am still not fluid with vector operations.
Can someone rewrite the for loop for me into something much more efficient?
n=1000;
Z=grand(1,n,'nor',0,1);
r=0.9;
V=Z;
for i=2:n;
V(i)=r*V(i-1)+sqrt(1-r^2)*Z(i);
end;
The transformation generates an autocorrelated (here rho=0.9) normal distribution V from an uncorrelated normal distribution Z and eventually I will need it for very much larger n values....</pre>
</blockquote>
<br>
You may use filter(), with a feedback component (since V(i)
depends on the previous state V(i-1) computed at the previous
step).<br>
However, as shown below, a quick trial shows an initial
discrepancy between filter() result and yours with the explicit
loop.<br>
I don't know why. May be the setting for the initial condition
should be carefully considered/tuned...<br>
</blockquote>
<br>
This is certainly the reason. For i=1, V(i-1) is unknown and must
be somewhat provided. The last filter() option zi is not really
documented (i have no time to go to the reference to get clear
about how "the initial condition relative to a "direct form II
transposed" state space representation." works. Trying to provide
a value V(0) such that V(1)==Z(1) decreases the initial
discrepancy by a factor 10. But it is still non zero.<br>
<pre style="font-family:Monospaced;font-style:normal;font-size:12.0;"><span style="color:rgb(0,0,0);">y</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(50,185,185);">filter</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(50,185,185);">sqrt</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">1</span><span style="color:rgb(92,92,92);">-</span><span style="color:rgb(0,0,0);">r</span><span style="color:rgb(92,92,92);">^</span><span style="color:rgb(188,143,143);">2</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">, </span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(188,143,143);">1</span> <span style="color:rgb(92,92,92);">-</span><span style="color:rgb(0,0,0);">r</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(0,0,0);">Z</span><span style="color:rgb(0,0,0);">, </span> <span style="color:rgb(0,0,0);">Z</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">1</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(92,92,92);"></span><span style="color:rgb(0,0,0);"></span><span style="color:rgb(92,92,92);"></span><span style="color:rgb(74,85,219);">*(</span><span style="color:rgb(188,143,143);">1</span><span style="color:rgb(92,92,92);">-</span><span style="color:rgb(50,185,185);">sqrt</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">1</span><span style="color:rgb(92,92,92);">-</span><span style="color:rgb(0,0,0);">r</span><span style="color:rgb(92,92,92);">^</span><span style="color:rgb(188,143,143);">2</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(74,85,219);">)/r</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span></pre>
<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
</blockquote>
<p><br>
</p>
</body>
</html>