SynthMaker

FIR filters?

Archive · 2005 31 old posts

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

sequencer ·

Hi

Been away for a while from the community...

Does anyone know if anybody has implemented an FIR filter.

I've built something within Quantum FX and I would like to implement as a true portable VST (you can only use the produced VST effect within the Quantum Fx program and not as a portable VST effect for use in any host), but it requires FIR filters where I can vary the number of coefficients to tune it. I basically need a FIR variable Low Pass and High Pass filter and was wondering if anyone had produced something of that ilk yet ?

My DSP is pretty useless and non-existant, otherwise I'd have a go and share it myself.

Thanks

Sequencer 🙂

rl ·

In sm you just need to cascade "one sample delay" modules weighted by your filter coefficients. You will need a lot of filter taps though.

Here is a link to an applet that calculates FIR coefficients based on desired filter settings:

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

sambean ·

Hi sequencer,

There's a method that's quite efficient using buffers, but I'm not sure if the number of coefficients can be altered dynamically..

Here it is in brief off the top of my memory, it may not work but the jist is there..

streamin in; streamout out;

float coefs[16]; // coefficient data float delay[16]; // delay buffer float ci,di; // pointers float c,d,total; // temporary variables float SIZE= 16; // size of buffer

stage(0) // this only gets called once at start { coefs[0] = ... // Put your coefficients in here in reverse order coefs[1] = ... // ..

}

stage(1) { delay[di] = in; //put input sample into delay buffer di = di + 1; //input delay pointer di = (di<SIZE)&di; // loop delay pointer

total = 0; ci = 0; loop(16) { d = delay[di] c = coefs[ci]; total = total + c * d;

di = di + 1; di = (di<SIZE)&di;

ci = ci + 1; }

out = total; }

Because the coefficients are in reverse order, imagine that the delay buffer is a delay line in reverse order. The oldest sample in the buffer is always overwritten by the new input sample, then the FIR calculation is carried out in the loop, in reverse order. At the end of the FIR calculation, the delay pointer will be pointing at the oldest sample, ready for it to be overwritten with the new sample..

Hope this makes helps, sorry if the explanation of FIR is a bit vague, but I think the code should work..

If it doesn't I'll be giving it a try sometime tomorrow..

Cheers

Sam

sambean ·

Have tried it, it only works if you leave out the stage(0) and stage(1) parts.. it may be a bug with the code, I'll have a look tomorrow..

rl ·

BTW: do you have a special reason to implement lo/hi-pass filters as FIR filters? Compared to IIR filters you need to do *a lot* more computations and you can't easily change freq and Q on the fly.

sambean ·

Here's the full code for an FIR lowpass filter..

streamin in; streamout out;

float coefs[16]; // coefficient data float delay[16]; // delay buffer float ci,di; // pointers float SIZE= 16; // size of buffer float total,t1,t2;

coefs[0] = 0.4834199; // Put your coefficients in here in reverse order coefs[1] = -0.6794291; //

coefs[2] = -0.1477999; coefs[3] = 0.1191140; coefs[4] = 0.1973543;

coefs[5] = 0.1598165; coefs[6] = 0.0698853; coefs[7] = -0.0232286;

coefs[8] = -0.0871423; coefs[9] = -0.1068423; coefs[10] = -0.0832151; coefs[11] = -0.0298618; coefs[12] = 0.0313550; coefs[13] = 0.0754760; coefs[14] = 0.0797122; coefs[15] = 0.0282147;

delay[di] = in; //put input sample into delay buffer di = di + 1; //increment delay pointer di = (di<SIZE)&di;

total = 0; ci = 0; loop(16) { t1 = delay[di]; t2 = coefs[ci]; total = total + t1 * t2; di = di + 1; di = (di<SIZE)&di;

ci = ci + 1; } out = total;

Ideally you should have the coefficients being set in stage(0), but there appears to be a bug, but this version still works, albeit a little slower..

sequencer ·

Hi Guys,

First off, thanks for the replies. As I said my DSP is pretty minimal and I'm going to have to ask a dumb question or 2.

The code for Low Pass FIR filter: How is the cutoff specified? I'm guessing that it's to do with the co-efficients. I have tried to find some on-line info on this but, to no avail.

I would like to implement an effect that requires no phase shift of the signal (hence the FIR requirement).

Basically all it would do is to apply a crossfeed of left and right signals for headphone listening, i.e. the left signal will be delayed by the number taps/coefficients and added onto the right signal at a lower signal level. This is supposed to give a reasonable illusion of an expanded soundstage via Headphone listening. Obviously the same happens to the right to complete the illusion. Hope this makes sense.

As I said previously, I've already done this in Quantum FX ( still work in progress but, it's a noticeable effect) and was hoping to port this over somehow.

Thanks for the useful info

Sequencer 🙂

