Fix test on win64b : test_run(signal_processing, lattn)
[scilab.git] / scilab / modules / signal_processing / tests / unit_tests / lattn.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2013 - Scilab Enterprises - Charlotte Hecquet
4 // Copyright (C) 2013 - Scilab Enterprises - Sylvestre Ledru
5 // Copyright (C) 2013 - Scilab Enterprises - Adeline CARNIS
6 //
7 //  This file is distributed under the same license as the Scilab package.
8 // =============================================================================
9
10 //Generate the process
11 t1=0:0.1:100;
12 y1=sin(2*%pi*t1)+sin(2*%pi*2*t1);
13
14 //Covariance of y1
15 nlag=128;
16 c1=corr(y1,nlag);
17 c1=c1';
18
19 //Compute the filter with maximum order=15 and p=1
20 n=5;
21 [la1,sig1]=lattn(n,1,c1);
22 poly(0,"z");
23
24 expected = [1, 0.4429775275224619446313];
25 computed = coeff(la1(1));
26 assert_checkalmostequal(computed, expected, 1.e-14);
27
28 expected = [1, -0.7424151347904438535963, 0.6626546432402768971315];
29 computed = coeff(la1(2));
30 assert_checkalmostequal(computed, expected, 1.e-14);
31
32 expected = [1, -0.7483090096409563685143, 0.6686337968594154856916, -0.0048019603017336104020];
33 computed = coeff(la1(3));
34 assert_checkalmostequal(computed, expected, 1.e-11);
35
36 expected = [1, -2.259216884889600152064, 3.0129744887444243062191, -2.2463220443824241101538, 0.9961140979715100707281];
37 computed = coeff(la1(4));
38 assert_checkalmostequal(computed, expected, 1.e-13);
39
40 expected = [1, -1.8328746888034248563315, 2.0881496310317460007866, -1.0213063678721847615805, 0.0953432301271536220000, 0.3993857757876373426598];
41 computed = coeff(la1(5));
42 assert_checkalmostequal(computed, expected, 1.e-10);
43
44 expected = [-1.7888543819998343753497, 1];
45 computed = coeff(sig1(1));
46 assert_checkalmostequal(computed, expected, 1.e-14);
47
48 expected = [1.2273893327241232054092, -1.2451484900822573642643, 1];
49 computed = coeff(sig1(2));
50 assert_checkalmostequal(computed, expected, 1.e-14);
51
52 expected = [-1.5168020192922293531979, 2.3534861083273810322680, -2.2502643910424811046767, 1];
53 computed = coeff(sig1(3));
54 assert_checkalmostequal(computed, expected, 1.e-13);
55
56 expected = [1.0674946929328583689056, -2.3156179157577936322809, 3.0672491379903537023210, -2.255390458180256185727, 1];
57 computed = coeff(sig1(4));
58 assert_checkalmostequal(computed, expected, 1.e-12);
59
60 expected = [1.4523203295727387107661, -2.2136119179063014072995, 2.0601861867297621699890, -0.1951300338336365847169, -0.8087137031222213501280, 1];
61 computed = coeff(sig1(5));
62 assert_checkalmostequal(computed, expected, 1.e-10);
63
64 //Compare result of poles with p=-1 and with levin function
65 [la2,sig2]=lattn(n,-1,c1);
66 expected = [1, -1.7888543819998343753497];
67 computed = coeff(la2(1));
68 assert_checkalmostequal(computed, expected, 1.e-14);
69
70 expected = [1, -1.2451484900822573642643, 1.2273893327241232054092];
71 computed = coeff(la2(2));
72 assert_checkalmostequal(computed, expected, 1.e-14);
73
74 expected = [1, -2.25026439104248154877, 2.3534861083273810322680, -1.5168020192922295752425];
75 computed = coeff(la2(3));
76 assert_checkalmostequal(computed, expected, 1.e-13);
77
78 expected = [1, -2.2553904581802566298165, 3.0672491379903545904995, -2.3156179157577940763701, 1.0674946929328590350394];
79 computed = coeff(la2(4));
80 assert_checkalmostequal(computed, expected, 1.e-12);
81
82 expected = [1, -0.8087137031221993677121, -0.1951300338336872108869, 2.0601861867298310038166, -2.2136119179063538098262, 1.4523203295727622474942];
83 computed = coeff(la2(5));
84 assert_checkalmostequal(computed, expected, 1.e-10);
85
86 expected = [0.4429775275224624442316, 1];
87 computed = coeff(sig2(1));
88 assert_checkalmostequal(computed, expected, 1.e-14);
89
90 expected = [0.6626546432402768971315, -0.7424151347904438535963, 1];
91 computed = coeff(sig2(2));
92 assert_checkalmostequal(computed, expected, 1.e-14);
93
94 expected = [-0.0048019603017336104020, 0.6686337968594154856916, -0.7483090096409563685143, 1];
95 computed = coeff(sig2(3));
96 assert_checkalmostequal(computed, expected, 1.e-11);
97
98 expected = [0.9961140979715094045943, -2.2463220443824232219754, 3.0129744887444229739515, -2.2592168848895997079751, 1];
99 computed = coeff(sig2(4));
100 assert_checkalmostequal(computed, expected, 1.e-13);
101
102 expected = [0.3993857757876351222137, 0.0953432301271577298252, -1.0213063678721903126956, 2.0881496310317495535003, -1.8328746888034264106437, 1];
103 computed = coeff(sig2(5));
104 assert_checkalmostequal(computed, expected, 1.e-10);