I’ve included the code in the following post to make it easier to copy and paste, can someone indicate to me why the following filter is giving me a rather useless result (see the wave form indicated in the images included below) The input sound is stored in an array, as is the output, the commented out FOR LOOP is if there is more than one channel (not so in this case) and the commented out filter params are for a Low Pass Filter (which gives the SAME result, no matter what the f0 value is set to)

I’m trying to implement the DSP filter using the FMOD Ex system, i’m at the point now where I’m writing the filter itself, after much searching i’ve found many examples of the following notch with slight variations, all of mine see to end up with the result shown in the images. Basically, what ever filter i try and implement in this fashion (not using FFT and rFFT to move between time and freq. domains) Gives me the same results in output (always)

Is where the particular filter design came from.

http://img157.imageshack.us/my.php?imag … nalum6.jpg
(Initial Wave – Sine wave 80hz)

(Output Wave – Filter removing 80hz)

Any help or suggestions would be most appreciated.


  • You must to post comments

//Input buffer
float *x = (float *)inbuf.ToPointer();

            //output buffer
            float *y = (float *)outbuf.ToPointer();

            //temp buffer
            float[] buffer;
            buffer = new float[length  * inchannels];

            //sample rate
            int freq = 44100;

            // location
            int f0 = 100;

            float w0 = (float)(2*Math.PI*(f0/freq));
            float sinW0 = (float)Math.Sin(w0);
            float cosW0 = (float)Math.Cos(w0);
            float BW = 0.1f;
            float alpha = (float)(sinW0 * Math.Sinh(Math.Log(2) / 2 * BW * w0 / sinW0));
            float a0, a1, a2, b0, b1, b2;

            // NOTCH
            b0 = 1;
            b1 = -2 * cosW0;
            b2 = 1;
            a0 = 1 + alpha;
            a1 = -2 * cosW0;
            a2 = 1 - alpha;

// low pass filter
b0 = (1 – cosW0) / 2;
b1 = 1 – cosW0;
b2 = (1 – cosW0)/2;
a0 = 1 + alpha;
a1 = -2*cosW0;
a2 = 1 – alpha;
for (int n = 2; n < length; n++) {
//for (int chan = 0; chan < inchannels; chan++) {

                    y[n] = (b0 / a0) * x[n] + (b1 / a0) * x[n - 1] + (b2 / a0) * x[n - 2] - (a1 / a0) * y[n - 1] - (a2 / a0) * y[n - 2];

  • You must to post comments

there was an error with one of the variables being set ‘NaN’ i fixed that, the low pass, high pass is now working.. but the notch doesnt. Any ideas? Notch gives me no change over input data


  • You must to post comments

As a person trying to do a similar thing using code from [url=http://www.musicdsp.org/showone.php?id=35:12af62jf]here[/url:12af62jf] I can understand your frustrations. 😉

Just a question, how do you run your filters on multi-channel (i.e. stereo) sound? Don’t the channels cause you a bit of trouble?

In my current attempts, I have been splitting up the samples into left and right, and then performing the notch onto them seperately prior to rejoining. Of course my notch still doesn’t seem to be right, so… :roll:

My notch code (that is run on the compiled channel data) is [url=http://www.cs.waikato.ac.nz/~rmh14/downloads/code.txt:12af62jf]here[/url:12af62jf]

  • You must to post comments

I;ve got the buffer of interleaved values


(being left and right values, 1,2,3,4 and so on), i had two nested for loops

for iLength
for iNumChannels
output[iLength + iNumChannels] = input[iLength + iNumChannels]
end for
end for

or similar.. depends on where you are getting your data from.


  • You must to post comments

I’ve been trying hard to search for a bandpass filter source code on the net but with no success. Luckily you guys have discussed it clearly. Could you ArchfileX, if you may allow, post the complete code in C#. I’ll dearly appreciate your help. Kind regards,

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.