summaryrefslogtreecommitdiff
path: root/macros/decimate.sci
blob: 5a2e42819faac4e9bb6ce12942019a76e539fb1f (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
function y = decimate(x, q, n, ftype)
rhs = argn(2)
if(rhs<2 | rhs>4)
error("Wrong number of input arguments.")
elseif(~(sum(length(q)==1) & q == fix (q) & q > 0))
error("Parameter 2 must be a positive integer.")
end
if (nargin < 3)
ftype = "iir"
n = []
elseif (nargin < 4)
if (ischar (n))
ftype = n
n = []
else
ftype = "iir"
end
end

if (~ and(strcmp (ftype, {"fir", "iir"})))
error("Filter type must be either fir or iir.")
end

fir = strcmp (ftype, "fir")
if (isempty (n))
if (fir)
n = 30
else
n = 8
end
end

if(~(sum(length(n)==1) & n == fix (n) & n > 0))
error("N must be a positive integer.")
end
select(rhs)
case 2 then
y = callOctave("decimate", x, q)
case 3 then
y = callOctave("decimate", x, q, n)
case 4 then
y = callOctave("decimate", x, q, n, ftype)
end
endfunction