sambean ·

Not so sure about getting the coefficients, I just lifted them from some old university files I had lying around..

You may be able to avoid getting into DSP stuff by trying to find a simple coefficient calculator and porting it into an SM module..

I know that designing FIR filter can get pretty heavy (just leafing through a book).. But a fairly straightforward method is the Windowed Sinc function..

I'm not too good at explaining the maths of DSP so maybe have a google of that (in short the coefficients describe the impulse response of the filter , an ideal lowpass filter - a rectangle with cutoff at fc- has an infinite impulse response in the shape of a sinc function.. as we cant have infinite coefficients we truncate them and apply a window to smooth it off and use this window as our cofficients..)

Now with the latest release we have trig float functions (thanks guys!) the sinc function can be implemented as follows (if we leave out the window for just now i.e. a rectangular window):

coef = 2 * cutoff * (sin(n*2*pi*cutoff)/n*2*pi*cutoff)

we need to calculate coefficients for both positive and negative n, so it's simpler if we have an odd number of coefficients, say 15..

So use the above equation to calculate coefficients for n from -7 up to 7 for your specified cutoff using a module..

You'll have to modify the FIR code so you have an input for every coefficient and load the codes into the data array (it doesnt matter about reversing the order as they should be symmetric)

I'll let you have a go at this now before I try to explain any more.. I may be just confusing you more.. Let me know how you get on and if this makes any sense.. I may have a shot at it myself and it may be clearer if I present a module or something..

Hope this helps

Sam

edit..

Forgot to mention you have to set the sinc function = 2 * cutoff for n = 0 manually as you'll just get an error with the maths modules

sambean ·

Me again!

Decided to make a simplified version of the FIR routine using SM modules, not sure if it's as fast, but it's alot easier to visualize and to play about with..

http://freespace.virgin.net/cc.lai/FIR/SimpleFIR.osm

Tom7777 ·

Thanks sambean, great examples 🙂

oddson ·

DSP neophyte question: does all this mean SM's built in filters are IIR?

stefan ·

Yes 🙂 For most common filtering, IIR is superior to FIR, but FIR has its usage as well. Convolving is FIR filtrering for instance.

sambean ·

Getting carried away with this now..

Sorry, I've jumped the gun a bit and gone on to write a basic coefficient calculator..

It's using a rectangular window, so if you want to improve it you can try out designing windows..

Also because the coefficients are symmetric, the FIR section can be simplified a great deal.. Should also be fairly straightforward to expand this to more coefficients..

http://freespace.virgin.net/cc.lai/FIR/SimpleFIR.osm

sequencer ·

Wow Sambean 😍

I'm still trying to wade through DSP online stuff to figure out what I'm supposed to do and you go and create this...thanks a million.

Now I'll just need to look inside to see whats going on and (if you don't mind try and adapt it to my own needs.

The only problem I have, is so little time in which to do any tinkering with Synthmaker due to house hunting etc. I hope the situation will change in the next 3 months or so as I am going to be somewhat of a Sad git and be living on my own again...Oh well ! At least I can try to properly get hold of Synthmaker and try some of this DSP stuff out.

A word of warning though...don't hold your breath for anything coming out of my head this side of 2005.

Agian, thanks for input on this, much appreciated 😀

Sequencer

sambean ·

No worries!

It was fun working it out.. Never really played with FIR stuff before, so it was good to learn..

Feel free to adapt away, there's still lots more that can be done with it, this is just bare bones here.. It would be good to see it being put to use.

Good luck with all the real life things.. See you around..

Sam

steph_tsf ·

Hello Sambean,

It was fun working it out.. Never really played with FIR stuff before, so it was good to learn..

This is my first day discovering SynthMaker and I can't believe my eyes. I'm standing in front of a FIR implementation + a frequency response analyzer, and Sambean is reporting "having fun".

It would be good to see it being put to use.

Surely one application of this outstanding approach would enable students to practice DSP on trivial WinXP PCs, no specific hardware and neither specific software development environments, and allow those students to "play" at home, at will.

What an evolution ! Steph

skOre ·

I presume we have a teacher/professor around here then?

steph_tsf ·

Hi skOre,

skOre wrote: I presume we have a teacher/professor around here then?

No, I'm not a teacher/professor but I manage to keep contacts in schools and labs ... and DSP "at your fingertips" is something of high value for some (should I say many) of my relations. I would like to setup a couple of demonstrations using a "thin" VST-host (maybe Winamp correctly equipped, who knows ?) and a few "basic" DSP modules like FIR, IIR, enveloppe detectors, ... all running on a WinXP computer without specific hardware, without thousands of dollars licences... and betting on a horse that has another 20 years lifetime. To me, SynthMaker is like an unique opportunity. I'm just wondering if "native DirectX" instead of "VST" woudn't be more bulletproof ... so please comment on this ...

