Advertisement
tepples

Blackman notch

Oct 29th, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. #!/usr/bin/env python
  2. """
  3.  
  4. Blackman dual-passband filter generator
  5. by Damian Yerrick
  6.  
  7. Bisqwit wanted help making the FIR filter for NTSC luma/chroma
  8. separation.  I'm using a crossover at 5/6 and 7/6 Fsc (3.0 and
  9. 4.2 MHz).
  10.  
  11. """
  12. from __future__ import division
  13. import math
  14.  
  15. def sinc(x):
  16.     pix = math.pi*x
  17.     return math.sin(pix)/pix if pix else 1
  18.  
  19. # Sum of a lowpass and a bandpass
  20. ls = [(sinc(x * 5/36) - sinc(x * 7/36) + sinc(x * 10/36))
  21.       * 1
  22.       for x in range(-35, 36)]
  23.  
  24. # Apply Blackman window
  25. N = len(ls)
  26. alpha = 0.16
  27. black = [(1 - alpha - math.cos(2*math.pi*x/(N+1))
  28.           + alpha*math.cos(4*math.pi*x/(N+1)))/2
  29.          for x in range(1, N+1)]
  30. ls = [a * b for (a, b) in zip(black, ls)]
  31.  
  32. print "Filter: [%s]" % ",".join("%7.4f" % el for el in ls)
  33. print "DC convolve: %.4f" % sum(ls)
  34. sineconv = [sum(math.cos(math.pi*(x + i)/6) * y
  35.                 for (x, y) in zip(range(len(ls)), ls))
  36.             for i in range(12)]
  37. print "Sine convolve (wanna get these values compared to DC convolve):"
  38. print "[%s]" % ",".join("%7.4f" % el for el in sineconv)
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement