summaryrefslogtreecommitdiff
path: root/tests/test.sce
blob: 8e68761f61a1e412ec5ebb00c8b468ad3eb45571 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
exec builder.sce
exec loader.sce


//exec build.sce
test_pass=[]
res=[]

test1=0
/////////Test case for       2) arburg                  //////////

a = octave_fun("arburg","signal", [1,2,3,4,5],2);
a = floor(abs(a*1000));

if(a==[1000 1863 957])
    test_pass=[test_pass,1];
else
    test_pass=[test_pass,0];
    disp("arburg test failed")
end

/////////Test case for       4) aryule                  //////////

a = octave_fun("aryule","signal", [1,2,3,4,5],2);
a = floor(abs(a*1000));

if(a==[1000 814 119])
    test_pass=[test_pass,1];
else
    test_pass=[test_pass,0];
    disp("aryule test failed")
end

/////////Test case for       38)levinson                  //////////

a = [1 0.1 -0.8];
v = 0.4;
rand("seed", 0);
w = sqrt(v)*rand(15000,1);
x=octave_fun("filter","signal",1,a,w);

r=octave_fun("xcorr","signal",x);

ar=octave_fun("levinson","signal",r,length(a)-1);

ar = round(ar*10000)/10000;

if(ar ~= 0)
  test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("levinson Test failed")
end

/////////Test case for       **)sigmoid_train                  //////////

s = octave_fun("sigmoid_train",0.1,[1:3],[4])
s=floor(abs(s*1000))
if(s==273)
  test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("sigmoid_train Test failed")
end

/////////Test case for       **)circshift                  /////////

 M = [1 2 3 4];
 R = octave_fun("circshift",M,[0 1]);

if(R == [4 1 2 3])
  test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("circshift failed")
end

/////////////////////////////////////////////
/////////Test case for       **)kaiser                 //////////

a = octave_fun("kaiser",6,[0.2])
a = floor(abs(a*1000))
if(a==[990; 996; 999; 999; 996; 990])
  test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("kaiser Test failed")
end

/////////////////////////////////////////////

/////////////////////////////////////////////


/////////Test case for       autoreg_matrix                 //////////
m = octave_fun("autoreg_matrix",[1 2 3],[2]);

if(m == [1 0 0; 1 1 0; 1 2 1])
  test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("autoreg_matrix test failed")
end

/////////////////////////////////////////////
/////////Test case for       arch_rnd                 //////////

a = [1 2 3 4 5];
b = [7 8 9 10];
t = 5 ;
rand("seed", 0)
m = octave_fun("arch_rnd",a,b,t);
m = round(m*1000)/1000;

if(m ~=0 )
   test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("arch_rnd Test failed")
end

/////////////////////////////////////////////

/////////Test case for       postpad                 //////////

y = octave_fun("postpad",[1 2 3],6);

if(y == [1 2 3 0 0 0 ] )
   test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("postpad Test failed")
end


/////////Test case for       wconv                 //////////
a = [1 2 3 4 5];
b = [7 8 9 10];
y = octave_fun("wconv",[1],a,b);

if(y == [7.    22.    46.    80.    114.    106.    85.   50.])
           test_pass=[test_pass,1]
else
	test_pass=[test_pass,0]
	disp("wconv Test failed")
end
/////////Test case for       dctmtx                 //////////
T = octave_fun("dctmtx",[3]);
T = floor(abs(T*1000))

if(T == [577  577  577; 707  0  707; 408 816 408])
           test_pass=[test_pass,1]
else
	test_pass=[test_pass,0]
	disp("dctmtx Test failed")
end

/////////Test case for       40) medfilt1                  //////////


fs = 100;
t = 0:1/fs:1;
x = sin(2*%pi*t*3)+0.25*sin(2*%pi*t*40);

y = octave_fun("medfilt1","signal",x,10);
y = round(y*10000)/10000 ;
y = y';

if(length(y) ~= 0)
           test_pass=[test_pass,1]
    else
	test_pass=[test_pass,0]
	disp("medfilt1 Test failed")
end

/////////////////////////////////////////////
/////////Test case for       arma_rnd                 //////////

a = [1 2 3 4 5];
b = [7; 8; 9; 10; 11];
t = 5 ;
v = 10 ;
n = 100 ;
rand("seed", 0);
m = octave_fun("arma_rnd","signal",a, b, v, t, n);
m = round(m);

if(m ~= 0)
           test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("arma_rnd Test failed")
end

