| 1 | def chebwin(M, at, sym=1): |
|---|
| 2 | """Dolph-Chebyshev window. |
|---|
| 3 | |
|---|
| 4 | INPUTS: |
|---|
| 5 | |
|---|
| 6 | M : int |
|---|
| 7 | Window size |
|---|
| 8 | at : float |
|---|
| 9 | Attenuation (in dB) |
|---|
| 10 | sym : bool |
|---|
| 11 | Generates symmetric window if True. |
|---|
| 12 | |
|---|
| 13 | """ |
|---|
| 14 | if M < 1: |
|---|
| 15 | return array([]) |
|---|
| 16 | if M == 1: |
|---|
| 17 | return ones(1,'d') |
|---|
| 18 | |
|---|
| 19 | odd = M % 2 |
|---|
| 20 | if not sym and not odd: |
|---|
| 21 | M = M+1 |
|---|
| 22 | |
|---|
| 23 | # compute the parameter beta |
|---|
| 24 | beta = cosh(1.0/(M-1.0)*arccosh(10**(abs(at)/20.))) |
|---|
| 25 | k = r_[0:M]*1.0 |
|---|
| 26 | x = beta*cos(pi*k/M) |
|---|
| 27 | # find the window's DFT coefficients |
|---|
| 28 | # using the Chebyshev polynomial |
|---|
| 29 | p = polyval(special.chebyt(M - 1), x) |
|---|
| 30 | # Appropriate IDFT and filling up |
|---|
| 31 | # depending on even/odd M |
|---|
| 32 | if M % 2: |
|---|
| 33 | w = real(fft(p * 1.0)); |
|---|
| 34 | n = (M + 1) / 2; |
|---|
| 35 | w = w[:n] / w[0]; |
|---|
| 36 | w = numpy.core.concatenate((w[n - 1:0:-1], w)) |
|---|
| 37 | else: |
|---|
| 38 | p = p * exp(1.j*pi / M * r_[0:M]) |
|---|
| 39 | w = real(fft(p)); |
|---|
| 40 | n = M / 2 + 1; |
|---|
| 41 | w = w / w[1]; |
|---|
| 42 | w = numpy.core.concatenate((w[n - 1:0:-1], w[1:n])); |
|---|
| 43 | if not sym and not odd: |
|---|
| 44 | w = w[:-1] |
|---|
| 45 | return w |
|---|