How do I implement a bandpass filter given by this equation?

I'm messing around with some audio stuff and the algorithm I'm trying to implement calls for a band-pass second-order FIR filter given by the equation

H(z) = z - z^(-1)

How do I implement such a bandpass filter in C?

I have raw audio data as well as an FFT on that audio data available to me, but I'm still not sure how to implement this filter, neither am I sure exactly what the equation means.

In the image below, I am trying to implement HF3:

Answers


z^-1 is a unit (one sample) delay, z is one sample into the future. So your filter output at sample i depends on input samples at i-1 and i+1. (In general you can think of z^-n is an n sample delay.)

If you have time domain samples in an input buffer x[], and you want to filter these samples to an an output buffer y[], then you would implement the given transfer function like this:

y[i] = x[i+1] - x[i-1]

E.g. in C you might process a buffer of N samples like this:

for (i = 1; i < N - 1; ++i)
{
    y[i] = x[i + 1] - x[i - 1];
}

This is a very simple first-order non-recursive high pass filter - it has zeroes at +1 and -1, so the magnitude response is zero at DC (0) and at Nyquist (Fs / 2), and it peaks at Fs / 4. So it's a very broad bandpass filter.


Need Your Help

OSX/Cocoa : adding objects on the Dock

osx cocoa dock

For one of my software, I might need to have to add some objects that could have the same behavior as any of object already present (apps/stack etc.), having a contextual menu.

How to update created and modified fields using the repository design pattern?

c# asp.net-mvc repository-design

I am currently working on my first asp.net mvc application. I am trying to drink the kool-aid of all the the sample projects I see and trying to use the repository design pattern.