9cded3e0044479f8ed39c134449749653b4f061a
[scilab.git] / scilab / modules / signal_processing / help / ja_JP / correlation_convolution / corr.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="ja" xml:id="corr">
4
5     <refnamediv>
6
7         <refname>corr</refname>
8
9         <refpurpose>相関 , 共分散</refpurpose>
10
11     </refnamediv>
12
13     <refsynopsisdiv>
14
15         <title>呼び出し手順</title>
16
17         <synopsis>[cov,Mean]=corr(x,[y],nlags)
18
19             [cov,Mean]=corr('fft',xmacro,[ymacro],n,sect)
20
21
22
23             [w,xu]=corr('updt',x1,[y1],w0)
24
25             [w,xu]=corr('updt',x2,[y2],w,xu)
26
27             ...
28
29             [wk]=corr('updt',xk,[yk],w,xu)
30
31         </synopsis>
32
33     </refsynopsisdiv>
34
35     <refsection>
36
37         <title>引数</title>
38
39         <variablelist>
40
41             <varlistentry>
42
43                 <term>x</term>
44
45                 <listitem>
46
47                     <para>実数ベクトル</para>
48
49                 </listitem>
50
51             </varlistentry>
52
53             <varlistentry>
54
55                 <term>y</term>
56
57                 <listitem>
58
59                     <para>実数ベクトル, デフォルト値 x.</para>
60
61                 </listitem>
62
63             </varlistentry>
64
65             <varlistentry>
66
67                 <term>nlags</term>
68
69                 <listitem>
70
71                     <para>i整数, 指定した相関係数の数.</para>
72
73                 </listitem>
74
75             </varlistentry>
76
77             <varlistentry>
78
79                 <term>xmacro</term>
80
81                 <listitem>
82
83                     <para>scilab 外部ルーチン (下記参照).</para>
84
85                 </listitem>
86
87             </varlistentry>
88
89             <varlistentry>
90
91                 <term>ymacro</term>
92
93                 <listitem>
94
95                     <para>scilab 外部ルーチン (下記参照), デフォルト値: xmacro</para>
96
97                 </listitem>
98
99             </varlistentry>
100
101             <varlistentry>
102
103                 <term>n</term>
104
105                 <listitem>
106
107                     <para>整数, シーケンス全体の大きさ (下記参照).</para>
108
109                 </listitem>
110
111             </varlistentry>
112
113             <varlistentry>
114
115                 <term>sect</term>
116
117                 <listitem>
118
119                     <para>シーケンスのセクションの大きさ (下記参照).</para>
120
121                 </listitem>
122
123             </varlistentry>
124
125             <varlistentry>
126
127                 <term>xi</term>
128
129                 <listitem>
130
131                     <para>実数ベクトル</para>
132
133                 </listitem>
134
135             </varlistentry>
136
137             <varlistentry>
138
139                 <term>yi</term>
140
141                 <listitem>
142
143                     <para>実数ベクトル,デフォルト値: xi.</para>
144
145                 </listitem>
146
147             </varlistentry>
148
149             <varlistentry>
150
151                 <term>cov</term>
152
153                 <listitem>
154
155                     <para>実数ベクトル, 相関係数</para>
156
157                 </listitem>
158
159             </varlistentry>
160
161             <varlistentry>
162
163                 <term>Mean</term>
164
165                 <listitem>
166
167                     <para>実数または実数ベクトル,  x (および y)の平均</para>
168
169                 </listitem>
170
171             </varlistentry>
172
173         </variablelist>
174
175     </refsection>
176
177     <refsection>
178
179         <title>説明</title>
180
181         <para>
182
183             以下を計算します.
184
185         </para>
186
187         <programlisting role=""><![CDATA[
188          n - m
189          ====
190          \                                       1
191 cov(m) =  >   (x(k) - xmean) (y(m+k) - ymean) * ---
192          /                                       n
193          ====
194          k = 1
195  ]]></programlisting>
196
197         <para>
198
199             ただし,   m=0,..,<literal>nlag-1</literal> で,2つのベクトルは
200
201             <literal>x=[x(1),..,x(n)]</literal>,
202
203             <literal>y=[y(1),..,y(n)]</literal>です.
204
205         </para>
206
207         <para>
208
209             シーケンス x および y が異なる場合, corr(x,y,...)はcorr(y,x,...)
210
211             と異なることに注意してください.
212
213         </para>
214
215         <variablelist>
216
217             <varlistentry>
218
219                 <term>短いシーケンス</term>
220
221                 <listitem>
222
223                     <para>
224
225                         <literal>[cov,Mean]=corr(x,[y],nlags)</literal> は,
226
227                         最初の nlags 個の相関係数および Mean = <literal>mean(x)</literal>
228
229                         (<literal>y</literal> が引数として指定された場合,<literal>[x,y]</literal> の平均)
230
231                         を返します.
232
233                         シーケンス  <literal>x</literal> (または <literal>y</literal>) は実数,
234
235                         <literal>x</literal>と<literal>y</literal>は同じ次元 n と仮定されます.
236
237                     </para>
238
239                 </listitem>
240
241             </varlistentry>
242
243             <varlistentry>
244
245                 <term>長いシーケンス</term>
246
247                 <listitem>
248
249                     <para>
250
251                         <literal>[cov,Mean]=corr('fft',xmacro,[ymacro],n,sect)</literal>
252
253                         ここで,<literal>xmacro</literal> は以下のどちらかです
254
255                     </para>
256
257                     <itemizedlist>
258
259                         <listitem>
260
261                             <para>
262
263                                 <literal>[xx]=xmacro(sect,istart)</literal> という型の関数で,
264
265                                 <literal>istart</literal> から
266
267                                 <literal>istart+sect-1</literal>までの添字を有するシーケンスの
268
269                                 一部を含む
270
271                                 <literal>nsect</literal>次のベクトル<literal>xx</literal>を返します.
272
273                             </para>
274
275                         </listitem>
276
277                         <listitem>
278
279                             <para>
280
281                                 FortranサブルーチンまたはCプロシージャで,
282
283                                 同じ計算を行ないます(例えば,<literal>dgetx</literal>の
284
285                                 ソースコードを参照ください).
286
287                                 <literal>n</literal> = シーケンスの総数.
288
289                                 <literal>sect</literal> = シーケンスのセクションの大きさ.
290
291                                 <literal>sect</literal> は 2の累乗とする必要があります.
292
293                                 <literal>cov</literal> は
294
295                                 <literal>sect</literal>次です.
296
297                                 計算は FFT により行われます.
298
299                             </para>
300
301                         </listitem>
302
303                     </itemizedlist>
304
305                 </listitem>
306
307             </varlistentry>
308
309             <varlistentry>
310
311                 <term>更新法</term>
312
313                 <listitem>
314
315                     <programlisting role=""><![CDATA[
316 [w,xu]=corr('updt',x1,[y1],w0)
317 [w,xu]=corr('updt',x2,[y2],w,xu)
318  ...
319 wk=corr('updt',xk,[yk],w,xu)
320  ]]></programlisting>
321
322                     <para>
323
324                         この呼び出し手順では,計算結果が<literal>corr</literal>をコールする度に
325
326                         更新されます.
327
328                     </para>
329
330                     <programlisting role=""><![CDATA[
331 w0 = 0*ones(1,2*nlags);
332 nlags = power of 2.
333  ]]></programlisting>
334
335                     <para>
336
337                         <literal>x1,x2,...</literal> は,
338
339                         <literal>x=[x1,x2,...]</literal>で,<literal>xi</literal>の大きさが
340
341                         2の累乗となるような<literal>x</literal> の一部です.
342
343                         <literal>nlags</literal>個の係数を得るには,
344
345                         最後の fft を <literal>c=fft(w,1)/n</literal>;
346
347                         <literal>cov=c(1nlags)</literal>を実行する必要があります
348
349                         (<literal>n</literal> は <literal>x (y)</literal>の大きさ).
350
351                         注意:
352
353                         この呼び出し手順は <literal>xmean = ymean = 0</literal> を仮定します.
354
355                     </para>
356
357                 </listitem>
358
359             </varlistentry>
360
361         </variablelist>
362
363     </refsection>
364
365     <refsection>
366
367         <title>例</title>
368
369         <programlisting role="example"><![CDATA[
370 x=%pi/10:%pi/10:102.4*%pi;
371 rand('seed');rand('normal');
372 y=[.8*sin(x)+.8*sin(2*x)+rand(x);.8*sin(x)+.8*sin(1.99*x)+rand(x)];
373 c=[];
374 for j=1:2,for k=1:2,c=[c;corr(y(k,:),y(j,:),64)];end;end;
375 c=matrix(c,2,128);cov=[];
376 for j=1:64,cov=[cov;c(:,(j-1)*2+1:2*j)];end;
377 rand('unif')
378
379 rand('normal');x=rand(1,256);y=-x;
380 deff('[z]=xx(inc,is)','z=x(is:is+inc-1)');
381 deff('[z]=yy(inc,is)','z=y(is:is+inc-1)');
382 [c,mxy]=corr(x,y,32);
383 x=x-mxy(1)*ones(x);y=y-mxy(2)*ones(y);  //centring
384 c1=corr(x,y,32);c2=corr(x,32);
385 norm(c1+c2,1)
386 [c3,m3]=corr('fft',xx,yy,256,32);
387 norm(c1-c3,1)
388 [c4,m4]=corr('fft',xx,256,32);
389 norm(m3,1),norm(m4,1)
390 norm(c3-c1,1),norm(c4-c2,1)
391 x1=x(1:128);x2=x(129:256);
392 y1=y(1:128);y2=y(129:256);
393 w0=0*ones(1:64);   //32 coeffs
394 [w1,xu]=corr('u',x1,y1,w0);w2=corr('u',x2,y2,w1,xu);
395 zz=real(fft(w2,1))/256;c5=zz(1:32);
396 norm(c5-c1,1)
397 [w1,xu]=corr('u',x1,w0);w2=corr('u',x2,w1,xu);
398 zz=real(fft(w2,1))/256;c6=zz(1:32);
399 norm(c6-c2,1)
400 rand('unif')
401
402 // Fortran または C 外部ルーチンのテスト
403 //
404 deff('[y]=xmacro(sec,ist)','y=sin(ist:(ist+sec-1))');
405 x=xmacro(100,1);
406 [cc1,mm1]=corr(x,2^3);
407 [cc,mm]=corr('fft',xmacro,100,2^3);
408 [cc2,mm2]=corr('fft','corexx',100,2^3);
409 [max(abs(cc-cc1)),max(abs(mm-mm1)),max(abs(cc-cc2)),max(abs(mm-mm2))]
410
411 deff('[y]=ymacro(sec,ist)','y=cos(ist:(ist+sec-1))');
412 y=ymacro(100,1);
413 [cc1,mm1]=corr(x,y,2^3);
414 [cc,mm]=corr('fft',xmacro,ymacro,100,2^3);
415 [cc2,mm2]=corr('fft','corexx','corexy',100,2^3);
416 [max(abs(cc-cc1)),max(abs(mm-mm1)),max(abs(cc-cc2)),max(abs(mm-mm2))]
417  ]]></programlisting>
418
419     </refsection>
420
421     <refsection role="see also">
422
423         <title>参照</title>
424
425         <simplelist type="inline">
426
427             <member>
428
429                 <link linkend="fft">fft</link>
430
431             </member>
432
433         </simplelist>
434
435     </refsection>
436
437 </refentry>
438