summaryrefslogtreecommitdiff
path: root/macros/chebwin.sci
blob: 2caeecd1863ed4662d0b9cfb2c26505caf55bdab (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
function w = chebwin (m, at)

 funcprot(0);
    rhs= argn(2);

  if (rhs < 1 | rhs > 2)
    error("Wrong Number of input arguments");
  elseif (~ (isscalar (m) & (m == fix (m)) & (m > 0)))
    error ("chebwin: M must be a positive integer");
  elseif (rhs == 1)
    at = 100;
  elseif (~ (isscalar (at) & isreal(at)))
    error ("chebwin: AT must be a real scalar");
  end

  if (m == 1)
    w = 1;
  else
    // beta calculation
    gamma = 10^(-at/20);
    beta = cosh(1/(m-1) * acosh(1/gamma));
    // freq. scale
    k = (0:m-1);
    x = beta*cos(%pi*k/m);
    // Chebyshev window (freq. domain)
    p = cheb(m-1, x);
    // inverse Fourier transform
    if (modulo(m,2))
      w = real(fft(p));
      M = (m+1)/2;
      w = w(1:M)/w(1);
      w = [w(M:-1:2) w]';
    else
      //half-sample delay (even order)
      p = p.*exp(%i*%pi/m * (0:m-1));
      w = real(fft(p));
      M = m/2+1;
      w = w/w(2);
      w = [w(M:-1:2) w(2:M)]';
    end
  end

endfunction