SynthMaker

DC blocker filter

Archive · 2008 11 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

oddson ·

I was able to use Tobybear's filter explorer to generate this DC blocker filter:

streamin x; streamout y; float a0= -0.997865,a1= 1.99573,a2= -0.997865; float b1= -1.99573,b2= 0.995735; float yold,yold1,yold2,xold,xold1,xold2;

yold2=yold1; yold1=y; y= a2*xold2 + a1*xold1 + a0*x - b2*yold2 - b1*yold1; xold2=xold1; xold1=x;

I have a steeper version that also seems to work (at least both seem to work when testing with the impulse and signal analyzer):

streamin x; streamout y; float a0,a1,a2,b1,b2,t1,t1sq,t2,t3,yold,yold1,yold2,xold,xold1,xold2; stage(0){ // calculate temporary variables t1=tan1(0.24999); t2=0.6735; t1sq= t1*t1; t3=1+(t1/t2)+t1sq;

// calculate coefficients a0= -1*t1sq/t3; a1= (2*t1sq)/t3; a2= -1*t1sq/t3; b1= (-2*(t1sq-1))/t3; b2= (1-(t1/t2)+t1sq)/t3; }

// process input yold2=yold1; yold1=y; y= a2*xold2 + a1*xold1 + a0*x - b2*yold2 - b1*yold1; xold2=xold1; xold1=x;

But when I try to put the coefficients in directly it messes up. I think it has to do with the decimal representation of the floats. With values so very close to whole numbers I guess you have to be correct to the last bit.

oddson ·

streamin x; streamout y; float a0,a1,a2,b1,b2,yold,yold1,yold2,xold,xold1,xold2; stage(0){

// calculate coefficients a0= -1.08793e+008/(1+(10430.4/0.6735)+1.08793e+008); a1= (2*1.08793e+008)/(1+(10430.4/0.6735)+1.08793e+008); a2= -1.08793e+008/(1+(10430.4/0.6735)+1.08793e+008); b1= (-2*(1.08793e+008-1))/(1+(10430.4/0.6735)+1.08793e+008); b2= (1-(10430.4/0.6735)+1.08793e+008)/(1+(10430.4/0.6735)+1.08793e+008); }

// process input yold2=yold1; yold1=y; y= a2*xold2 + a1*xold1 + a0*x - b2*yold2 - b1*yold1; xold2=xold1; xold1=x;

This works (and seems to do a very good job of it too).

But if I try to sub these values (calculated using Excel from the same formulas as above):

-0.999857659 1.999715319 -0.999857659 -1.999715301 0.999715337

...I get an unstable filter.

Anyone have any suggestions?

infuzion ·

oddson wrote: But if I try to sub these values (calculated using Excel from the same formulas as above): -0.999857659 1.999715319 -0.999857659 -1.999715301 0.999715337 ...I get an unstable filter.

double floatsaren't available yet...well you can try in regular ASM.

oddson ·

infuzion wrote: double floatsaren't available yet...well you can try in regular ASM.

I know... I'm trying to over-determine the single float values so they will set to bit-level accuracy but it's not working. The max. resolution for floats does not correspond exactly to a certain number of decimal places but I thought SynthMaker's code module should be able to set them if there are more decimals than are needed but it does not seem to be working. I think it's a deficiency in the code module but I'm not 100% sure.

I wonder if I can assign them in ASM at the bit level?

infuzion ·

There are only so many bits in a 32bit float you can fill, no matter how you fill it. You could split up the math, but that could get messy & expensive, & the output will still be 32bit.

oddson ·

I'm only talking about getting the right 32 bits saved... somehow when I use the above numbers -- which should be more than accurate enough -- I get an unstable filter. But when I use calculation that should lead to the single float equivalents -- I get a filter that works quite well... but I waste a few cycles in stage zero calculating them every time -- even though they are the same every time...

1) this would appear to be a minor bug in the way SM converts decimal values into 32 bit floats 2) is there a workaround to avoid the calculation described?

MyCo ·

This could do it:

streamin in; streamout out;

float lastin; float lastout;

out = in-lastin + 0.9999*lastout;

lastin = in; lastout = out;

coeffs are: a0 = 1 a1 = -1 a2 = 0 b1=-0.9999 b2=0

oddson ·

Ok... 😊 well that's much simpler and seems to work nicely.

I've also discovered mine is inverting the signal... maybe I should leave filters for the DSP experts. 😉

It still makes me wonder about how SynthMaker's code module assigns decimal values to floats...

MyCo ·

if you want to know how a float is stored, you can just assign it to an output, and then connect my stream inspector to it. It can show you the exact hex value.

bootsy ·

And don't forget to scale the mult factor (frequency) depending on your samplerate, should be 1-(2*PI*frequency/samplerate).

hansdump ·

of course you can change that coeffs if you want a quick or slow dc adaption...

just have a read at this https://ccrma.stanford.edu/~jos/fp/DC_Blocker.html for more theoretical background.

dc tracking values from 1...0.9 //dctracking: a low value allows // faster tracking

here my asm implementation...

streamin x;streamout y;streamin dctracking;float xm1=0; float ym1=0;

movaps xmm0,dctracking; mulps xmm0,ym1; addps xmm0,x; subps xmm0,xm1;

//Assignment> sLeft=xmm0 movaps y,xmm0; //Assignment> sLeft=x movaps xmm0,x; movaps xm1,xmm0; //Assignment> sLeft=y movaps xmm0,y; movaps ym1,xmm0;

Sry, if I was too lazy to look at yours...

N8!

H.

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.