Ticket #581: chebwin-fix.patch

File chebwin-fix.patch, 1.6 KB (added by rmay, 4 years ago)

Patch against SVN head that makes chebwin work for high orders

  • signaltools.py

    old new  
    854854        M = M+1 
    855855 
    856856    # compute the parameter beta 
    857     beta = cosh(1.0/(M-1.0)*arccosh(10**(at/20.))) 
     857    order = M - 1.0 
     858    beta = cosh(1.0/order * arccosh(10**(abs(at)/20.))) 
    858859    k = r_[0:M]*1.0 
    859860    x = beta*cos(pi*k/M) 
    860861    #find the window's DFT coefficients 
    861     p = zeros(x.shape) * 1.0 
    862     for i in range(len(x)): 
    863         if x[i] < 1: 
    864             p[i] = cos((M - 1) * arccos(x[i])) 
    865         else: 
    866             p[i] = cosh((M - 1) * arccosh(x[i])) 
     862    # Use analytic definition of Chebyshev polynomial instead of expansion 
     863    # from scipy.special. Using the expansion in scipy.special leads to errors. 
     864    p = zeros(x.shape) 
     865    p[x > 1] = cosh(order * arccosh(x[x > 1])) 
     866    p[x < -1] = (1 - 2*(order%2)) * cosh(order * arccosh(-x[x < -1])) 
     867    p[numpy.abs(x) <=1 ] = cos(order * arccos(x[numpy.abs(x) <= 1])) 
    867868 
    868869    # Appropriate IDFT and filling up 
    869870    # depending on even/odd M 
    870871    if M % 2: 
    871         w = real(fft(p)); 
    872         n = (M + 1) / 2; 
    873         w = w[:n] / w[0]; 
     872        w = real(fft(p)) 
     873        n = (M + 1) / 2 
     874        w = w[:n] / w[0] 
    874875        w = concatenate((w[n - 1:0:-1], w)) 
    875876    else: 
    876877        p = p * exp(1.j*pi / M * r_[0:M]) 
    877         w = real(fft(p)); 
    878         n = M / 2 + 1; 
    879         w = w / w[1]; 
    880         w = concatenate((w[n - 1:0:-1], w[1:n])); 
     878        w = real(fft(p)) 
     879        n = M / 2 + 1 
     880        w = w / w[1] 
     881        w = concatenate((w[n - 1:0:-1], w[1:n])) 
    881882    if not sym and not odd: 
    882883        w = w[:-1] 
    883884    return w