/////////Test case for       ncauer                 //////////

[z p g] = octave_fun("ncauer","signal",3, 10, 4);
g = floor(abs(g*1000));

if(g == 324)
           test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("ncauer Test failed")
end

/////////Test case for ellipap //////////

[z p g] = octave_fun("ellipap","signal",4, 3, 10);
g = floor(abs(g*1000));

if(g == 324)
  test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("ellipap Test failed")
end
////////Test case for besselap ///////////////  
[z p g] = octave_fun("besselap","signal",5);
g = round(g*10000)/10000;
p = round(p*10000)/10000;

if(g == 1)
           test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("besselap Test failed")
end

/////////Test case for       zp2tf                 //////////

[num, den] = octave_fun("zp2tf","signal",[1 2 3], [4 5 6], 5);
num = round(num*10000)/10000;
den = round(den*10000)/10000;

if(num == [5 -30 55 -30] & den == [1.  -15.    74.   -120])
           test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("zp2tf Test failed")
end

/////////Test case for       tf2zp                 //////////

[z p k] = octave_fun("tf2zp","signal",[1 2 3], [4 5 6]);
k = floor(abs(k*1000));

if(k == 250)
  test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("tf2zp Test failed")
end

/////////Test case for       buttap                 //////////

n = 5 ;
[z p g] = octave_fun("buttap", n);
g = round(g*10000)/10000;

if(g == 1)
           test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("buttap Test failed")
end

/////////Test case for       cheb1ap                 //////////

[z p g] = octave_fun("cheb1ap", 10, 3);
g = floor(abs(g*1000));

if(g == 1)
           test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("cheb1ap Test failed")
end

/////////Test case for       sftrans                 //////////
//fc = 100;
//[z p k] = octave_fun("tf2zp","signal",[1 2 3], [4 5 6])
//[Sz, Sp, Sg] = octave_fun("sftrans",z, p, k, 2*%pi*fc, %f);
//Sz = round(Sz*10000)/10000;


//if(Sz ~= 0)
//           test_pass=[test_pass,1]
//else
//	test_pass=[test_pass,0]
//	disp("sftrans Test failed")
//end

/////////Test case for       bilinear                 //////////

[b a] = octave_fun("bilinear","signal",[1 2 3], [4 5 6], 1);
b = round(b*10000)/10000;
a = round(a*10000)/10000;


if(round(a) == [1 -1 0])
           test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("bilinear Test failed")
end
/////////Test case for       buttord                 //////////
[n, Wn] = octave_fun("buttord",40/500, 150/500, 3, 60);
Wn = floor(abs(Wn*1000));

if(n == 5 & Wn == 80)
           test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("buttord Test failed")
end

/////////Test case for       butter                 //////////

[b a] = octave_fun("butter","signal",4,0.3,"high");
b = floor(abs(b*1000));
a = floor(abs(a*1000));

if(b == [275 1101 1652 1101 275] & a == [1000 1570 1275 484 76])
           test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("butter Test failed")
end

/////////Test case for       cheb1ord                 //////////

[n, Wn]=octave_fun("cheb1ord","signal",[0.25 0.3],[0.24 0.31],3,10);
Wn = floor(abs(Wn*1000));

if(n == 3 & Wn == [250 300])
           test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("cheb1ord Test failed")
end

/////////Test case for       cheby1                 //////////

[z, p, k]=octave_fun("cheby1","signal",2,6,0.7,"high");// Note it shld return k as well
z = floor(abs(z*1000));
p = floor(abs(real(p)*1000));
k = floor(abs(k*1000));

if(z == [1000;1000] & real(p) == [629;629] & k == 55)
   test_pass=[test_pass,1];
else
	test_pass=[test_pass,0];
	disp("cheby1 Test failed")
end

/////////Test case for       cheb2ord                 //////////

Wp = 40/500;
Ws = 150/500;
Rp = 3;
Rs = 60;
[n,Ws] = octave_fun("cheb2ord",Wp,Ws,Rp,Rs);
Ws = round((Ws*10000)/1000);

if(n == 4 & Ws == 3)
           test_pass=[test_pass,1]
else
	test_pass=[test_pass,0]
	disp("cheb2ord Test failed")
end

/////////////////////////////////////////////
res=find(test_pass==0)

if(res~=[])
    disp("One or more tests failed in test1")
		disp(length(test_pass),"Total functions tested:")
		//exit(1)
else
disp(length(test_pass),"Total functions tested:")
disp("ALL OK")
//exit()
end

exit()