high-pass filter implementation in python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saeedsab
    New Member
    • Apr 2013
    • 1

    high-pass filter implementation in python

    Hi
    I want to subtract all the behaviour that have length scale bigger than data-length/10 from each vector. Here is the function I wrote:

    Code:
    def hpass(vec):
    	cutoff_hz = len(vec)/10.
    	sample_rate=len(vec)
    	nyq_rate = sample_rate / 2.
    	numtaps = 10
    	warmup = numtaps - 1
    	fir_coeff = firwin(numtaps, cutoff_hz/nyq_rate)
    	delay = (warmup) #/ sample_rate
    	t=np.arange(len(vec))
    	t-=delay
    	ln=len(t)-delay
    	t=t[:ln]
    	fl= lfilter(fir_coeff,1.0,vec)
    	tmp=vec[:ln]-fl[t]
    	filtered=(tmp)
            return filtered
    but apparently this does not work probably since the delay part is not calculated right, can anybody help me with this?

    Cheers
    Last edited by Meetee; Apr 10 '13, 11:08 AM. Reason: Code tags [CODE/] added
  • YarrOfDoom
    Recognized Expert Top Contributor
    • Aug 2007
    • 1243

    #2
    It's been a while since I've done anything frequency related so could you explain what the value for delay should be?
    Right now it is equal to warmup, since half of line 8 is commented out.

    If you're using Python 2.x rather than 3.x the problem might be integer division related since warmup and sample_rate are both integer values (assuming you're using the full line 8 without anything commented out). Python 3.x integer division results in a float (so 3/2=1.5), but 2.x versions still have classic integer division where the results are rounded down (3/2=1).

    Comment

    Working...