Thanks, Steph

steph_tsf ·

steph_tsf wrote: I'm just wondering if "native DirectX" instead of "VST" woudn't be more bulletproof ... so please comment on this ...

Just found this from Microsoft. http://www.microsoft.com/belux/fr/msdn/ ... haser.mspx This time it is not Winamp as VST-host, but WindowsMediaPlayer as DSP-host using DirectX. This is far from a graphical programming environment, but ... Munoz is one of the promotors of "Native Signal Processing" back in the mid nineties, and what he has been foreseen and promoted ... is our everyday reality !

Please comment. Thanks, Steph

The Sound Scientist ·

Thats a pretty cool link... My whole family is from Belgium..I'm the first born here in America... As a new and aspiring programmer creating something to "hook" into windows media player is pretty cool stuff...Maybe a Synthmaker VST could one day work with other hosting apps other then VST compatible ones.. The future of this program is very very promising.. 🙂 😀 😉 Peace and Science..... and good luck! 😉

sambean ·

steph_tsf wrote: This is my first day discovering SynthMaker and I can't believe my eyes. I'm standing in front of a FIR implementation + a frequency response analyzer, and Sambean is reporting "having fun".

hehehe.. If only I was as keen when it mattered at university..

steph_tsf wrote: Surely one application of this outstanding approach would enable students to practice DSP on trivial WinXP PCs, no specific hardware and neither specific software development environments, and allow those students to "play" at home, at will.

Thats what I love about SM over the other modular synth programs.. The low level capabilities allow easy implementation of modules copied from DSP diagrams.. At Uni we were taught synthesis using SynthEdit, where this was suitable as we were being taught from an analogue perspective, I think that Synthmaker would be an excellent tool for teaching from a DSP perspective..

As to the DirectX support, I've wondered about this too, I'm not sure of the implementation difficulties and the devs are busy working towards the first release, but it may make sense to incorporate this at a later stage as it opens up the market to other applications apart from DAWs.. You should perhaps suggest this in the Ideas and Requests forum..

sambean ·

While on topic, for those who are interested I've updated the FIR example up to 63 points and included a windowing section..

http://freespace.virgin.net/cc.lai/FIR/SimpleFIR2.osm

😀

skOre ·

link not working

sambean ·

Ooops!

Thanks Skore...

Fixed now..

Tom7777 ·

Thanks sambean 🙂

fritzman ·

Thanx Sambean!!! 😀

cAPSLOCK ·

I hope it is OK that I resurrect this thread.

I have been playing with FIR filter ideas for research purposes, and if I can get a couple things to work here, I plan to go ahead and become an early adopter. 😉

But I have a few questions.

First, in the 63 and 15 point examples by sambean I am curious how the values for the coefficients correspond to.. well what are they? 😉

I see integers 0,1,2,3,4...,30,31 and the like... What is the range of these values? Can they correspond to a floating point number between -1 to 1?

More importantly for me, I am interested in making a module that would map a very short IR wave file across the array of coefficients.

Or, perhaps even better, I would like to create a module that just convolves the signal with the short IR. The IR would be well under 200 samples, and perhaps as small as 32-64. Still if it were possible I would like the length of the IR to not matter. (Within reason. I do not plan on playing with long reverb type IRs, just very short IRs.)

So... my questions are:

1. Is there a way to translate (by hand) the floating point values of a IR WAV file to these 1 - 31 vaules?

2. Even better, is there a way to use a loaded wav file with the wave array or other wave module to convoluve the signal? Or to 'automatically' build a filter based on that wave file?

Am I asking too much of SM and the community? 😈

Thanks!! cAPSLOCK

cAPSLOCK ·

No luck for me on this?? Should i try the questions in a new thread? Or just try to figure it out myself (well I am already tring to do that 😉 )?

rl ·

Hi cAPS I'm trying to give a little explanation:

Sambeans example is a 32 tap FIR which convolutes a lowpass filter with a sound input. The integer numbers are the tap numbers. The ideal (brickwall) lowpass filter has a known impulse response: The fourier coefficents are 2*fc*(sin(2*PI*fc*n)/sin(2*PI*fc*n)) Some windowing is applied and fed into the FIR network.

The taps of a FIR network are the fourier coefficients. To obtain the coefficients of an audio signal, you could try using a STFT. (I have not tried yet, whether it's practicable to use the S|M FFT component, though)

cAPSLOCK ·

Thanks rl... I have a long way to go, but I will get there hopefully. 😉

jkristos ·

I know this thread hasn't been going for quite a while but...

For my first real project I am hoping to design a linear phase eq, so I need to calculate coefficients for more filter types. Does anyone know of a good resource for finding these equations?

Thank you for all the work you did creating that lowpass section Sambean. I hope you don't mind if I use that for a basis for the other filters.

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.