[Clam-devel] IIR BiQuad LPF/BPF/HPF

Karsten Krispin karsten.mailinglists at krispin.de
Thu Jan 8 14:30:08 PST 2009


Hello!

... and a happy new year!

I'm searching for a IIR implementation for LP, BP and HP filters.  Does CLAM 
already implemented such things?

Currently I'm implementing it via SpectralAnalysis/Synth. Unfortunately this 
implementation consumes much cpu power.

Is there already something available in CLAM?

If not: I tried to implement it with the reference of 

http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt

So far so good. It works. As far as I understand, the only tricky part is to 
calculate the coefficients.

For now, all refers to a LP implementation:

That I have done and it is working.. some how:

I have pushed a rectangle-wave throug the filter to explain:

The result is represented in the attached "biquad_nonzerophase.png"
Here you can see that the right edge of the rectangle is somhow flipped.

In "biquad_zerophase.png" you could see how I would expect the filtered signal 
to be. It was created with a SpectralLowPass in the signal-chain. 

This flipped edge is caused by a nonzero phased filter as I read somewhere.
This nonzero phase behaviour could be erased by applying the same filter 
backwards to the signal.

But if I do this, the result is "biquad_nonzerophase_backwards.png". Some 
weird peaks at the corner of each AudioBuffer occour.

If I apply the same filter forwards, everything is fine, like in 
"biquad_nonzerophase.png". 


The filter-code is:

You apply CLAM::Audio Buffer to the filter class and it does the magic within 
filter() - function:

All variables prefixed with an underscore are class-private variables.
Those with an "_bx*" and "_by*" are variables for the backward filter.

The biquad coefficients are applied, of course.

Has someone an particular idea?

Code below.

Thanks in advance,
Karsten Krispin


Code:

void BiQuadFilter::Generic::filter(CLAM::Audio & buffer)
{
	
	CLAM::TData * buf = buffer.GetBuffer().GetPtr();
	CLAM::TSize bufSize = buffer.GetSize();

	CLAM_ASSERT(buf, "Pointer to AudioBuffer is empty");
	
	/* Forward Filter */
	for(int i = 0; i < bufSize; i++)
	{
		_y = _b0 * buf[i] + _b1*_x1 + _b2*_x2 - _a1*_y1 - _a2*_y2;
		_x2 = _x1;
		_x1 = buf[i];
		_y2 = _y1;
		_y1 = _y;

		buf[i] = _y;
	}
	*/
	
	/* Backward Filter */
	for(int i = bufSize-1; i >= 0; i--)
	{
		_by	= _b0*buf[i] + _b1*_bx1 + _b2*_bx2 - _a1*_by1 - _a2*_by2;
		
		_bx2 	= _bx1;
		_bx1 	= buf[i];

		_by2	= _by1;
		_by1	= _by;
		
		buf[i] = _by;
	}
}










-------------- next part --------------
A non-text attachment was scrubbed...
Name: biquad_nonzerophase_backwards.png
Type: image/png
Size: 2191 bytes
Desc: not available
URL: <http://lists.clam-project.org/pipermail/clam-devel-clam-project.org/attachments/20090108/f00fac1e/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: biquad_zerophase.png
Type: image/png
Size: 5257 bytes
Desc: not available
URL: <http://lists.clam-project.org/pipermail/clam-devel-clam-project.org/attachments/20090108/f00fac1e/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: biquad_nonzerophase.png
Type: image/png
Size: 2432 bytes
Desc: not available
URL: <http://lists.clam-project.org/pipermail/clam-devel-clam-project.org/attachments/20090108/f00fac1e/attachment-0008.png>


More information about the clam-devel mailing list