DSPRelated.com
Forums

band-pass filter in time domain

Started by samseed February 14, 2005
Hi, could someone plz explain to me how I can perform a FIR (band-pass)
filter in the time-domain? I have my time-domain audio samples
(coefficiants?) ready to work with.

Because of speed issues I'd like to do the filtering in the time-domain
rather than FFT>filter>iFFT.

I'm new to DSP and don't have a super math background (I'm just a
programmer!).

I've read over many posts in comp.dsp and studied various dsp sites,
but I still need some hand-holding...

Please be as specific and descriptive as possible. Formulas to
accomplish the filter would be greatly appreciated. Thank you very much
for any help.

samseed wrote:

> Hi, could someone plz explain to me how I can perform a FIR (band-pass) > filter in the time-domain? I have my time-domain audio samples > (coefficiants?) ready to work with. > > Because of speed issues I'd like to do the filtering in the time-domain > rather than FFT>filter>iFFT. > > I'm new to DSP and don't have a super math background (I'm just a > programmer!). > > I've read over many posts in comp.dsp and studied various dsp sites, > but I still need some hand-holding... > > Please be as specific and descriptive as possible. Formulas to > accomplish the filter would be greatly appreciated. Thank you very much > for any help. >
You are probably correct in not wanting to get to the frequency domain just to filter and go back -- there are ways to do so efficiently, but I haven't had occasion to use them so can only recommend a time-domain approach. There are a gazzilon different band-pass filter implementations out there, so it's hard to give you one specific example. Google around -- there should be examples galore. I suggest getting a book, and reading it -- "Understanding Digital Signal Processing" by Lyons would be a start. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
thanks Tim, yes Lyon's book is on my list.

Here's a low-pass filter I've been playing with. I haven't seen any
beneficial results, other than static when I increase the cutOffFreq.


int sampleRate = 32000;
int cutOffFreq = 3;

for (int i= 0; i < input.length; i++)  {

    double b = Math.atan(Math.PI * cutOffFreq/sampleRate);

    b = -(b - 1.0)/(1.0 + b);

    double a = 0.5 * (1.0 - b);

    output[i] = (short)(a*input[i] + a*(input[i]-1) + b*(input[i]-1));
}


any observations or suggestions?

ok, i've noticed some basic errors in the above loop.

Am I correct in thinking that this is a 3 tap low-pass filter? Can this
be accomplished in the time-domain?

Is each tap a multiplication of a sample and a frequency?

I'm guessing you are looking for coefficients and know how to do
convolution.

first you should define the cut-offs for the band-pass filter.  Then you can
either use a FIR Filter design program (probably in MATLAB) to find the
filter coefficients, or find the coefficients yourself manually.  To find
them manually...its a bit complicated (using pole-zero plot to find out
poles at normalized frequency...and then finding the difference equation
using inverse z-transform, etc.)...if you're unfamiliar w/ DSP, then u're
better off using a filter design program.

"samseed" <agent3492003@yahoo.com> wrote in message
news:1108400761.744984.30520@c13g2000cwb.googlegroups.com...
> Hi, could someone plz explain to me how I can perform a FIR (band-pass) > filter in the time-domain? I have my time-domain audio samples > (coefficiants?) ready to work with. > > Because of speed issues I'd like to do the filtering in the time-domain > rather than FFT>filter>iFFT. > > I'm new to DSP and don't have a super math background (I'm just a > programmer!). > > I've read over many posts in comp.dsp and studied various dsp sites, > but I still need some hand-holding... > > Please be as specific and descriptive as possible. Formulas to > accomplish the filter would be greatly appreciated. Thank you very much > for any help. >
A simple low pass filter is H(z) = 0.5 (1 + z^-1) = (z + 1)/(2 z)
A simple high pass filter is H(z) = 0.5 (1 - z^-1) = (z + 1)/(2 z)

Each of these has their cut-off frequency at 1/2 the sampling
frequency. The cut-off frequency is frequency at which the output of
the filter is 1/sqrt(2) the input.

To implement these you would use the equations, respectively:
    y[n] = 0.5 ( x[n] + x[n-1] )     // low pass
    y[n] = 0.5 ( x[n] - x[n-1] )      // high pass

You will get a band pass filter if you cascade the two -- i.e run the
output of one through the other. This should get you started until you
find a better algorithm. Higher order filters that are extensions of
the above are possible. They have a sharper cut-off, but a smaller
pass-band. The overlapping region, which you are interested in, gets
smaller as the order of the filter increases.

Note that the output of the cascaded filters in the pass band will be
at least attenuated to half level of the input. 

-- Arya

Try the java applet at this link.

http://www.dsptutor.freeuk.com/FIRFilterDesign/FIRFilterDesign.html

-- Arya

You could put  the computation for a & b outside (before) the loop as they
are constants for the duration.

Did you intend the cutoff freq to be 3Hz?

Jim Adamthwaite.


yea that was the "basic" error I noticed...

>Did you intend the cutoff freq to be 3Hz?
No. I was just messing with the results.