By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,767 Members | 1,033 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,767 IT Pros & Developers. It's quick & easy.

high-pass filter implementation in python

P: 1
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:

Expand|Select|Wrap|Line Numbers
  1. def hpass(vec):
  2.     cutoff_hz = len(vec)/10.
  3.     sample_rate=len(vec)
  4.     nyq_rate = sample_rate / 2.
  5.     numtaps = 10
  6.     warmup = numtaps - 1
  7.     fir_coeff = firwin(numtaps, cutoff_hz/nyq_rate)
  8.     delay = (warmup) #/ sample_rate
  9.     t=np.arange(len(vec))
  10.     t-=delay
  11.     ln=len(t)-delay
  12.     t=t[:ln]
  13.     fl= lfilter(fir_coeff,1.0,vec)
  14.     tmp=vec[:ln]-fl[t]
  15.     filtered=(tmp)
  16.         return filtered
but apparently this does not work probably since the delay part is not calculated right, can anybody help me with this?

Cheers
Apr 10 '13 #1
Share this Question
Share on Google+
1 Reply

YarrOfDoom
Expert 100+
P: 1,247
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).
Apr 17 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.